Browse By

Directly mount disk in virtualbox vm

At some point I came across the need to use a Linux VirtualBox VM to dd to SD card inserted into my mac. You might need this to dd an image of an OS or just access the disk directly for what ever reason maybe formatting? Eg. Format a disk in EXT using a Linux VM on a mac.

First insert the SD card and check where it has been mounted using the following commands,

The first disk0 being your hard drive and the second disk1 being the SD card you can gernerally tell by the size and by referencing the Disk Utility app for mac. WARNING **If you are unsure DO NOT continue you may cause your computer to become unusable requiring a reinstall of the OS**

An issue with Mavericks and I believe Mountain Lion is that these disks get mounted as root:operator which means your user cannot modify them so we’ll need to change the owner of these devices and verify with ls;

Once that is done we can create the Virtualbox Rawdisk using VBoxManage internalcommands

If you get an error “VERR_RESOURCE_BUSY” like below its because the disk you are using has a partition that has been mounted. You can “unmount” the partition in Disk Utility just don’t “Eject” the whole disk.

At any point during this tutorial (Even when starting the VM) if you get a disk busy the partition has been mounted, just unmount it.

Now that we have created the raw vmdk we can attach it to the VM and we are done.

Open Virtualbox, right click your machine -> Settings -> Storage -> “Add Hard Disk” icon on the SATA Controller -> Select your disk1.vmdk file or what ever you called it. OK -> OK -> and your Done! Start your VM and you should be able to see the disk for linux sudo fdisk -l should show you the same disk parameters (size partitions etc) as diskutil list (/dev/sdb is the SD card from earlier)

 

One thought on “Directly mount disk in virtualbox vm”

  1. Eduardo says:

    Thanks for this tutorial.

    When I try to open the file in Virtualbox -> storage, the file appears greyed out (as in no vmdk types allowed). Then when I select All files, I get:

    Failed to open the optical disk file /file.vmdk.

    Permission problem accessing the file for the medium ‘/file.vmdk’ (VERR_ACCESS_DENIED).

    Result Code: VBOX_E_FILE_ERROR (0x80BB0004)
    Component: Medium
    Interface: IMedium {05f2bbb6-a3a6-4fb9-9b49-6d0dda7142ac}
    Callee: IVirtualBox {fafa4e17-1ee2-4905-a10e-fe7c18bf5554}
    Callee RC: VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)

    Version: 4.3.28
    Host: Yosemite

    Thanks again for any help.

Leave a Reply

Your email address will not be published. Required fields are marked *