Using RAW Devices In VirtualBox VMs - Page 2

5 Mount A RAW Device Inside An Existing VM

Now let's assume we want to add a RAW device as an addtitional partition to an existing VM. I want to add the LVM volume /dev/vg0/vm10storage. Let's create it as follows (with a size of 5GB - this is just an example):

lvcreate -L5G -n vm10storage vg0

Like in chapter three, we need to create a new .vmdk file for this partition before we can use it with VirtualBox:

cd /home/vbox/
VBoxManage internalcommands createrawvmdk -filename vm10storage.vmdk -rawdisk /dev/vg0/vm10storage
chown vbox:vbox vm10storage.vmdk

Now go to the VirtualBox GUI and stop the VM to which you want to add the partition (e.g. Stop > ACPI Shutdown):

After the VM has stopped, go to Storage:

Click on the Add Hard Disk icon next to SATA Controller:

Click on Choose existing disk:

Select the appropriate .vmdk file (vm10storage.vmdk in this case) and click on OK:

Click on OK again:

Now start the VM. After it has started, log into it. The following commands have to be run inside the VM!

You should find the new drive (/dev/sdb in this case) in the output of

fdisk -l

[email protected]:~# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x0003974c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758    41940991    20719617    5  Extended
/dev/sda5          501760    41940991    20719616   8e  Linux LVM

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 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: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/mapper/vm10-root: 20.7 GB, 20661141504 bytes
255 heads, 63 sectors/track, 2511 cylinders, total 40353792 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: 0x00000000

Disk /dev/mapper/vm10-root doesn't contain a valid partition table

Disk /dev/mapper/vm10-swap_1: 532 MB, 532676608 bytes
255 heads, 63 sectors/track, 64 cylinders, total 1040384 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: 0x00000000

Disk /dev/mapper/vm10-swap_1 doesn't contain a valid partition table
[email protected]:~#

You can now use this drive as you would normally do, e.g. partition it...

fdisk /dev/sdb

[email protected]:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x862fb2cf.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):
 <-- n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
 <-- p
Partition number (1-4, default 1): <-- 1
First sector (2048-10485759, default 2048): <-- ENTER
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
 <-- ENTER
Using default value 10485759

Command (m for help):
 <-- t
Selected partition 1
Hex code (type L to list codes):
 <-- 83

Command (m for help): <-- w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[email protected]:~#

... create a file system on it (e.g. ext4)...

mkfs.ext4 /dev/sdb1

... and mount it:

mount /dev/sdb1 /mnt


Falko Timme

About Falko Timme

Falko Timme is an experienced Linux administrator and founder of Timme Hosting, a leading nginx business hosting company in Germany. He is one of the most active authors on HowtoForge since 2005 and one of the core developers of ISPConfig since 2000. He has also contributed to the O'Reilly book "Linux System Administration".

Share this page:

Suggested articles

0 Comment(s)

Add comment


By: Falko Timme