Tuesday, December 14, 2010

Virtualize a Windows7 Partiton from Linux, No Reprocutions.

I recently purchased a Lenovo ThinkPad Edge 14. While wanting to take full advantage of the VT extensions using Linux and a Windows 7 virtual machine with VirtualBox, as well as booting natively into Windows transparently. I started a study of the latest VT technologies as well what those have done in the distant past. What I found was a solution that worked well yet required constant repair. As a sysadmin, this wouldn't do and there had to be a better solution. This post outlines just this. My setup requires no repairing in Windows7.

What you'll need is a dual boot system. Windows7 + Linux of your choice. Anything kernel 32 or later should do as you'll be using grub2. For myself I use CrunchbangLinux Statler. Anything Debian based, Ubuntu or Debian Squeeze should suffice. The new Fedora/Arch/ or Centos based releases should suffice too as they'll be using grub2.

1.)First

Once inside the 3rd partiton of your Linux

$ sudo fdisk -l

or

# fdisk -l

should produce something similar:



(note, my partitioning scheme is very complex, as long as it is NTFS in the first 2 you are ready to roll)

2.) Second

Lets install VirtualBoxOSE on a debian based system or other.

Debian based
$ sudo apt-get install virtualbox-ose

Fedora based
$ su -c yum install virtualbox (or virtualbox-ose, it's been a while)

Arch based
$ sudo pacman -Sy virtualbox or # pacman -Sy virtualbox

once VirtualBox is installed you need to load it by typing the following command in a terminal, clicking an icon, or launcher
$ virtualbox

3.) Third

Now we are ready to setup our VM.

You need to add yourself to the disk group to allow VBox access to the Windows Partition.

$ usermod -a -G disk (username)

logout and log back into your desktop or session

This will allow you to do the creation of your rawdisk partition based VM withought editing the permissions on a dev filesystem node, which I would strongly discourage.

Now you are ready to create your VM. Lets first make the harddrive for the VM.

$ VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/HardDisks/win7.vmdk -rawdisk /dev/sda -partitions 1,2 -relative -register

now that part is what you need to pay attention too, according to my fdisk -l my win7/NTFS partitions were on sda1 and 2 where you'll need to substitute yours. As this is the most common on sda1 and 2 we'll just go with it.

4.) Finalize your VM and use it!!

now you'll need to fireup virtualbox for real and create the VM properties for the first boot.

$ virtualbox or click on the icon

you'll need to do the new vm wizard

The only thing important to note in this process is not to mmake a new Virtualharddisk, use the existing win7.vmdk one we just made :P

I give it 1024 ram and 1 proc as well as bridged networking. But that is all accordin to your discression. Everything should work fine now except for the boot sector. You'll need a grub disk to get it to fire off correctly.

For this go over to supergrubdisk.org and get the "super grub2 disk" set this for the iso on your ide drive in the win7 VM properties.

Now boot your vm and make sure you autolist os's from the first grub entry. You'll see windows7. Hit enter and be patient. You should now be set!!

1 comment: