10

I've an APFS disk image (disk3). Currently it's capacity is near close; around 700 MB left.

Is it possible to increase it while keeping the data inside intact!

I've tried diskutil apfs resizeContainer but with no luck.

diskutil list:

/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         251.0 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         250.0 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +250.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            170.4 GB   disk1s1
   2:                APFS Volume Preboot                 23.1 MB    disk1s2
   3:                APFS Volume Recovery                517.3 MB   disk1s3
   4:                APFS Volume VM                      3.2 GB     disk1s4

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS CAN                     499.7 GB   disk2s2

/dev/disk3 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +30.2 GB    disk3
   1:                        EFI EFI                     209.7 MB   disk3s1
   2:                 Apple_APFS Container disk4         29.9 GB    disk3s2

/dev/disk4 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +29.9 GB    disk4
                                 Physical Store disk3s2
   1:                APFS Volume cache                   29.3 GB    disk4s1
4

2 Answers 2

9

You can first increase the size of the disk image and in a second step the size of the container:

  1. Get the disk image limits:

    hdiutil resize -limits /path/to/disk_image
    
  2. Eject the disk image items:

    diskutil list
    diskutil eject diskXsY #eject all volumes/items of the image
    
  3. Depending on the limits increase the size of the image:

    hdiutil resize -size <size> /path/to/disk_image #<size> in b|k|m|g|t (e.g. 50g)
    

    This works for normal as well as sparse images. I didn't test sparse bundle images.

  4. Mount the disk image:

    hdiutil attach /path/to/disk_image
    
  5. Get the details:

    diskutil list
    
  6. Increase the size of the APFS container:

    diskutil apfs resizeContainer <disk_identifier_apfs_container> 0
    

    Don't mix the disk identifiers of SSD and disk image APFS container here! The embedded APFS volume should be expanded automatically if required.


Using certain APFS formatted disk images (sparse images) may result in data loss in the image on APFS formatted physical disks with low free space.

Instead of using an APFS disk image simply create a new APFS cache volume (with quota?) in the APFS container (internal SSD) or an image/a second partition on an external HDD.

0
0

One solution would be to create a new larger AFPS disk image.

In your case, the source would be the container disk4, as shown below.

/dev/disk3 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +30.2 GB    disk3
   1:                        EFI EFI                     209.7 MB   disk3s1
   2:                 Apple_APFS Container disk4         29.9 GB    disk3s2

Below is the diskutil list output from a propose larger AFPS disk image target.

/dev/disk5 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +200.0 GB   disk5
   1:                        EFI EFI                     209.7 MB   disk5s1
   2:                 Apple_APFS Container disk6         199.8 GB   disk5s2

You the could clone the source to the target by using the command given below.

asr  --source  /dev/disk4  --target  /dev/disk6  --erase

Or, the following could be substituted.

asr  --source  /dev/disk3s2  --target  /dev/disk5s2  --erase

Note: Afterwards, both the source and target will be unmounted.

BTW, you can use the Disk Utility application instead of the asr command. This substitution seemed to succeed, when I tested. The only problem was the Disk Utility application hung afterwards. This required me to Force Quit the Disk Utility application. I was using macOS 10.13.3.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .