APFS Bootable Clone With Command Line
After multiple trial and error attempts, we finally mastered APFS and are ready to share the knowledge on creating APFS bootable backup with macOS command line. Having such copy on an external drive is rather useful in case something disastrous happens to your local disk, you will have an exact copy of the disk that can be connected externally to your Mac and boot it up. Clone copy of your disk will protect you against any physical or software damage to your computer and system disk, by preserving all the essential files and data.
All of the commands below should be used in Terminal app on macOS 10.13 (High Sierra) and macOS 10.14 (Mojave). Highlighted in bold parts should be replaced with your own respective volume name, disk ID, etc.
ONLY for users of macOS 10.14 (Mojave):
You need to assign additional rights to Terminal app. For this, open “Security & Privacy” tab of System Preferences dialog, open “Privacy” tab and select “Full Disk Access”. Click the lock at the bottom left corner, click “+”, select Terminal app in Applications/Utilities folder and add it to the list.
System rsync is rather outdated (its last update was in 2006) and it doesn’t support some parameters necessary for creating a full clone. There are several methods of updating rsync. We advise using Homebrew.
Install Homebrew by using this command in Terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Now you need to install a new rsync version:
brew install rsync
Make sure that rsync has been updated (version 3.1.3 was available at the time we wrote these instructions). If the rsync version hasn’t been updated, try restarting the system, and check rsync version once again.
rsync --version
Using Disk Utility app create an APFS volume on your external disk. Make sure that your external disk use GUID partition scheme. It’s also important that created APFS volume size is equal or bigger than the source system volume. Let's name the external disk volume as BackupClone.
Activate on-disk ownership on your disk volume with the help of vsdbutil tool. Copy/paste the string below into Terminal, change BackupClone part to your external disk volume name and press return:
sudo vsdbutil -a /Volumes/BackupClone
Create full copy of the source system volume on BackupClone volume with the help of rsync tool:
For macOS 10.14:
sudo rsync -xrlptgoXvHS --progress --delete --fileflags / /Volumes/BackupClone
For macOS 10.13:
sudo rsync -xrlptgoEvHS --progress --delete / /Volumes/BackupClone
Now we need to make our clone bootable. To do this we need to create a new Preboot volume in APFS container that includes BackupClone and copy system files from source Preboot volume in there.
Check the current situation with all your volumes:
diskutil list
As a result we see that MyDisk (disk1s1) is the source, and BackupClone (disk3s1) is our clone copy destination:
Create Preboot volume in APFS container disk3 that includes BackupClone:
diskutil apfs addVolume disk3 apfs Preboot -role B
In the new Preboot volume let's create a folder, name the folder exactly as UUID of your volume BackupClone (disk3s1).
UUID can be obtained with diskutil:
diskutil info disk3s1 | grep "Volume UUID"
Result will be like this, but with a different UUID value:
Copy/paste this UUID to create a folder on Preboot volume:
mkdir /Volumes/Preboot/A579A99E-9795-4086-890E-04E2112D1E78
Now mount the source Preboot volume:
diskutil mount disk1s2
Obtain UUID of the source volume and copy system files from source volume to external Preboot volume:
diskutil info disk1s1 | grep "Volume UUID"
Result will be like this, but with a different UUID value:
Copy files using rsync tool:
sudo rsync -xrlptgoEvHS --progress --delete /Volumes/Preboot\ 1/CD9E8D34-F576-3F9B-AF7C-217C860721F4/ /Volumes/Preboot/A579A99E-9795-4086-890E-04E2112D1E78
Unmount Preboot volumes one by one:
diskutil unmount disk1s2
diskutil unmount disk3s2
Run command updatePreboot for your BackupClone (disk3s1):
diskutil apfs updatePreboot disk3s1
Specify the path to boot files folder on your clone volume:
sudo bless --folder /Volumes/BackupClone/System/Library/CoreServices --bootefi
Update dyld's shared cache on clone volume using update_dyld_shared_cache tool:
sudo update_dyld_shared_cache -root /Volumes/BackupClone -force
In System Preferences open Startup Disk tab, then select BackupClone and press Restart button. Your computer will restart and boot up from created BackupClone volume.
Now you successfully created a bootable clone of your APFS disk volume. The next time you need to boot up your Mac from the clone, connect the external drive and start your Mac holding Option (Alt) key, until boot disk selection appears.
For making clone once again, it is enough to implement steps 3, 10 and 12.
If you have questions or want to comment on the article, contact our Support Team.
If you don’t want to spend time on all of the steps above, or you want to create clone backups on a regular basis, try Get Backup Pro. Beyond that, Get Backup Pro will offer: