Skip to content

Instantly share code, notes, and snippets.

@alanmur
Last active September 22, 2021 04:00
Show Gist options
  • Save alanmur/d1164d25281eed7aaea90c6fe96b1021 to your computer and use it in GitHub Desktop.
Save alanmur/d1164d25281eed7aaea90c6fe96b1021 to your computer and use it in GitHub Desktop.
Resize mac1.metal disk partition to size of EC2 EBS volume

Resize mac1.metal disk partition to size of EC2 EBS volume

Do we need to increase the partition size?

Look at the size of the partition and volume in About This Mac

image

Select Storage

image

The capacity of the volume is 64.24 GB (purple arrow) which is a tiny fraction of the 1.07 TB of EBS storage this instance has attached. This instance needs the volume to be expanded. (If it was already sized correctly, the volume would occupy most of the drive.)

image

Procedure

Open the terminal. You can do this in the GUI if you like...

image

Or use the terminal from the SSH connection... (I will do this. The commands are identical).

Issue the diskutil list command, to see the disks and partitions.

image

Identify the external, physical disk, which is the EBS store attached to the instance. You can see this is /dev/disk0 on this instance. It is not always this disk! The second entry in the list for disk0 is the Apple_APFS Container disk2, which is the disk we want to expand, and it is called disk0s2. The root of this disk is disk0.

The first step is to repair the root disk. Issue the following command making sure that the disk you specify is the external, physical disk for your instance:

diskutil repairdisk /dev/disk0

image

Erasing the EFI partition (disk0s1) is safe on mac instances.

image

Then issue the command, making sure that the disk identifier is for the Apple_APFS Container:

diskutil apfs resizeContainer disk0s2 0

The zero means 'fill the available space'

The command spews, and may take a while, but ultimately looks like this:

image

Listing the partitions again looks like this:

image

The container is now nearly the same size as the physical disk. Back in the UI, we see the same result.

image

Attribution

Liberally borrowed from this YouTube video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment