June 6, 2011 3

Resize HFS+ Partition in Linux

Let's say we've got a left over Time Machine backup disk from our old, sacrilegious OSX install, and we'd like to keep those backups but also shrink the partition down and recover some usable space. Here is an easy way to shrink an HFS+ partition in linux. Please use common sense and make sure that you have another backup of this data before attempting this.

Note to OSX/Time Machine users: I've had some people end up here looking for a way to resize their Time Machine partition. You can easily follow this article with an Ubuntu Live CD.

First plug in the drive and determine which device it is on. In my case it is /dev/sdb. The first thing we need to do is unmount the partition we're looking to resize. You can figure out which partition that is by running parted, like so:

sudo parted /dev/sdb

You will be greeted with a "(parted)" prompt. Enter "print" to view details of the partitions on the drive. In my case, I want to resize partition 2, so we'll "quit" out of parted and unmount partition 2.

sudo umount /dev/sdb2

Now let's go back into parted and resize our partition. We're going to enter into parted, select the partition we'd like to resize, and then we'll be prompted for a start and end to the partition. In my case, I had about 512Gb of data on my 1TB drive. I also had a small partition before this one, which is why it prompted me to start my partition at 210MB. You should probably select whatever it suggests as the start (by simply not entering anything, the item in brackets is the proposed default), and then selecting an end which is a little larger than your usage. I chose 550GB for my end, just to be safe. Below is an output of the whole process:

Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: WD My Passport 071A (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name                  Flags
 1      20.5kB  210MB   210MB   fat32        EFI System Partition  boot
 2      210MB   1000GB  1000GB  hfsx         Time Machine Backups

(parted) resize                                                          
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition number? 2                                                      
Start?  [210MB]?                                                          
End?  [1000GB]? 550GB                                                    
(parted) quit

After you specify an end point and hit enter, the program will go to work and may take some time to finish. I have a relatively fast machine and I believe the drive is 7200rpm. It took only a few minutes to complete. A successful resize should bring you back to the (parted) prompt. Then just enter "quit" to exit parted. At this point I opened gparted and used it's visual editor to create a file system on the newly created partition. When you plug in the drive you should now see the old and new partitions and have access to all the files on both. Again, please, be smart, back up your data.

  • Christopher Blinn

    This is exactly what I’m trying to do, but the time machine partition is hfs+, not hfsx as in your example. I don’t know if this is the source of my problem, but here’s my problem:
    (parted) print
    Number  Start  End     Size    File system  Flags 1      0.00B  2000GB  2000GB  hfs+
    (parted) resize
    WARNING: you are attempting to use parted to operate on (resize) a file system.
    [snip]
    Partition number? 1
    Start? 0
    End?  [2000GB]? 1000GB
    Error: The sector size stored in the journal is not 512 bytes.  Parted only supports 512 bytes length sectors.

    Does that mean I have to disable journaling in the hfs+ partition via OSX before I can resize it with parted? Might I just as well look for OSX resizing tools?

    • http://conjurecode.com/ David

      If you still have access to an OSX machine I would highly recommend finding a tool on OSX to help you resize your partition. I followed this process because I did not have such access. I’m not sure how to solve your issue, I just documented the specific steps that worked for me in my case. Sorry I couldn’t be of more help, good luck!

  • http://conjurecode.com/ David

    I  If you still have access to an OSX machine I would highly recommend finding a tool on OSX to help you resize your partition. I followed this process because I did not have such access. I’m not sure how to solve your issue, I just documented the specific steps that worked for me in my case. Sorry I couldn’t be of more help, good luck!

Dedicated Server Hosting by Hivelocity