Using VirtualBox to install an OS to real disk partitions

I have recently discovered a new way to install operating systems to real hardware using VirtualBox. The same principles may apply to other VM programs like QEMU but, VirtualBox is open source, free as in “free beer” and according to their home page, “Presently, VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts and supports a large number of guest operating systems.”

I followed instructions for attaching a real hard disk to a VM in VirtualBox at the following link

Note the following sentence in the article, "Dear reader, your attention is directed at the fact that it is equally straight forward to kill your data when the disc is accessed in this manner. The procedure on how to accomplish this is left as an exercise… "

I am using a desktop PC I built to experiment with running Mac OS X (a “Hackintosh”). It has a fairly complicated partitioning set up to allow it to accommodate Mac OS, Linux, Windows 7 and Haiku using the legacy (non-EFI) boot mode. I chose to use the Linux environment to do this exercise since that is my primary OS at the moment. I had to execute the command:

sudo chmod 777 /dev/sda

so that VirtualBox could access the disk with the appropriate permissions. The storage settings for the VM must be set to use the install media for the OS you wish to install as the optical disks in the VM and the VM must be set up to boot from the optical drive.

Having done all that, installing Haiku was very straightforward. Just boot to the installer, go into drive setup and format the partition you have set aside for Haiku as a BeFS drive and then select it as the target. It only takes a couple of minutes for the actual install and then when the VM is restarting you power it off and then proceed to restart the real hardware. I have a flash drive that was set up to boot and install Mac OS X on non Apple hardware which uses the Chameleon bootloader and I boot into Mac OS and install the Cameleon bootloader from the Mac OS environment.

I suspect that folks not running Mac OS but, running Linux could use GRUB or GRUB2 to boot into Haiku but, I have not used anything other than Chameleon in recent times.

Once the bootloader has been successfully set up, all that needs to be done to reinstall Haiku, is to run the VM again with the iso image of the install media attached as the optical disk. I have used this technique to install Windows 7 and Windows 10 from iso images but, Windows installs it’s own bootloader, requiring that bootloaders that accommodate non-Windows operating systems have to be re-installed. This is a convenient way to test nightly builds on real hardware without having to create install media every time.

Why VirtualBox? Using kvm, just set the disk, like /dev/sdc, as the target to install directly to it.

The first paragraph sort of explains why, cross platform. The second sentence alludes to the possibility of using “other VM programs like QEMU” and we can now add kvm. Finally it was an article I read recently that discussed this method and QEMU and VirtualBox were mentioned by name. I really don’t have any fixed preferences but, I like the fact that I can just download a disk image and install the OS to my hard disk using a VM, which VM is a matter of choice. Before your post, I was not aware of kvm.