1. Create the target LV:
core:osx# [color=green]lvcreate -L450G -n MacPool450Glv bkupvg[/color] Logical volume "MacPool450Glv" created core:osx# ls -la /dev/bkupvg/MacPool450Glv lrwxrwxrwx 1 root root 32 2012-09-16 20:51 /dev/bkupvg/MacPool450Glv -> /dev/mapper/bkupvg-MacPool450Glv
2. Use VBoxManage tool to link a vmdk filename to the desired LV:
core:osx# [color=green]VBoxManage internalcommands createrawvmdk -filename /home/vbox/osx/MacPool450Glv.vmdk -rawdisk /dev/mapper/bkupvg-MacPool450Glv[/color] RAW host disk access VMDK file /home/vbox/osx/MacPool450Glv.vmdk created successfully.
If you are curios, the file is normal text and it looks like this inside:
core:osx# [color=green]cat /home/vbox/osx/MacPool450Glv.vmdk[/color] # Disk DescriptorFile version=1 CID=34bd16ff parentCID=ffffffff createType="fullDevice" # Extent description RW 943718400 FLAT "/dev/mapper/bkupvg-MacPool450Glv" 0 # The disk Data Base #DDB ddb.virtualHWVersion = "4" ddb.adapterType="ide" ddb.geometry.cylinders="16383" ddb.geometry.heads="16" ddb.geometry.sectors="63" ddb.uuid.image="41fa68c6-5e6c-4f78-8b2a-700412621523" ddb.uuid.parent="00000000-0000-0000-0000-000000000000" ddb.uuid.modification="00000000-0000-0000-0000-000000000000" ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
3. Use this newly crated disk inside a virtual machine but slightly different:
create another disk controller and enable "Use host I/O cache" otherwise you will experience very (very very) bad performance of the entire virtual machine. Example below:
Extra note:
If you want to resize the logical volume, you will have to shut down the machine, remove the disk from virtualbox, delete the vmdk file, resize the logical volume in LVM and redo this tutorial from step 2.
As bonus, will show you below how to convert an lvm partition (or raw device) into vdi image:
1. Create a raw image with dd:
dd if=/dev/mapper/sourcelv of=/path/to/image.raw
2. Convert the raw image to vdi:
VBoxManage convertdd image.raw image.vdi --format VDI
Example:
root@core:~# dd bs=16000 if=/dev/mapper/bkupvg-pluto200g1 of=/images/pluto200g1 13421772+1 records in 13421772+1 records out 214748364800 bytes (215 GB) copied, 3608.66 s, 59.5 MB/s root@core:/images# VBoxManage convertdd pluto200g1.raw pluto200g1.vdi --format VDI Converting from raw image file="pluto200g1.raw" to file="pluto200g1.vdi"... Creating dynamic image with size 214748364800 bytes (204800MB)... root@core:/images#