The idea is that if virtualization enables you to run an additional machine on an additional (virtual) disk represented by an image file, it should also be able to operate on the actual disk and in this way convert dual booting from serialized to parallelized. And indeed VirtualBox can do it and the documentation is in its manual, chapters 9.9 "Using a raw host hard disk from a guest" and 9.9.2 "Access to individual physical hard disk partitions".
Prerequisites
Caution: accessing one file system from two machines at once is a sure way to corrupt it and lose data. VB gives you some protection but you still have to be careful. One thing, you must not share a swap partition between the two systems. Also, make sure that you do not have the other system's partition mounted, especially as a "quickie" on /mnt.Setting up
Change this according to your needs:DISK=/dev/sdaGive yourself access rights to the other system's partitions (LOGNAME is preset by bash):
SWAP=5
ROOT=6
sudo setfacl -m u:$LOGNAME:r $DISKCopy the bootloader of the other system to a file:
sudo setfacl -m u:$LOGNAME:rw $DISK$SWAP $DISK$ROOT
dd if=$DISK$ROOT of=/tmp/boot.bin bs=512 count=1Create a virtual disk to refer to the other system's partitions:
VBoxManage internalcommands createrawvmdk -register \That's quite a mouthful so let's go over the options:
-filename ~/.VirtualBox/VDI/other-system.vmdk \
-rawdisk $DISK -partitions $SWAP,$ROOT \
-relative -mbr /tmp/boot.bin
- register is a convenience setting that attaches the created disk to the VB disk manager.
- filename is the virtual disk being created and it must be an absolute path.
- rawdisk is the device of the whole target disk.
- partitions restricts the access to these partitions. Other partitions will be visible but appear to contain only zeroes.
- relative means that we will be able to drop access rights to the whole disk (see the next command) and retain only those to the used partitions
- mbr specifies bootloader code to be used (partition info is still taken from the real MBR). That is important since in my case the real MBR references GRUB's menu.lst from sda1. That partition will appear as empty and GRUB would fail with "Error 17". So I give VB the boot record of the other system which references menu.lst on its own, visible, partition.
sudo setfacl -x u:$LOGNAME $DISKNow create a new machine in VB and attach the vmdk to it.
(there is a CLI way but I just clicked in the GUI)
Running it
Make sure that the other partitions are not used: (Hmm, VB should do that by itself. Must file a bug for that...)sudo swapoff $DISK$SWAPClick Play and have a lot of fun.
sudo umount $DISK$ROOT
If you used the defaults when partitioning, you will not get very far because the initrd will not find the disk. The bootloader refers to it by its ID but it is no longer /dev/disk/by-id/ata-TOSHIBA_MK8032GAX_Y6EAT0PKT-part6 but rather .../ata-VBOX_HARDDISK_VB22889591-0c34ac94-part6. The workaround is to edit the GRUB menu on the fly (ESC, Enter, (E)dit, ..., (B)oot) and to replace the long strings by the short names like /dev/hda6. The fix is to use paths from /dev/disk/by-uuid.