Home > Mac OS X, macOS, Scripting, VMware, VMware ESXi > Expanding partition size in an ESXi-hosted macOS VM

Expanding partition size in an ESXi-hosted macOS VM

As part of working on a project recently, I ran into an unexpected problem with ESXi-hosted Mac VMs. For these VMs, I was creating VMDK files from AutoDMG-generated disk images, using vfuse to convert the disk image into a VM with ESXi-compatible VMDK disk image files.

My workflow looked like this:

1. Create disk image using AutoDMG.
2. Use vfuse to create VMDK files using a command similar to the one shown below:

sudo vfuse -i /path/to/autodmg_created_disk_image_here --esx

Screen Shot 2017 04 09 at 12 08 22 PM

3. Upload the VMDK files to a convenient location on my ESXi server
4. Set up a new VM, using copies of uploaded VMDK files for the VM boot disk.
5. Resize the new VM to the desired size using VMware’s vmkfstools utility.
6. Start up the VM.

After logging in, I ran the following command to enable macOS to recognize and use the unallocated space from the VM resizing:

diskutil resizeVolume / R

Normally, this command is able to do a live re-sizing of the boot partition to use all available unallocated space. However, this time the re-sizing process failed and the following error was displayed:

Screen Shot 2017 04 09 at 10 20 53 AM

Screen Shot 2017 04 09 at 10 21 37 AM


computername:~ username$ diskutil resizeVolume / R
Note: Your partition map does not use the entire space of your whole-disk. You should use "diskutil repairDisk" and then repeat this command.
Resizing to full size (fit to fill)
Started partitioning on disk0s2 Macintosh HD
Verifying the disk
Verifying file system
Using live mode
Performing live verification
Checking Journaled HFS Plus volume
Checking extents overflow file
Checking catalog file
Checking multi-linked files
Checking catalog hierarchy
Checking extended attributes file
Checking volume bitmap
Checking volume information
The volume Macintosh HD appears to be OK
File system check exit code is 0
Resizing
Error: -5341: MediaKit reports partition (map) too small; if you recently grew your whole-disk, you should run whole-disk repair
computername:~ username$

view raw

gistfile1.txt

hosted with ❤ by GitHub

How to fix this? For more details, see below the jump.

My research on this problem turned up the following links:

Both posts confirmed that this was a known issue, but neither offered viable fixes for the problem I was seeing. After some discussion with Nick Cobb in the MacAdmins Slack, I noticed this section of the error message I had received:

Your partition map does not use the entire space of your whole-disk. You should use "diskutil repairDisk" and then repeat this command.

After some testing, the following command resolved the problem I was seeing:

diskutil repairDisk /dev/disk0

Screen Shot 2017 04 09 at 10 24 55 AM

Once the diskutil repairDisk command had been run to fix the partition map, I verified that the following command could now resize the partition without problems:

diskutil resizeVolume / R

Screen Shot 2017 04 09 at 10 26 45 AM

Screen Shot 2017 04 09 at 10 27 28 AM

To automate the process, I wrote a script to run the repairDisk command. However, repairDisk asks for a Yes/No confirmation before running.

Screen Shot 2017 04 09 at 10 24 23 AM

The answer in this specific situation is always going to be “yes”, so the yes command is piped into the command to automatically provide a “yes” answer to the confirmation dialog.


#!/bin/bash
# Fix VM boot disk's partition map. This is necessary
# to allow the boot drive to grow after cloning a VMDK.
#
# Issue documented here:
# https://kb.vmware.com/kb/2069255
# http://osxadmin.blogspot.com/2014/03/expand-os-x-virtual-disk-in-esxi.html
# repairDisk asks for a y/n confirmation before running,
# so the yes command is piped into the command to answer
# "yes" to the confirmation dialog.
/usr/bin/yes | /usr/sbin/diskutil repairDisk /dev/disk0

view raw

gistfile1.txt

hosted with ❤ by GitHub

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment