« Error during server based archiving using -DAOS ON commandline parameter. | Main| Creating a sha2+ keyring with Domino CA signed certificate »

Fun with OSX Storage or How to upgrade to a larger boot disk

Tags: Apple MacBook OSX CoreStorage physical volume resizing increase physical volume howto
Recently I bought a larger SSD for my wife's  2011 MacBook Pro and to avoid having to reinstall everything I created an image of the original SSD using my Ubuntu laptop.
I restored the image onto the new drive,  using gParted I then moved the Recovery Partition to the end of the disk to free space directly following the main OSX partition.
This left only one more thing, to resize the actual OSX partition to use the full size of the new drive.

Unfortunately this wasn't so easy as I first thought.
The tools available to me on my Linux system didn't quite seem up to the task, so I put the drive into the MacBook Pro, and booted into Recovery Mode (Command-R).
No problem there, the Disk Utility saw the drive, but flat out refused to resize it. I could create a new partiition in the unused space, but that wasn't quite what we had in mind.

In recovery I then opened up a terminal window.

The command "diskutil list" showed the full size of the drive and "diskutil cs list" showed there was a smaller physical volume containing  a logical volume "Macintosh HD"

A few Google queries later I found my self trying the (undocumented) diskutil resizedisk / diskutil cs resizevolume commands but both returned errors.

Edit: the command diskutil cs resizedisk returned:  this operation couldn't proceed because the target's boot helper was mounted

After a couple of iterations where I fine tuned my Google query I ended up with the following.
Put the original SSD back into the MacBook Pro, connect the new one throuh a USB adapter and boot into Recovery, click Utilities in the menubar and select Terminal.

gpt show /dev/disk2

     start      size  index  contents
         0         1         PMBR
         1         1         Pri GPT header
         2        32         Pri GPT table
        34         6
        40    409600      1  GPT part C12A7329-F81F-11D2-BA4B-00A0C93EC93B
    409640  235298960      2  GPT part 53746F72-6167-11AA-AA11-00306543ECAC
  235708600   251420488
  487129088   1267712      3  GPT part 426F6F74-0000-11AA-AA11-00306543ECAC
  488396800  0

This command shows the partitions inside the GPT partition including the free space between 2 GPT part and 3 GPT part (because we haved moved the recovery partition to the end of the drive)
(fdisk /dev/disk2 only shows one GPT partition which spans the entire drive).

take note of the starting location, size and identifiers for the GPT partitions, then enter

gpt destroy /dev/disk2
gpt create -f /dev/disk2

Now we need to recreate the existing partitions, here your notes about starting location, size and identifier come into play.

gpt add -b <beginlocation> -s <size> -t <identifier> /dev/disk2

In my case gpt add -b 40 -s 40960 -t C12A7328-F81F-11D2-BA4B-00040C93EC93B /dev/disk2

For the first (EFI) partition this results in an popup error about not being able to mount a volume.

The second one is the actual OSX partiton which in my case went from 120GB to 249GB. Here I had to add the size of the second partition + the size of the free space between the second and third partition for the correct size.
gpt add -b 409640 -s 486719448 -t 53746F72-6167-11AA-AA11-00306543ECAC /dev/disk2

The third one is the recovery partition
After creating the second partition it gets automatically mounted, so before we can continue to recreate the recovery partition we need to unmount it first using the command

diskutil unmount disk2s2

gpt add -b 487129088  -s 1267712 -t 426F6F74-0000-11AA-AA11-00306543ECAC /dev/disk2

Reboot back to recovery and in a terminal window issue the following command to actually grow the volume:

diskutil cs resizevolume disk2s2 249G

To actually resize the volume.

After rebooting the system sees the added space