Saturday, September 25, 2021

Cloning a macOS Big Sur partition to a USB Drive (bootable)

I'm using MacBook Air 2013 running macOS Big Sur. This is how I made a bootable backup of my macOS partition to another partition on my USB drive. Apple Software Restore (asr command line utility) allows a user to restore the content of a (system) volume (disk/partition) to another volume or disk image. This can be thought of cloning a partition.

Step 1

My USB drive has 4 partitions as shown in the image below. The internal system volume (source), macOS Big Sur, is going to be restored to NAK-macOSBigSur partition (target) on the USB drive. The partition is formatted as APFS with GUID Partition Map scheme.

NOTE: This post is about restoring from a snapshot of the system volume (which is explained in the next steps). If there is no snapshot and so it won't be specified in the command, the size of target volume (or disk image) must be greater than the size of the source system volume (not just the size of the system volume's content) or the restore will fail. Just make sure the target volume's size is bigger before the restore and then shrink it later.


Step 2

Note down the identifiers of the source system volume, macOS Big Sur, and the target USB's partition. They can be viewed in DiskUtility or from Terminal using this command:



> diskutil apfs list


APFS Containers (2 found)

|

+-- Container disk1 0A4D95E1-BDA4-4BEF-B349-D34D0B1EAD0B

|   ====================================================

|   APFS Container Reference:     disk1

|   Size (Capacity Ceiling):      89999998976 B (90.0 GB)

|   Capacity In Use By Volumes:   65204166656 B (65.2 GB) (72.4% used)

|   Capacity Not Allocated:       24795832320 B (24.8 GB) (27.6% free)

|   |

|   +-< Physical Store disk0s2 E0056EF5-6FCD-4D45-AB00-C7D273999AE5

|   |   -----------------------------------------------------------

|   |   APFS Physical Store Disk:   disk0s2

|   |   Size:                       89999998976 B (90.0 GB)

|   |

|   +-> Volume disk1s1 23C04205-6361-398C-989F-10195CDC66BA

|   |   ---------------------------------------------------

|   |   APFS Volume Disk (Role):   disk1s1 (Data)

|   |   Name:                      macOS Big Sur - Data (Case-insensitive)

|   |   Mount Point:               /System/Volumes/Data

|   |   Capacity Consumed:         47762022400 B (47.8 GB)

|   |   Sealed:                    No

|   |   FileVault:                 No

|   |

|   +-> Volume disk1s2 0300C5AA-7F28-4FB1-9B21-F128B56BD685

|   |   ---------------------------------------------------

|   |   APFS Volume Disk (Role):   disk1s2 (Preboot)

|   |   Name:                      Preboot (Case-insensitive)

|   |   Mount Point:               /System/Volumes/Preboot

|   |   Capacity Consumed:         284585984 B (284.6 MB)

|   |   Sealed:                    No

|   |   FileVault:                 No

|   |

|   +-> Volume disk1s3 FF1FA02B-5C9E-41E9-8193-4676E5DC57D3

|   |   ---------------------------------------------------

|   |   APFS Volume Disk (Role):   disk1s3 (Recovery)

|   |   Name:                      Recovery (Case-insensitive)

|   |   Mount Point:               Not Mounted

|   |   Capacity Consumed:         623341568 B (623.3 MB)

|   |   Sealed:                    No

|   |   FileVault:                 No

|   |

|   +-> Volume disk1s4 A0B8A157-01F7-4563-9C6A-CC869FE11FB5

|   |   ---------------------------------------------------

|   |   APFS Volume Disk (Role):   disk1s4 (VM)

|   |   Name:                      VM (Case-insensitive)

|   |   Mount Point:               /System/Volumes/VM

|   |   Capacity Consumed:         1074819072 B (1.1 GB)

|   |   Sealed:                    No

|   |   FileVault:                 No

|   |

|   +-> Volume disk1s5 8C1ADEAE-7361-415F-AEBF-C64BD1C00146

|       ---------------------------------------------------

|       APFS Volume Disk (Role):   disk1s5 (System)

|       Name:                      macOS Big Sur (Case-insensitive)

|       Mount Point:               Not Mounted

|       Capacity Consumed:         15330869248 B (15.3 GB)

|       Sealed:                    Broken

|       FileVault:                 No

|       |

|       Snapshot:                  9942DBA2-5C5C-4A6C-B099-79AE2C7B011D

|       Snapshot Disk:             disk1s5s1

|       Snapshot Mount Point:      /

|       Snapshot Sealed:           Yes

|

+-- Container disk3 FD345835-64FB-4924-962B-FB26C2B8F980

    ====================================================

    APFS Container Reference:     disk3

    Size (Capacity Ceiling):      76559953920 B (76.6 GB)

    Capacity In Use By Volumes:   122478592 B (122.5 MB) (0.2% used)

    Capacity Not Allocated:       76437475328 B (76.4 GB) (99.8% free)

    |

    +-< Physical Store disk4s5 17F2CE1B-2E10-411D-8ECF-0435F949DFAE

    |   -----------------------------------------------------------

    |   APFS Physical Store Disk:   disk4s5

    |   Size:                       76559953920 B (76.6 GB)

    |

    +-> Volume disk3s1 714E92A0-4F22-47A0-A72C-449E389BFC23

        ---------------------------------------------------

        APFS Volume Disk (Role):   disk3s1 (No specific role)

        Name:                      NAK-macOSBigSur (Case-insensitive)

        Mount Point:               /Volumes/NAK-macOSBigSur

        Capacity Consumed:         827392 B (827.4 KB)

        Sealed:                    No

        FileVault:                 No


Step  3

Run Apple Software Restore command as following:


> sudo asr restore --source /dev/disk1 --toSnapshot 9942DBA2-5C5C-4A6C-B099-79AE2C7B011D --target /dev/disk5 --erase --buffersize 32m  


Password:

Validating target...done

Validating source...done

Erase contents of /dev/disk5 ()? [ny]: y

Replicating ....10....20....30....40....50....60....70....80....90....100

Replicating ....10....20....30....40....50....60....70....80....90....100

Restored target device is /dev/disk5s2.

Restore completed successfully.

Apple does not allow restoring a system volume when its seal is broken and so is mine, then specifying the --snapshot option is a workaround to bypass the restriction. The snapshot was created by macOS Big Sur automatically when it updated itself and so it's the OS update snapshot.

The seal is part of Signed System Volume (SSV) technology, which is used to protect a system content on a signed system volume. With SSV, the kernel rejects any data or code (at runtime) that does not have a valid cryptographic signature from Apple to protect the integrity of the system content. I'm not sure if the seal is broken because I once booted into Recovery mode and used DiskUtility to restore the system volume to a USB drive. But, some people on the internet said the seal was broken even for a fresh install of Big Sur. 

/dev/disk1 is the identifier of the (source) system volume's container. The identifier of the system volume can also be used, /dev/disk1s1, in this case.

/dev/disk5 is the identifier of the target USB partition's container. The identifier of the partition can also be used, /dev/disk3s1, in this case.

--buffersize 32m option (32m means 32 Megabytes) makes the asr command run faster than the default buffer size. This is ideal for block-copies between partitions.  The size should be changed and experimented for an optimal value.

And the image below shows how my USB drive's partition changed after restore completed.


macOS Sierra

The asr restore command might throw the error below.

Source volume is read-write and cannot be unmounted, so it can't be block copied.

To solve that, the asr restore command must be run in Mac's Recovery mode (restart the machine and hold Command + R).

macOS High Sierra

The asr restore command always fail at the end. Many people reported the same so I downgraded to macOS Sierra.




No comments:

Post a Comment