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:
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.
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:
(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.
