How to create an APFS partition using the terminal?
Hello everyone.
Preface:
I have an NVMe SSD and a box for connecting an SSD via USB. I want to make a multi-boot disk with different operating systems (including macOS) from this kit.
Also I need an EFI partition larger than the standard 200 MB.
That's what I was doing:
1. Connected the disk via USB
2. In the disk utility, the entire disk was formatted in APFS
3. Using the
diskutil list
command, I looked at the status of the partitions on the attached disk
4. Then, using the
sudo gpt -r show /dev/disk3
command, I looked at the state of the partitions in more detail
5. Using these commands, I deleted the EFI and APFS partitions
diskutil unmountDisk disk3
sudo gpt remove -i 1 /dev/disk3
diskutil unmountDisk disk3
sudo gpt remove -i 2 /dev/disk3
(yes, after deleting each partition, the entire disk had to be unmounted)
5.1 And looked at the disk information to make sure. that the partitions are deleted
diskutil list
sudo gpt -r show /dev/disk3
6. Using this command, I found out the size of the sector on the disk
diskutil info /dev/disk3 | grep "Block Size"
Device Block Size: 512 Bytes
7. I want to create an EFI partition with a size of 350 MB and it is 367001600 bytes or 716800 sectors
To create this EFI partition I run this command
sudo gpt add -b 40 -i 1 -s 716800 -t efi /dev/disk3
8. The next partition I want to create an APFS partition with a size of 100 GB is 107374182400 bytes or 209715200 sectors and for this I execute this command
sudo gpt add -b 716840 -i 2 -s 209715200 -t apfs /dev/disk3
9. Checked that both partitions are really created
diskutil list
sudo gpt -r show /dev/disk3
And after that, some kind of non-functional APFS container is created.
With this command, I tried to create a volume in the APFS container
sudo diskutil apfs addVolume /dev/disk3s2 APFS TestAPFS
but this error appears
Error starting APFS Container creation: The given disk is not an APFS Container Reference (-69630)
I am trying to create an APFS disk in place of the current APFS partition
sudo diskutil apfs createContainer /dev/disk3s2
but also got an error
Error: -69614: The disk is already in use by APFS
And even when I tried to delete this APFS container
sudo diskutil apfs deleteContainer /dev/disk3s2
I got an error
Unable to look up the APFS Container Reference for the given Physical Store
I also tried to reformat the APPS section to APFS, using this command
sudo diskutil eraseVolume APFS TestAPFS disk3s2
but it didn't help
After that, I opened the disk utility and in the hierarchy of the connected disk there was a dark gray name of the 100 GB partition and it was called, like, "Physical Location" (something like that). I formatted it in APFS and eventually formatted the entire disk into 1 APFS partition and the EFI partition became 200 MB again.
How to create a working APFS partition using the terminal correctly, so that it is the same as the disk utility does?
P.S.
Here are the articles I relied on:
https://apple.stackexchange.com/questions/280405/create-an-efi-partition
https://www.transscendsurvival.org/2019/02/27/mac-osx-fixing-gpt-and-pmbr-tables/
https://eclecticlight.co/2017/04/08/how-to-make-your-own-apfs-volume/
Mac Pro