0

I have a virtual disk of 1 GB, on which I want to create two volumes of 400 MB. With

diskutil partitionDisk /dev/disk0 2 GPT APFS VOLUME1 400M APFS VOLUME2 400M

it created one APFS container of 400 MB and another one of 600 MB.

How can I create two containers of 400 MB?

0

2 Answers 2

2

You need to add a third triplet which instructs diskutil where to put the remaining unused free space. For example, to place the free space after the second APFS container of 400 MB, the command would be the following.

diskutil partitionDisk /dev/disk0 3 GPT APFS VOLUME1 400M APFS VOLUME2 400M free none R

The word free means free space. Since free space cannot have a name, the word none is just used as a placeholder. The letter R means remainder. In other words, the remaining space after creating all other partitions is left unused.

Below is an excerpt from man diskutil which explains further. The version of macOS is Ventura 13.3.1 (a).

The last partition is usually automatically lengthened to the end of the partition map (disk). You can specify an exact size for your last partition by specifying it as the penultimate triplet and specifying an additional (last) triplet as Free Space. Or you can use the R (remainder) size specifier for one of your middle partitions while specifying an exact size for your last partition.

Below is the output from diskutil list.


/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 GB     disk0
   1:                 Apple_APFS Container disk1         400.0 MB   disk0s1
   2:                 Apple_APFS Container disk2         400.0 MB   disk0s2
                    (free space)                         200.0 MB   -

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +400.0 MB   disk1
                                 Physical Store disk0s1
   1:                APFS Volume VOLUME1                 24.6 KB    disk1s1

/dev/disk2 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +400.0 MB   disk2
                                 Physical Store disk0s2
   1:                APFS Volume VOLUME2                 24.6 KB    disk2s1
0

Actually, I used this workaround.

diskutil partitionDisk /dev/disk0 3 GPT APFS VOLUME1 400M APFS VOLUME2 400M APFS VOLUME3 0b

It create 3 APFS containers, 2 of 400 MB, and with the rest of space going to the APFS container with the volume labeled VOLUME3.

2
  • 3
    Rather than create the VOLUME3, you could have just left free space by using the command partitionDisk /dev/disk0 3 GPT APFS VOLUME1 400M APFS VOLUME2 400M free none R. The word free means free space. Since free space cannot have a name, the word none is just used as a placeholder. The letterR means remainder. In other words, the remaining space after creating all other partitions is left unused. Commented Mar 18 at 10:59
  • Add as answer, please So I can vote and close question
    – elbarna
    Commented Mar 18 at 22:47

You must log in to answer this question.

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