Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My Ubuntu 12.04 install is on /dev/sda5 and Windows 7 is on /dev/sda1. When I am running Ubuntu, I would like to use Virtualbox to run Windows 7 in a VM. The Windows 7 partition is 1 TB and is half full, i.e. large, so I don't want to copy it into a virtual hard disk.

I have read that it is possible to use a real hard disk for a Virtualbox VM, but the various instructions I have found differ from each other, and I can't seem to get it to work. Does anyone know a way to make it work in Ubuntu 12.04 and Virtualbox 2.1.12_Ubuntu r77245 (the latest Ubuntu installed the repos)?

Please post how it works for you as I want to retry any method that might work.

share|improve this question
    
Why is your MSWIN partition 1TiB? Although, not a complete solution: If possible, move everything that doesn't need to be on there (data...media files?) and then re-size the partition which will make any approach easier. If you wanted to go the image route, clearing then shrinking that partition will leave you with enough space to make a full image of the smaller, new partition. :-) –  Alastair Jan 6 at 14:58
add comment

5 Answers

up vote 10 down vote accepted

The command you want is

VBoxManage internalcommands createrawvmdk -filename Win7.vmdk -rawdisk /dev/sda -partitions 1

This will create a special VMDK virtual disk file (Win7.vmdk) which is actually a pointer to the host disk partition /dev/sda1.

In theory, you can then use this as the disk file for a VM to run directly from the actual disk partition, but...

  • (a) I've never tried this, so don't know how reliable it is
  • (b) you may get problems with Windows Activation depending on your license key and whether Windows decides that the detected 'hardware' has significantly changed
share|improve this answer
    
Thank you. I didn't even think about the activation problem. That's sure to put a stop to my plans. –  Jazz Jul 26 '12 at 3:52
1  
In addition, even if it worked (which I doubt) you may seriously damage your Windows when running from both boot, and the VM. –  Takkat Jul 26 '12 at 8:54
    
@ubnewbie2: I'd probably only try this as an experiment and/or when using some sort of Volume Licensing key and I'd probably view it as a one-way operation; i.e. you'd have more difficulties trying to reverse it. I actually run Windows 7 and use a VirtualBox VM with Ubuntu, often in full screen mode so the PC seems only to be running Linux, and would be more confident of running Ubuntu off a raw disk partition. –  StarNamer Jul 26 '12 at 11:19
    
FYI, I have now tried this, in reverse. I needed to change a machine running Ubuntu over to Win 7, so made freed some space by resizing partitions and creating a new one and installed Win 7. This replaced grub2 with he windows bootloader so I then installed VirtualBox and created a new VM, with a minimal virtual disk to book from, which then uses the existing 'raw' partitions to run from. It works OK, although a bit sluggish due to reduced memory and only seeing 1 CPU core (instead of 4). –  StarNamer Aug 7 '12 at 12:55
    
-partitions at the end a list of the partitions you want virtual box to "see" (not the partition # you want to use) VBoxManage internalcommands --help will show you other things you can do with the internal commands, as well as what the options mean. –  Mark0978 Dec 18 '13 at 13:10
add comment

There are two ways to do that

First is to use full disk image (of /dev/sdb)

sudo VBoxManage internalcommands createrawvmdk -filename sdb.vmdk -rawdisk /dev/sdb

Second, as @StarNamer showed, is to use only one (or few) partitions, it will be like that

sudo VBoxManage internalcommands createrawvmdk -filename sda1.vmdk -rawdisk /dev/sda -partitions 1

to create image of just one (/dev/sda1) partition

sudo VBoxManage internalcommands createrawvmdk -filename sda2_1.vmdk -rawdisk /dev/sda -partitions 2,1

to create custom partition table which will map /dev/sda2 and /dev/sda1 in that order.

Most striking difference will be that full disk image will use bootloader and partition table exactly as they are in your disk, so in theory (I did that previously only in qemu) you will be able to setup OS from your virtual machine. And from my limited experience I can say that full disk image will work exactly as qemu -hda /dev/sdb

share|improve this answer
    
"full disk image will use bootloader and partition table exactly as they are in your disk" - under which scenario, the first (/dev/sdb) or the second (with partitions specified)? –  naught101 Jul 22 '13 at 23:39
1  
Also, virtualbox needs to be run as root, otherwise you get Permission problem accessing the file for the medium '/home/naught101/sda2_windows.vmdk' –  naught101 Jul 22 '13 at 23:49
1  
"Also, virtual-box needs to be run as root". Actually no, you need to be a member of group disk. Much safer than running virtual-box as root. –  user193006 Sep 15 '13 at 1:14
add comment

See this detailed howto post I came across for VirtualBox booting a WinXP, Win 7, or Win 8 partition:

Virtualbox-with-existing-windows-partition.

share|improve this answer
2  
You should always try to include the basics from the linked article. At least enough that people can tell it's what they are looking for. –  coteyr May 7 '13 at 16:39
    
@Karl d - Did this work for you? –  Freedom_Ben May 7 '13 at 17:21
add comment

Thats true. don't try this I have burned my fingers & had to re-install Windows & other softwares, so much painful. This was on dual boot Xp & Ubuntu 12.04; after install of winxp grub2 gone!

share|improve this answer
add comment

There is an Disk option called "Immutable", so in theory if you select this option for the vmdk linking to your raw disk, it should not change the original partition.

To do so open "Virtual Media Manager" found under "File", select your image and click "Modify" (You have to make sure this image is not attached to any machine, otherwise you get an error). Now you can set the media type to "Immutable".

I have not tested this, though. If anyone does (of course with a test setup) it would be good to report back here.

Has anyone considerations which speak against this idea?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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