see original here: https://www.belightsoft.com/products/resources/apfs-bootable-clone-with-command-line
We'll be cloning / to a new APFS partition using rsync, then we'll be making the preboot volume and creating
some files inside so boot works. Also using bless and updating system cache to make it bootable via mac itself.
- Install a new rsync using brew
- Install the clone's storage media, format as APFS using disk utility, call it Mac
- Assuming /Volumes/Mac is mounted, run
sudo rsync -xrlptgoXvHS --progress --delete --fileflags --exclude /Volumes / /Volumes/Mac
- let's add a preboot volume to your target disk
diskutil listto find the BSD disk identifier of the source and target disks.- Assuming / is
disk2s1and Mac isdisk3s1, note the base disk of Macdisk3. Run sudo diskutil apfs addVolume disk3 apfs Preboot -role B- This will automount the new preboot at /Volumes/Preboot
- Find Mac UUID using
diskutil info disk3s1 | grep "Volume UUID", assume it is2FCEE275-84D0-4140-A4B7-40C0170A2EB3 sudo mkdir /Volumes/Preboot/2FCEE275-84D0-4140-A4B7-40C0170A2EB3diskutil listagain, search for / Preboot volume identifier, assume is isdisk2s2sudo diskutil mount disk2s2, should mount at/Volumes/Preboot 1, which is stupid- Find / UUID using
diskutil info disk2s1 | grep "Volume UUID", assume it is91C1A3BA-EC18-4842-B5A4-3576343E7A06 - Rsync /Volumes/Preboot\ 1/${UUID} to Mac /Volumes/Preboot/${UUID}, note the whitespace "\ " escape on the Preboot 1 volume name
sudo rsync -xrlptgoXvHS --progress --delete /Volumes/Preboot\ 1/91C1A3BA-EC18-4842-B5A4-3576343E7A06/ /Volumes/Preboot/2FCEE275-84D0-4140-A4B7-40C0170A2EB3diskutil unmount /Volumes/Preboot\ 1diskutil unmount /Volumes/Preboot- Update Preboot for Mac, run
sudo diskutil apfs updatePreboot disk3s1
- Some tidybit to make mac bootable by macs
sudo bless --folder /Volumes/Mac/System/Library/CoreServices --bootefisudo update_dyld_shared_cache -root /Volumes/Mac -force
While this is the best set of steps for cloning a macOs disk, I can't say it worked for me. It did, however, give me a crucial understanding of several key things like the preboot. I had to resort to a regular macOs installer to make the target disk bootable (some installer magic I guess) but I use a specific bootloader so that might have been the issue or something else really (I don't know)