Resizing or expanding a CoreStorage volume

Solution 1:

After gaining some experience with CoreStorage volumes, I reworked my first answer to generalize and facilitate it by adding some scenarios and deleting some dispensable steps.

Basically there is one undocumented command to resize or expand a CoreStorage volume group and an inherent logical volume:

diskutil cs resizeStack LVUUID size  

The command expands or shrinks the whole CoreStorage Volume Group including the physical volume(s), the logical volume family and the logical volume in one step to the desired size.

While shrinking it down to the size of the occupied space in the logical volume shouldn't be problem at all (but not recommended because at least 10% free space should be left), any blocking partition except the recovery partition has to be deleted or diminished before expanding the CoreStorage stack.

The command comes in handy in several scenarios:

  • expanding a CoreStorage volume after deleting a 2nd old-style JHFS+ volume on the same device (this may happen after splitting your disk in two partitions in Mavericks and then updating to Yosemite. The first partition - your system volume - might be converted to a CoreStorage volume, while the 2nd volume is left alone.)

enter image description here

  • expanding a CoreStorage volume after manually deleting a Boot Camp NTFS volume

enter image description here

  • resizing a CoreStorage volume to create 2nd old-style JHFS+ volume on the same device

enter image description here

Beware: The command is vastly undocumented and as such potentially destructive.

Preparation:

  • Backup your data.
  • Detach any external drive (especially your external Time Machine backup drive).
  • Restart to Internet Recovery Mode by pressing alt cmd R at startup.
    The prerequisites are the latest firmware update installed, either ethernet or WLAN (WPA/WPA2) and a router with DHCP activated.
    On a 50 Mbps-line it takes about 4 min (presenting a small animated globe) to boot to a recovery netboot image which usually is loaded from an apple/akamai server.

    I recommend ethernet because it's more reliable. If you are restricted to WIFI and the boot process fails, just restart your Mac until you succeed booting.

    Alternatively you may start from a bootable installer thumb drive (Mavericks or Yosemite) or a thumb drive containing a full system (Mavericks or Yosemite).

Modify CoreStorage stack:

  • Open in the menubar Utilities/Terminal

First you should get an overview of your disks and the partition layout:

  • Enter diskutil list
    Example listing:

    /dev/disk0
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *68.7 GB    disk0
       1:                        EFI EFI                    209.7 MB    disk0s1
       2:          Apple_CoreStorage                         53.7 GB    disk0s2
       3:                 Apple_Boot Recovery HD            650.0 MB    disk0s3
       4:                        EFI No Name EFI            100.0 MB    disk0s4
    /dev/disk1
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     Apple_partition_scheme                         *1.3 GB    disk1
       1:        Apple_partition_map                         30.7 KB    disk1s1
       2:                  Apple_HFS OS X Base System        *1.3 GB    disk1s2
    /dev/disk2
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:                  Apple_HFS System                 *53.5 GB    disk2
    /dev/disk3-disk12 ...belong to the OS X Base System (your recovery system you booted to previously)
    

    Disk0 is your main internal disk device containing the EFI-partition (dis0s1), the CoreStorage partition (disk0s2) and the Recovery HD (disk0s3). The No Name EFI (disk0s4) only exists if you had a Boot Camp partition previously and deleted it manually.

    Disk1 is a logical disk created by booting to the netboot image which contains a recovery system (OS X Base System = disk1s2) similar to the Recovery HD.

    Disk2 is also a logical disk residing in disk0s2 and it contains the CoreStorage stack.

  • Enter gpt -r -vv show /dev/disk0
    Example listing:

    gpt show: /dev/disk0: mediasize=68719476736; sectorsize=512; blocks=134217728
    gpt show: /dev/disk0: PMBR at sector 0
    gpt show: /dev/disk0: Pri GPT at sector 1
    gpt show: /dev/disk0: Sec GPT at sector 134217727
          start       size  index  contents
              0          1         PMBR
              1          1         Pri GPT header
              2         32         Pri GPT table
             34          6         
             40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
         409640  104974016      2  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
      105383656    1269536      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
      106653192     204800      4  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
      106857992   27359703         
      134217695         32         Sec GPT table
      134217727          1         Sec GPT header
    

    The partition with the index number 1 is the regular EFI-partition, the partition with index number 2 is your CoreStorage partition and the partition with index number 3 is your Recovery HD.
    The partition with index number 4 (=No Name EFI) only exists if you had a Boot Camp partition previously and deleted it manually. All the rest is unallocated free space (in the example 27359703 blocks à 512 B).

  • Enter diskutil cs list
    Example listing:

      CoreStorage logical volume groups (1 found)
    |
    +-- Logical Volume Group A629E051-D7B0-4B8C-A803-074F62704636
        =========================================================
        Name:         System
        Status:       Online
        Size:         53946696192 B (53.9 GB)
        Free Space:   16777216 B (16.8 MB)
        |
        +-< Physical Volume 90C09FC0-4215-4871-901B-70E2C9C7D464
        |   ----------------------------------------------------
        |   Index:    0
        |   Disk:     disk0s2
        |   Status:   Online
        |   Size:     53946696192 B (53.9 GB)
        |
        +-> Logical Volume Family F6962E38-50E4-4458-BFE6-CF2E179352F5
            ----------------------------------------------------------
            Encryption Status:       Unlocked
            Encryption Type:         None
            Conversion Status:       NoConversion
            Conversion Direction:    -none-
            Has Encrypted Extents:   No
            Fully Secure:            No
            Passphrase Required:     No
            |
            +-> Logical Volume BD36C73D-860D-4DC6-B125-AD624F448B88
                ---------------------------------------------------
                Disk:                  disk2
                Status:                Online
                Size (Total):          53496696192 B (53.5 GB)
                Conversion Progress:   -none-
                Revertible:            Yes (no decryption required)
                LV Name:               System
                Volume Name:           System
                Content Hint:          Apple_HFS
    
  • to resize the CoreStorage volume you have to delete any blocking partition first (the Recovery HD doesn't count because it usually will be moved with the resizeStack command).
    First you have to unmount all mounted volumes on disk0 (first the CoreStorage volume, which has its own disk identifier disk2 but resides on disk0, then all other mounted volumes on disk0 - check this with df):

    diskutil unmountDisk /dev/disk2
    

    then additional volumes (if you have any at all). Example:

    diskutil unmount /dev/disk0s5 
    

    If you have a NoName EFI partition delete it by entering:

    gpt remove -i 4 disk0
    
  • Remount any previously unmounted volume in the reverse order with

    diskutil mount /dev/disk0s5
    diskutil mount /dev/disk2 
    
  • Since any blocking partition is deleted you may now resize the CoreStorage volume with

    diskutil cs resizeStack LVUUID size 
    

    with LVUUID: UUID of the logical volume and size: the final size of your CoreStorage volume.
    Examples:

    diskutil cs resizeStack BD36C73D-860D-4DC6-B125-AD624F448B88 60g  
    

    to expand it to 60 GB

    diskutil cs resizeStack BD36C73D-860D-4DC6-B125-AD624F448B88 40g  
    

    to shrink it to 40 GB

    diskutil cs resizeStack BD36C73D-860D-4DC6-B125-AD624F448B88 0g 
    

    to expand it to the full available size (0g is a magic number here).

    Your Recovery HD should be moved automatically - regardless of whether shrinking or expanding the CS volume - to the very end of it.

  • In case of shrinking the CoreStorage volume you may now create a 2nd partition with gpt.
  • Enter the following to get the new partition scheme:

    gpt -r -vv show /dev/disk0
    

    and

    gpt add -b StartBlock -s NumberOfBlocks disk0
    

    to create a new partition. StartBlock is the number of the first block in the unallocated space and NumberOfBlocks is the number of free blocks or smaller. NumberOfBlocks has to be dividable through 8!

  • Enter exit and quit Terminal.
  • Open Disk Utility (and format your newly created partition if you have created a new partition in the second last step).
  • Then check your expanded CoreStorage volume for errors.
  • Quit Disk Utility.
  • Reboot to your main volume.

Solution 2:

The following diskutil cs resizeStack command is vastly undocumented and as such potentially destructive. There might be an easy way outlined first and a long winding, time consuming hard way.

Please backup your Mac OS X before proceeding.

The not-as-long-as-expected way:

A 2nd computer or an iPhone with the stackexchange credentials to enter the site or the chat is usefull.

Your Mac OS X partition (Macintosh HD) visible on the desktop is equivalent to the Logical Volume 7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

  1. First you have to backup your Recovery HD: Start Terminal.app and enter
    defaults write com.apple.DiskUtility DUDebugMenuEnabled 1 press enter and quit Terminal.app
  2. Start Disk Utility and enable 'Show every Partition' in the Debug menu After a few seconds all partitions should be visible
  3. Choose 'Recovery HD' on the left side and mount the partition 'Recovery HD'

    screen1

  4. Verify the disk

    screen2

  5. Create a disk image of 'Recovery HD' and save it read-only externally

    screen3

  6. Check the disk image for restore

    screen4

  7. Detach all external drives

  8. Restart into Internet Recovery Mode by pressing altcmdR
    or a bootable Mavericks or Yosemite Thumb Drive (full system or install).

  9. start Terminal from the menubar/utilities
  10. enter following command at the Terminal prompt:

    diskutil cs list
    
  11. Copy the Logical Volume (LV) alphanumeric UUID of your CoreStorage volume. The LVUUID should be the fourth listed. In the above example the alphanumeric is:
    7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
  12. Run the following command:

    diskutil cs resizeStack LVUUID partsize  
    

    According to the number found above it would be:

    diskutil cs resizeStack 7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx 0g  
    

    This will hopefully expand your CoreStorage volume to the full 750 GB.. Depending on your disk this will take several seconds (SSD) or minutes (HDD). After a successful resize check with diskutil list if the 'Recovery HD' still exists.
    (Previously the above command was diskutil cs resizeStack 7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx 748g. After some testing we found out that diskutil cs resizeStack 7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx 0g is the smarter command. It should expand the LVG to the maximal size while usually moving 'Recovery HD' to the very end of the physical disk. 0g seems like a magic number in this case.)

  13. Quit 'Terminal.app' and start 'Disk Utility' and verify the expanded volume.
  14. Reboot to Recovery HD and your main drive. Delete the disk image created in step 5 if everything works as expected

If that didn't work then the longer and harder way:

  1. enter diskutil list
  2. Erase the Recovery HD with diskutil eraseVolume Free\ Space %noformat% IDENTIFIER_Recovery_HD.
    In your example: diskutil eraseVolume Free\ Space %noformat% disk0s3
  3. enter following command at the Terminal prompt: diskutil cs list
  4. Copy the Logical Volume (LV) alphanumeric UUID of your CoreStorage volume. The LVUUID should be the fourth listed. In the above example the alphanumeric is:
    7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
  5. Run the following command:
    diskutil cs resizeStack LVUUID partsize

    According to the number found above it would be:

    diskutil cs resizeStack 7BF42B7B-xxxx-xxxx-xxxx-xxxxxxxxxxxx 748g  
    

    This will hopefully expand your CoreStorage volume to almost full 748 GB (i have left some space for a future Recovery HD.

  6. Build a partition for Recovery HD if necessary
  7. Rebuild Recovery HD if necessary
    (work in progress: tested in Parallels but i can't restart in to recovery mode due to limitations of Parallels probably and the partition is always visible. Seems like the Apple Script at musings.silvertooth.us doesn't work with Yosemite/CoreStorage. I'm investigating that)

Please check back in the comments (or maybe chat) if you run into problems

Solution 3:

I am astonished about complexity of this problem (see @klanomath answer) and easiness to create it.

That's why I tried to play with it and found a work around.

  1. My problem was the following: I had 500GB-disk. I created 150GB-Macintosh-HD partition on this disk using Disk Utility, leaving 350GB as a "free space". When I tried to format the free space into second partition I failed to do it: when I pressed Apply it ignored my command and behaved like I never pressed "Apply" (when I wanted to close the Disk Utility window it warned me that there are unapplied changes).

  2. I took the first volume (that is formatted volume named Macintosh HD, it had 150GB size) and asked Disk Utility to partition it into two partitions: 100GB + 50GB. Pressed "Apply" and magically Disk Utility created for me two partitions: 100GB + 400GB. At this point all space on disk become useful and I was quite happy with it.

  3. Then I simply removed second partition, pressing "-" and "Apply". As result it was merged with Macintosh HD and I returned back to were I was before step 1.

  4. Finally, I divided it into two partitions with the sizes 150GB and 350GB as I wanted at the start. Now the problem seems to be solved.