Virtualbox Raw Disk Access

Posted by zbrom on August 28, 2017 · 6 mins read

In this tutorial I am going to show you how to change the permissions of a /dev/sdx file to allow you to create a vmdk to boot a Windows installation on another HDD. In this tutorial I am going to use ferb as the user.

NOTE: I have not tried this tutorial with a processor that does not support VT-x/AMD-V. Check your bios to make sure that this is enabled.


WARNING:
Raw disk access is for expert users only. Incorrect usage can lead to massive data loss. Never mount a drive that is being accessed by a virtual machine. Doing so WILL cause unrecoverable data corruption.

As always make sure that you have done backups first.

The first step is to figure out which device contains the Windows install. Run the following command

Code:

fdisk -l

Output:

Disk /dev/sda: 60.0 GB, 60022480896 bytes, 117231408 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0009bad8

Device Boot Start End Blocks Id System

/dev/sda1 2048 526335 262144 83 Linux

/dev/sda2 526336 42469375 20971520 83 Linux

/dev/sda3 42469376 117229567 37380096 83 Linux

Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes, 5860533168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/sdc: 60.0 GB, 60022480896 bytes, 117231408 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xd4c0c6cf

Device Boot Start End Blocks Id System

/dev/sdc1 2048 206847 102400 7 HPFS/NTFS/exFAT

/dev/sdc2 * 206848 117229567 58511360 7 HPFS/NTFS/exFAT

My Windows install is located at /dev/sdc. The next thing we need to do is to give your user read/write access to this file. Use the following code to see the current permissions of the file.

Code:

ls -l /dev/sdc</code

Output:

brw-rw---- 1 root disk 8, 32 Nov 9 03:06 /dev/sdc

We can see here that the user root has ownership of the file and the group is disk. Both users have rw permissions on the file. So in order to give your user rw permissions to the file you must add your user to the group disk. Use the following code.

Code:

usermod -a -G disk ferb

In order for this to take work you must either reboot or log out after running the above command.

Now that your user has the correct permissions we can continue with the real tutorial. In order to make the vmdk we must use the tool VBoxManage. Run the following command.

Code:

VBoxManage internalcommands createrawvmdk -filename /home/ferb/windows_vm/windows.vmdk -rawdisk /dev/sdc

Now that we have a vmdk file for a rawdisk we need to set up the virtual machine. This is much more user friendly because it has a GUI.

Launch Virtual Box. You should see this:

Now click on the icon that says new. You should see this:

Now name your virtual machine and select the type and version:

Click the next button and set the memory. I used 8GB becasue I have 16GB of ram. You will want to set it somewhere in the green space:

Click the next button and browse to your vmdk file:

Click create and you should see something like this:

Click on settings:

Click on System:

Click on acceleration and make sure the following are checked:

To change the number of processors click on processor:

If your Windows is installed on an SSD click on storage:

Next click on your vmdk and select the use as SSD box:

Then click ok and click on start. My Windows is encrypted with both AES and twofish so I see this screen. (I’ll post a tutorial on Windows full system encryption at a later time):

Windows booting:

Windows booted:

As you can see the virtual machine has the amount of ram and processors that you specified in the settings. The virtual machine however does not have Aero running. You must install guest additions to use Aero.

Click on Devices at the top of the virtualbox window and click on install guest additions. If it asks you to download the image say yes. Once it has finished downloading click mount. It should come up in Autoplay:

Click on run:

Click next and check the direct3D box:

Click NO:

Then click OK then click install. When you see the following image check the box and click install:

Now it should start installing:

When you see the following screen click finish:

After rebooting you should be able to enable Aero.