This question is rather theoretical:

Suppose I have a PC with two different OS on two different partitions: OS1 on sda1 and OS2 on sda2. Is it somehow possible to set up a program like VMWare or Virtualbox in OS1, which accesses sda2, boots it and runs OS2? On the other hand OS2 should be bootable directly, as well.

I realize that the emulated OS2 would be an awful lot slower and probably noone would really use this setup, but I find this very interesting.


It's possible, yes, and it doesn't necessarily have to be slower, since these days it's not emulation anymore, it's virtualization – most CPUs support hardware-assisted virtualization (VT-x and such), but even without those, VirtualBox has many tricks for making software-virtualized VMs run fast.

In any case it won't be any slower than booting up a plain old VM. It might even be faster (due to using a raw partition instead of a fragmented disk image).

But I'm not entirely sure about how to do it in VirtualBox – I think you must create a special .vdi file using vboxmanage that points to the real partition? Also, I've no ideas about how to make the bootloader work in such a situation.

Though I used to debug various boot issues on Linux by running a read-only copy of the current OS within itself, using qemu-system-x86_64 -enable-kvm -hda /dev/sda -snapshot -monitor stdio.

| improve this answer | |
  • 6
    You man you actually ran a OS virtualized inside itself? – Wauzl Oct 26 '15 at 13:04
  • 8
    Sure, why not? It is not very different from running a regular VM. The only important part is -snapshot, which makes a temporary copy of /dev/sda (so that both systems won't clobber each other's data). – user1686 Oct 26 '15 at 13:07
  • 6
    Your tentative statement on using vboxmanage so setup a VDI (not VHD) as placeholder for the raw partition is correct. The VBOX manual explains it in detail. I like your debugging trick. Never though about doing it like that but I'm already thinking of some use-cases ;-) – Tonny Oct 26 '15 at 13:35

qemu will let you use block devices like /dev/sda2, etc. as virtual hard drives. VMWare does as well. Not sure about Virtualbox.

When you boot /dev/sda2 in a VM, it will have a similar effect as though you took a hard drive out and booted it in a different computer with different hardware. If the OS can handle that change, then you should be OK running the OS both in a VM and natively. Windows will give you problems, of course, and Linux will likely tolerate it very well.

You can mitigate potential problems by making the virtual hardware match as closely as the physical hardware on your system as possible - though of course you'll have to specify less RAM. Of particular importance is specifying the same type of disk controller (IDE, SCSI, etc.).

| improve this answer | |
  • 8
    Apparently virtualbox can do this also using the 'VBoxManage internalcommands createrawvmdk' comand (seen here ) – Michael B Oct 26 '15 at 13:35

It is completely possible, in fact, I used to do this!

I had one partition / disk (I forget which) with Windows one with Linux, I think it was in the days of Windows XP (admittedly, that did last for a while). It was a good way of having access to both sets of data without using a load of disk space with different installations.

The only issue I remember having was that I needed to set up two different hardware profiles in XP. It got really confused when it booted into the wrong ones.

I'm not sure how current activation processes would respond to the switching of hardware. That could well cause some issues... (but if you only ever boot Windows as a physical machine, and have Linux as a VM / or physical, that would solve that)

As I recall I did this with VMware workstation. That definitely supports booting from a raw disk. I'm sure the MS version does. I'm not so sure about the Linux VMs, but I'd be very surprised if not.

| improve this answer | |
  • Oh, hardware profiles... I have never actually touched that feature. Licensing would definitely ruin it now. – sinni800 Oct 26 '15 at 13:27
  • @sinni800 This was my only time ever using them, according to this they still exist, but have moved to the driver kit as devconx64.exe – Michael B Oct 26 '15 at 13:31
  • Hardware profiles were stripped from Vista and later windows systems – ZAB Sep 2 '16 at 19:31

Interestingly, for those running VMware Fusion on a Mac, with a Windows bootcamp partition, it's possible to start a virtual machine that runs off the bootcamp partition:

VMware Fusion allows you to launch an already-installed Boot Camp partition without affecting its ability to boot natively. This gives you the ability to access a Boot Camp partition from both inside the Mac OS using Fusion, and by rebooting and launching Windows directly.

Note, however:

You may be prompted to reactivate Windows because different hardware is recognized by the operating system.

Source: VMware - Launching your Boot Camp partition in VMware Fusion

| improve this answer | |
  • 3
    They recommend you get their tools installed first so the activation process sees the same "hardware" in both situations. Follow instructions or you will end up talking to Microsoft activation servers on the phone. – Thorbjørn Ravn Andersen Oct 27 '15 at 20:58
  • @ThorbjørnRavnAndersen great advice — thank you – magma Oct 28 '15 at 0:12

I did that. It's pretty useful, but there are some limitations and setting it up isn't trivial.

  • The native-or-VM OS must be tolerant about hardware it runs on. Most Linux distros don't care and just run on anything you boot them on as long as CPU architecture matches. It's not that smooth with Windows. You can also face activation/licensing problems.

  • On Windows, you can't boot OS in a virtual machine while its partition is mounted on host. This is not a big deal, as in this case you'd probably like to boot Linux inside Windows and Windows doesn't support ext filesystems anyway.

  • Setting bootloaders is tricky. You need separate boot configuration for booting in VM and for booting natively. I have used Grub4DOS/NeoGrub as 1st stage bootloader when booting natively, then I was able to chainload Windows bootloader or boot into Ubuntu. VM had a small (few MB) drive mounted with higher priority than the main drive. That drive contained manually installed GRUB2 which I used to boot Ubuntu inside VM.

  • Unusual bootloader setup requires careful updating. For example updating GRUB when running Linux natively could break your bootloader chain. Updating inside VM requires manually installing it to the boot partition.

| improve this answer | |

That is possible quite easily.. If you use seperate hard disks for each installation!

Have a look here for example: http://www.serverwatch.com/server-tutorials/using-a-physical-hard-drive-with-a-virtualbox-vm.html - or search the VirtualBox website (which is down at the moment) for these keywords.

I use it to be able to access my Linux partition when I do some Windows work, like Adobe stuff or other things that wont run that smoothly under Wine or Virtualisation of Windows in Linux.

Also, because I often access my tower remotely - and my whole Linux hard disk is encrypted, while my Windows hard disk isnt and only has non sensitive data on it. So I start up Windows (the Windows entry in GRUB is preselected) log into Teamviewer, start Virtualbox and then my Linux hard disk.

In this direction - Windows -> Virtualbox -> other HD with Linux -> it is possible quite simple, because of the superiour hardware detection, on the fly, that Linux, namely Ubuntu, supports.

In the other direction, you will end up with a mess. Windows doesnt like ever changing hardware.. It could mess up your system, doesnt start at all, or even if it does, maybe tells you that your license isnt valid anymore because too much hardware changes happend too often.

That said, you want to keep Windows as preselected boot entry in GRUB, but really watch out that you select the right entry in GRUB when it runs in Virtualbox. If you have problems with lags remotely, increase your boot timeout in GRUB to be safe.

Hope that helped you :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.