Using RAW Devices In VirtualBox VMs - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2012-07-22 19:16. ::

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

root@vm10:~# 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
root@vm10:~#

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

fdisk /dev/sdb

root@vm10:~# 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.
root@vm10:~#

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

mkfs.ext4 /dev/sdb1

... and mount it:

mount /dev/sdb1 /mnt

 

6 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.