Mounting mac vm vdi on macos with vboximg-mount

The vboximg-mount utility that comes with the VirtualBox on macOS is quite handy, but currently the documentation is patchy and sometimes just misleading ☹️ Here’s my account on how one could use it to access macOS virtual drive from macOS host.

  1. Figure out disk image or snapshot UUID

    I need the latest snapshot.

    $ vboximg-mount --list --verbose
    
    # skip - skip - skip #
    VM Name:   "macosvm"
    UUID:      98326baf-1c57-4033-b9a5-677b5a4c1234
    Path:      /Volumes/VMs/macosvm/macosvm.vbox
        Image:   hdd.vdi
        UUID:    06a1d86b-505a-4dc8-9968-ee0c37d61234
        Path:    /Volumes/VMs/macosvm/hdd.vdi
        Format:  VDI
        Size:    17.6G
        State:   created
        Type:    normal
             Snapshot: c07632b7-99da-4b1c-a0bc-525323d61234
             Name:     {c07632b7-99da-4b1c-a0bc-525323d61234}.vdi
             Desc:
             Size:     12.4G
             Path:     /Volumes/VMs/macosvm/Snapshots/{c07632b7-99da-4b1c-a0bc-525323d61234}.vdi
             Snapshot: 8320da18-20fd-4d10-9b12-3b6eaeaa1234
             Name:     {8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi
             Desc:
             Size:     2.0M
             Path:     /Volumes/VMs/macosvm/Snapshots/{8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi
  2. List partitions in selected image / snapshot
    $ vboximg-mount --list --image '8320da18-20fd-4d10-9b12-3b6eaeaa1234' --verbose
    
    Attempting to lock medium chain from leaf image to base image
      {8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi ... Locking for read
      {c07632b7-99da-4b1c-a0bc-525323d61234}.vdi ... Locking for read
      hdd.vdi ... Locking for read
    
    Creating container for base image of format VDI
    
    Opening medium chain
      Open: /Volumes/VMs/macosvm/hdd.vdi
      Open: /Volumes/VMs/macosvm/Snapshots/{c07632b7-99da-4b1c-a0bc-525323d61234}.vdi
      Open: /Volumes/VMs/macosvm/Snapshots/{8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi
    
    Virtual disk image:
    
       Base: /Volumes/VMs/macosvm/hdd.vdi
       Diff: /Volumes/VMs/macosvm/Snapshots/{8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi
       UUID: 8320da18-20fd-4d10-9b12-3b6eaeaa1234
    
    Partition   Boot   Start  Sectors     Size     Offset  Type                  
    hdd.vdi(0)            40  409600    200.0M      20480  EFI system partition
    hdd.vdi(1)        409640  66699184   31.8G  209735680  Mac OS X APFS

    ⚠️ Note that hdd.vdi(1) is a container that holds the target partition and some more stuff.

  3. Mount the disk image / snapshot
    $ mkdir /tmp/imgmount
    
    $ vboximg-mount --image '8320da18-20fd-4d10-9b12-3b6eaeaa1234' --root /tmp/imgmount
    
    $ ls -l /tmp/imgmount
    
    total 134217648
    -rw-r--r--  1 4294967295  nogroup  34359738368 26 авг 16:10 vhdd
    -rw-rw-rw-  1 root        wheel      209715200  1 янв  1970 vol0
    -rw-rw-rw-  1 root        wheel    34149982208  1 янв  1970 vol1
    lr--r--r--  1 root        wheel              0 26 авг 15:10 {8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi -> /Volumes/VMs/macosvm/Snapshots/{8320da18-20fd-4d10-9b12-3b6eaeaa1234}.vdi
  4. Create block devices
    $ hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount -readonly /tmp/imgmount/vhdd
    
    /dev/disk2              GUID_partition_scheme
    /dev/disk2s1            EFI
    /dev/disk2s2            Apple_APFS
    /dev/disk3              EF57347C-0000-11AA-AA11-1234567
    /dev/disk3s1            41504653-0000-11AA-AA11-1234567
    /dev/disk3s2            41504653-0000-11AA-AA11-1234567
    /dev/disk3s3            41504653-0000-11AA-AA11-1234567
    /dev/disk3s4            41504653-0000-11AA-AA11-1234567

    ⚠️ Note that the container partition is mapped to /dev/disk2s2 and all the partitions within it are mapped to /dev/disk3s*.

  5. Find target partition

    The volume name of the target partition is VirtualHD.

    $ diskutil list
    
    # skip - skip - skip #
    /dev/disk2 (disk image):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        +34.4 GB    disk2
       1:                        EFI EFI                     209.7 MB   disk2s1
       2:                 Apple_APFS Container disk3         34.1 GB    disk2s2
    
    /dev/disk3 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +34.1 GB    disk3
                                     Physical Store disk2s2
       1:                APFS Volume VirtualHD               21.5 GB    disk3s1
       2:                APFS Volume Preboot                 45.4 MB    disk3s2
       3:                APFS Volume Recovery                522.9 MB   disk3s3
       4:                APFS Volume VM                      20.5 KB    disk3s4
  6. Mount target partition
    $ mkdir /tmp/virtualhd
    
    $ diskutil mount readOnly -mountPoint /tmp/virtualhd /dev/disk3s1
    
    Volume VirtualHD on /dev/disk3s1 mounted
  7. Do what you gotta do with the target partition
    it flows man
    🤣😂🤣😂🤣
  8. Unmount target partition
    $ diskutil eject /tmp/virtualhd
    
    Disk /tmp/virtualhd ejected
  9. Remove block devices
    $ hdiutil detach /dev/disk2
    
    "disk2" unmounted.
    "disk2" ejected.
  10. Unmount disk image / snapshot
    $ umount /tmp/imgmount
    
    $ ls -l /tmp/imgmount
    
    # It's empty
Mounting mac vm vdi on macos with vboximg-mount

5 thoughts on “Mounting mac vm vdi on macos with vboximg-mount

    1. Haijiang says:

      Hello again. Have you figured out how to mount it as writable? I have tried many times, tweaked here and there, but still got ReadOnly mount

      Like

      1. Removing the readonly flags in step 4 and 6 didn’t do the trick it’s still readonly, also tried putting the mount point somewhere else other than /tmp/ and that didn’t work either. Is there a readwrite flag that can be used?

        Like

      2. Just to be sure in pp.3~6 you did smth like this:

        mkdir "$SOME_DIR"
        vboximg-mount --image "$UUID" --root "$SOME_DIR"
        hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount "$SOME_DIR"/vhdd
        mkdir "$YET_ANOTHER_DIR"
        diskutil mount -mountPoint "$YET_ANOTHER_DIR" "$DEV"

        And after that you ended up with a partition mounted read-only? What does the mount has to say on this? May be you could post here the appropriate line from the mount output?

        I don’t have a testbench to replicate those steps right now, but afair this worked for me back then.

        Are you sure it’s a mounting issue and not smth to do with access rights on the mounted FS, for example?

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s