Yesterday I talked about breaking all sorts of rules and replacing both the hardware and the software on a company-owned Lenovo W541. All in all, I'm happy to have turned the notebook into a useful piece of kit, but I still need to use the Windows installation my employer provided in order to access certain network resources. Dual-booting is not an option, so this means using a virtual machine. The question now is how we can take a company-supplied Windows installation and turn it into something that VirtualBox can use.
Oddly enough, the process is not as difficult as you might expect.
Disclaimer: Just because we can do a thing does not mean we should do a thing. I'm in a rather unique position with my employer which grants a certain amount of freedom and flexibility with regards to computing. Not everybody is this lucky. Be sure to consider any possible consequences of your actions if you plan on doing things to hardware you don't own. That said, if you're doing this to machines you have complete control over, I hope this document provides some value.
Mark Russinovich over at Microsoft released a very, very useful SysInternals tool called Disk2VHD and you can get it for free from the Microsoft site. Do yourself a favour and only get it direct from Microsoft. It's pretty small, coming in at under a megabyte and it has everything you need to make your current Windows installation into a virtual machine image that is readable by VirutalBox (and other virtual machine engines). You will need to run this from within Windows, and It needs both administrator access and a bunch of free disk space. When you make an image of your current hard drive, you will need at least that much free space for the destination file.
When you go to make an image, be sure you also include the boot volume and uncheck the "Use Vhdx" checkbox. I didn't do this the first time, and it meant having an non-bootable
.vhd file. I then had to boot into Windows and start all over again. I suggest playing it save and copying all of the strangely-named volumes, plus the Windows partition. You probably won't see the
¥ symbols in your volume names if you are in an English speaking country. Windows in Japan is really, really hard to look at.
Once you're happy with all of the settings hit the "Create" button and let the computer do its thing. Depending on the size of the image and the speed of your drives, the process can take anywhere between five minutes and many, many hours. Doing this before going to lunch is probably a good idea.
Once your file is made it's time to bring it over to Ubuntu. Unfortunately, it's not a simple process to get it working.
.vhd to a
VirutalBox can use
.vhd files, but I opted to convert the image to a
.vdi so that I could manage the file with VBoxManage. It's a proprietary format, but the advantages of using VirtualBox's built-in tools to resize or compress the images outweighs data portability for me. Also, I don't use other VM software, so cross-compatibility is a non-issue at this time. If you're not interested in converting the file to a
.vdi, jump down to "Using the
.vdi" and mentally replace the file extension with
.vhd in your head.
Now, unfortunately, I had a bit of trouble converting the image with VirtualBox 5.0.16, and was forced to temporarily install 4.3. If, like me, you have VirtualBox 5.0 installed, you can uninstall it with the following commands:
sudo apt-get remove virtualbox-\*
sudo apt-get purge virtualbox-\*
From here you can install 4.3.x. Now you'll also need to make sure that your machine has the current kernel headers installed, otherwise VirutalBox will complain when you try to convert the file. You can do this from the terminal with the following command:
sudo apt-get install linux-headers-$(uname -r)
Now, at last, you can convert the file. From the terminal, type:
VBoxManage clonehd /path/to/VHD /path/to/new/VDI —format VDI
This process might take a while, so give the computer some time. This would be a good opportunity to get up and walk the dog or use the washroom.
To use the
.vdi file we need to first create a new virtual machine image. For this I decided to create the image in VirtualBox 4.3 in the event something went wrong and I'd have to try again. Luckily, that didn't happen. Either way, here's the process. First, create a new Virtual machine and give it a good, descriptive name.
From there, click "Next" and set the amount of memory to dedicate then "Next" again to show the storage options. Here you'll want to choose "Use an existing virtual hard disk file" and select the one you just created.
From here you can hit "Create" and voila! You are now the proud virtual operator of an exact image of your Windows machine! Be sure to configure the hardware to include just the things you need, set up some shared folders so that you're not running Dropbox in the VM and on the host, and go to town.
Wait … Why?
One question that some people have asked me is why I would go through all this trouble. I spend a great deal of my day at the office using Windows, so why not just leave the computer as it was and run everything in Windows?
A valid question. My reasoning is simple. When bad things happen, Windows becomes a liability. Did IT push out an update that messed up your computer? No problem. Grab a back up of your VM (you do keep backups … right?) from the night or week before. So long as all of your important data is not kept on the Windows VM, it's all good. You can be up and running again in less than five minutes. Did you somehow contract a virus? Same thing. Kill the VM, copy a backup. Did a recent Windows Update turn your once-speedy computer into a sluggish pile of plastic and silicon? Once again, kill the VM and copy a backup.
I really don't like downtime, and using VMs allows me to very quickly recover from loss or throw away an OS update if something goes awry. Even if the Ubuntu host were to suffer from a serious failure, I'd be able to bring the VMs from the backup over to another computer running VirtualBox and (mostly) pick up where I left off within minutes. You can't tell me that any corporate IT department could get you a replacement computer or roll back a bad update in less time than it would take to copy a
.vdi from an external or networked hard drive.
So there we go! The work Lenovo is Ubuntu under the covers, and has the "approved" Windows image available any time its needed with far more versatility than most IT departments can offer. I'd call this a win-win.