Mac OS X 10.4: Non-destructively enlarge HFS+ partition

5,633

Solution 1

Can GParted rewrite the partition map (delete the linux partition and then resize the remaining HFS+ partition) without trying to enlarge the HFS+ filesystem? If so you might then be able to use diskutil to enlarge the HFS+ filesystem to fit the bounds of the newly grown partition.

Before trying this (or even using any of the commercial software), you should make sure you have a full backup (that way you can just destructively redo the partition with Disk Utility and restore from your backup—plus get a ‘free’ defrag for your troubles).

Solution 2

TL; DR: Move the whole partition left with dd or gparted. Then you will be able to enlarge it.

It's 2020 now, and diskutil (and its GUI) remains the same when it tries to handle resizing and stuff. The one rule it goes by is that it never moves where a partition starts. As a result:

  • the maximum size of resize is constrained by where you start your partition
  • when you "split" a partition, the new ones are always added after the original one

Luckily, moving the start of a partition is not hard: you just copy data without needing to know anything about the filesystem. This is exactly how gparted handles moves. After you move the beginning of the partition and adjust the partition table accordingly, you can resize normally.

For my specific case, I was regretting a conversion to APFS on a very loud 10TB HDD and trying to revert back to HFS+. I did the following, mostly with the Disk Utility GUI:

  • Shrink the APFS partition ("P1") to the minimal 2.23 TB allowed for my bunch of files.
  • Make the rest a HFS+ partition ("P2") and copy stuff there.
  • Shrink the HFS+ partition, and fortunately enough it was only 2.18 TB. This creates a third HFS+ partition ("P3").
  • Erase the APFS partition (P1) by formatting to HFS+.
  • Since P2 happens to be smaller than P1, I can just dd if=/dev/rdisk3s2 of=/dev/rdisk3s1 bs=$((128 * (1 << 20)) to copy it to where P1 is.
  • Now that everything is back in P1, I can just delete P2 and P3 using the partition button. This automatically grows P1 to the full 10TB size minus (2.23 TB - 2.18 TB). This is because diskutil does not see space unused by any partition (dumb, I know.)
  • Fire up sudo gdisk /dev/rdisk3, press n for a new partition, press enter thrice for the defaults, and press w to write to the partition.
  • sudo diskutil eject /dev/disk3, and then open the Disk Utilities app again. Do the partition thing to delete the mini-partition we just created to reclaim that space.

You might not be as lucky as I am to have enough space to hold two copies of the partition on the disk, so gparted will be your friend. Of course you can manually count the sectors and do a dd plus gdisk, but counting is... hard for me. Moving the partition to the right with dd would be even harder, since you need to copy in reverse direction.

Why doesn't Apple make something like this available? Easy as it sounds to say Apple doesn't care about implementing a dumb slow feature, the parted guys at GNU did the same when they ran into some complications. The issue seems to be that they want to do resize with moving, and resizing does require fs-specific knowledge. Well, it is more efficient to shrink before moving after all...

Share:
5,633

Related videos on Youtube

elcelista
Author by

elcelista

Updated on September 17, 2022

Comments

  • elcelista
    elcelista over 1 year

    I have a MacBook running OS X 10.4.11. Some time ago I shrank my main hard disk partition in order to dual-boot with Linux, but now I am running out of space on the Macintosh partition, and I would like to remove the Linux partition and restore the Macintosh partition to its original size. I have been able to remove the Linux partition, but I cannot seem to merge the free space back into the Macintosh partition. Originally I used GParted to shrink the partition, but I cannot use GParted to restore the partition because GParted is unable to enlarge HFS+ partitions.

    Does anyone know how I can restore my HFS+ partition to its original size without losing my data or spending money on a commercial product?

    If I attempt to use diskutil to resize the partition (while booted from the OS X installation DVD), I get the following:

    # diskutil resizeVolume disk0s2 119690149888B
    Started resizing on disk disk0s2 Macintosh HD
    Verifying
    Resizing encountered error No space left on device (28) on disk

    The 119690149888 bytes value was listed as the maximum size in the output of the command diskutil resizeVolume disk0s2 limits.

    I found other instructions for what I want to do at http://wiki.onmac.net/index.php/Triple_Boot_via_BootCamp#Restoring_your_Mac_to_its_original_state, but this requires Boot Camp, which is no longer available for OS X 10.4.

    (This is almost the same problem as question 50317 "Resize HFS Partition", but on Mac OS X 10.4 the Disk Utility application cannot resize partitions non-destructively. When I attempt to re-partition it warns that all data will be lost.)

  • elcelista
    elcelista over 14 years
    I booted from an Ubuntu 9.10 CD and used GParted to delete the Linux partitions, but it would not let me resize the HFS+ partition. When I clicked on 'Resize/Move' it would let me decrease the partition size but not increase it. Also, I don't have a spare hard disk at the moment, so I can't easily create a full backup. I'm thinking I'll probably have to buy an external hard drive and follow your suggestion.
  • Badu
    Badu about 14 years
    Yes I thought you could use a combination of Disk Utility/gparted to increase/decrease partition sizes, respectively. I cheated and used iPartition which will work on Tiger, but costs about $35. If you're spending money you could always buy Snow Leopard since it's only $25 but you would have to do an update without the full backup safety net.