I created the vmdk-file as describe in Chapter 9. Advanced topics and added it to my guest vm. After it, I could mount the entire raw disk up in my linux guest vm. Now I can read the ext4 file system, but I can't write to it. How can I get write access without changing the file system to NTFS? In Win7, I cannot set permissions to that hard disk because it's a raw hard disk with an unknown file system.
Okay, I found a solution by myself. Now, I want to give you detailed instructions about the steps I did to get it working.
VirtualBox 4.2.0 r80737
Host: Windows 7 (64-bit)
Guest: Ubuntu 12.04 LTS (64-bit)
Disk configuration in Win7 (host)
- Close all open programs or documents on any partition on the disk to pass-through.
DISKPART(command line utility) as admin.
LIST DISKto get a list of all available disks and their related ids. (
LIST PARTITIONSif you want to use just a part of the whole disk)
- Select hard drive carefully using
- Offline the disk using
OFFLINE DISK. All disk volumes will disappear from windows explorer.
ATTRIBUTES DISK CLEAR READONLY(important!) to make sure the disk will be writable.
- Verify with
VMDK file creation in Win7 (host)
cmd(command line utility) as admin.
cd "C:\Program Files\Oracle\VirtualBox"
(your path can differ dependent on your VirtualBox location).
VBoxManage internalcommands createrawvmdk -filename /path/RawDisk.vmdk -rawdisk \\.\PhysicalDrive1
(PhysicalDrive1 means second drive)
Add VMDK file to your Linux VM (guest)
- Open VirtualBox Manager
- Select Linux VM > Settings > Storage > IDE Controller > Add Attachment > Add Hard Disk > Choose existing disk > Select VMDK file
- Start Linux VM
Set permissions and mount raw disk
If you use Ubuntu then you should already see the drive in the navigation pane of the file explorer. If you would click on it now, you would just mount the drive read-only to
/media/drivename. To prevent this, open up a terminal and put the following into it:
cd /media sudo mkdir DRIVENAME sudo chown USERNAME DRIVENAME sudo chgrp USERNAME DRIVENAME
(replace DRIVENAME and USERNAME with proper values)
Reopen the file explorer and mount the drive by clicking on its name in the navigation pane. Now you should be able to create files and folders on your raw hard disk.
Of course it is possible to permanently mount the disk via
/etc/fstab, but then you have to
sudo mount the device and the graphical mounting via navigation pane won't work anymore.
After the VMDK file creation I noticed the following line in there:
This option is set by default. If you still run into issues and your raw disk is not an IDE disk but SATA, just change this line to:
Of course then you have to add the VMDK file as SATA Controller to your VM instead of IDE Controller.
The disk will appear in your guest as /dev/sda1 (consult virtual box' docs). You need to mount that drive read-write. The easiest way to configure this permanently is by adding a line to /etc/fstab such as this:
/dev/sda1 /mnt/raw/disk-file/ ext4 defaults 0 2
If you wish to remount the drive read-write on the fly, you may issue the comamnd:
mount -o remount,rw /dev/sda1
Again, this is assuming that the device for the drive is sda1. If you have nothing like that, then I would look trough the output of dmesg scanning for lines with "ATA" or "SCSI" as that will lead you to the device node of the drive. Usually It's really easy to spot in the /dev/ folder. Just look for hd[abcd..] or sd[abcd..][1234...].