Skip to content

Instantly share code, notes, and snippets.

@tcodes0
Last active November 16, 2020 19:34
Show Gist options
  • Save tcodes0/e375992159e5223638686f0a499c6a12 to your computer and use it in GitHub Desktop.
Save tcodes0/e375992159e5223638686f0a499c6a12 to your computer and use it in GitHub Desktop.
how to clone apfs volumes and make bootable

see original here: https://www.belightsoft.com/products/resources/apfs-bootable-clone-with-command-line

Overview

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.

Media formatting, / cloning

  • 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

Preboot

  • let's add a preboot volume to your target disk
  • diskutil list to find the BSD disk identifier of the source and target disks.
  • Assuming / is disk2s1 and Mac is disk3s1, note the base disk of Mac disk3. 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 is 2FCEE275-84D0-4140-A4B7-40C0170A2EB3
  • sudo mkdir /Volumes/Preboot/2FCEE275-84D0-4140-A4B7-40C0170A2EB3
  • diskutil list again, search for / Preboot volume identifier, assume is is disk2s2
  • sudo diskutil mount disk2s2, should mount at /Volumes/Preboot 1, which is stupid
  • Find / UUID using diskutil info disk2s1 | grep "Volume UUID", assume it is 91C1A3BA-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-40C0170A2EB3
  • diskutil unmount /Volumes/Preboot\ 1
  • diskutil unmount /Volumes/Preboot
  • Update Preboot for Mac, run
  • sudo diskutil apfs updatePreboot disk3s1

Bless and dylb

  • Some tidybit to make mac bootable by macs
  • sudo bless --folder /Volumes/Mac/System/Library/CoreServices --bootefi
  • sudo update_dyld_shared_cache -root /Volumes/Mac -force

Disclaimer

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)

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