How To: Migrate a VirtualBox Windows 7 client to VMware Player

Step 0 – [Linux-specific instruction] When installing VMware Player, let it use /etc/init.d/ even if your system uses Systemd. After install you can create a service for vmware like this:

/etc/systemd/system/vmware.service

Start the service with systemctl start vmware to make sure it kicks off. If you want it to start automatically at boot use systemctl enable vmware.

Step 1 – Disable any devices in the virtual machine that run on VirtualBox/Oracle drivers.

Step 2 – Convert the VirtualBox.vdi hard drive to VMDK format via “vboxmanage clonehd source.vdi target.vmdk –format VMDK”

Step 3 – Launch vmplayer and create a new virtual machine. Say that you’ll add the operating system later and let it use a ‘single large drive’ or such.

Step 4 – Replace the default created .vmdk drive with the one you converted in step 2.

Step 5 – You can try booting your VM at this point – if it works, GREAT! But it’s likely to bluescreen with a 0x000007b error, if so you’ll need to follow the rest of the steps below:

With all that done, the Windows 7 client should boot in vmware player and start installing the VMware specific drivers.

Twiddles / Housekeeping

VM audio crackling? Live with it – it crackles for a few seconds then sorts itself out. Fixing it as per the below causes VM crashes with “vcpu-0 unexpected signal 11” errors.
In Windows client go: Control Panel | Hardware and Audio | Sound | Speakers | Properties | set it to 24-bit @ 44.1KHz or higher.
Source: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2012007

VM suspends and stops Linux host from suspending? Shut down the VM, then edit the .VMX file it and add the line suspend.disabled = “TRUE” then restart.

VM generating “spurius APIC interrupt on #CPU X, should never happen”? Edit /etc/vmware/config and add the line monitor_control.disable_hostedIPI = TRUE then restart VM.

How To: Convert VirtualPC .vhd hard drives to VirtualBox .vdi hard drives (or vice-versa)

Don’t bother – VirtualBox now natively supports .vhd drives – how handy is that? =D

But if you really wanted to, just use:

This will place the .vdi version of your drive in your current users VirtualBox folder, which is: ~/.VirtualBox

Relatedly, to go the other way (.vdi to .vhd) you could use:

Note: For this to work, you must not have the drive attached to any virtual machine, so if you already have it connected to a virtual machine, detach it first, mkay?

How To: Shrink/Compress a VirtualBox Windows Guest Machine

When you create a VirtualBox virtual-machine, you get the option to choose either a fixed sized hard drive (in which case the entire amount of space is allocated and fixed immediately), or a dynamically expanding hard drive for the virtual machines OS and file storage (i.e. you specify a maximum size for the hard drive, it starts at 0 bytes, and increases as necessary up to the maximum you gave it on creation – at which point the drive is full).

Linux and Windows via VirtualBox

This is all well and good, but the problem with dynamic storage is that although it’s more than happy to increase in size, it doesn’t come down in size again when data is removed. So, to give an example, if you created a 10GB dynamic disk for a virtual machine it starts off at 0 bytes, you install a 1GB operating system and the drive is now 1GB in size (and hence taking up 1GB of space on your actual hard drive), you rip a 4.7GB DVD to the virtual drive which makes its size now 5.7GB, you delete the DVD rip so only the OS remains – and you might think that the “dynamic” drive will automatically shrink back down to 1GB, only it doesn’t. You’re holding on to 4.7GB of unrecoverable* bloat. Lucky you… =P

You could rip another DVD and re-use that space without the drive expanding any further, but really, it’s just going to increase and increase, and you’ll know in your heart of hearts that when you’re running low on disk space you could really do with that space back to your real hard drive. In VMWare you can compact the drive image as a menu option, but in VB we have to do a three step process… So, shall we?

* = unrecoverable unless you jump through the below 3 hoops, or create a new dynamic drive image, expand it to a size just over the size of your data on your original drive, then raw-copy the data across, that is… IMHO the steps below are easier!

A-B-C, Easy As…

  1. Defrag your Windows guest machine
  2. Now we need to replace all the “blank” (but still taking up space!) areas of our drive with zeros so we can recognise them to be stripped out later. Thankfully, this is really easy. Just download free (and tiny – 47KB) command-line utility SDelete from Microsoft and run it from within your virtual Windows guest machine with the following command (the -c switch is important!):
  3. Once that’s finished running shut down your virtual machine, navigate to the folder where your virtual machine hard drive is (such as ~/.VirtualBox/HardDisks) then from your host system run the following command to compress the hard drive down to a more reasonable size:

    So if your virtual machine name (and thus by default the hard drive name) was “XP_Client_1”, then you’d use:

With that done I trimmed down an excessively bloated 25GB .VDI of Windows 7 into a still excessively bloated 15GB – but that’s just in the nature of Microsoft OS’s… =P

Update: If you get an error stating things along the lines of:

then you can fix it like this:

  1. Detach the drive from your virtual machine,
  2. Edit the file ~/.VirtualBox/VirtualBox.xml and remove all lines with the drive you want to compact mentioned in the HardDrives section (Note: be careful you don’t delete the virtual machine entry itself from the MachineRegistry section! Only remove the drive from the HardDrives section.),
  3. Now you’ll be able to compact the drive, and when it’s done you can re-attach the drive to your virtual machine. Good as old! =D

Snap Happy

Another thing you can do to decrease the disk usage of VirtualBox machines is get rid of all your snapshots if you don’t need them anymore. Each snapshot is basically an entire disk image which you can roll back to, so if you have Windows 7 installed it’s about 7GB or so after a fresh install, if you then put on 500MB of patches and take another snapshot you’re storing another 7.5GB. If you then install Office or something and that takes up 2GB and take yet another snapshot you’re burning through yet another 9.5GB, so we’re up to 23.5GB already for a single 9GB drive!

You should definitely be careful when merging snapshots into the main image (basically getting rid of the snapshots), as it has the potential to break, but more likely it has the potential to confuse and cause you to throw away data you didn’t mean to. This is because of some particularly ambiguous and misleading phrasing used in VirtualBox circles – the crux of the matter being:

  • When you restore a snapshot, it will throw the current state and/or any subsequent snapshots away and leave the machine in the state defined by the snapshot you’re restoring. This can mean a lot of changes which currently exist in the image being undone, and lot of files disappear, for example – the only copy of important documents created since the snapshot you’re restoring was made. Use with care.
  • When you delete a snapshot, it will actually merge the current state of the machine into the snapshot before removing that snapshot and leaving the machine at it’s current merged state but without the snapshot existing…

Yeah, I know it’s confusing, so just be careful, okay? If you’ve got the space available just take a copy of the .VDI file from the HardDisks folder AS WELL AS a copy of the snapshots by copying the folder with the name of your VM from the Machines folder, and then merge in the snapshots – this way if it all goes nuts you can’t throw away the knackered copy and replace it with your pristine pre-merge copies.

Cheers!

Credits: Thanks to Damien for his article at MakeTechEasier for the initial information (you can also find out how to compress Linux guests there too, but just be aware that the technique he outlines involves cloning the drives then shrinking and re-importing them) and to Alphatek’s article for the simplification!

How To: Install Windows 7 Upgrade as a Fresh Install

Update: See the bottom of the post for another method of performing a upgrade install as a fresh install which only needs a single copy of your Windows 7 upgrade disc and nothing else!

Backstory

I’d had enough of fighting with OpenOffice 3.2 today and finally cracked: I bought a copy of Microsoft Office 2010 Professional Academic edition for $49AUD through Microsoft’s It’s Not Cheating program.

However, since I run Linux I thought I’d just get a copy of CrossOver and I’d be laughing, but this was not to be. I ponied up for Office, set it downloading, then went to get CrossOver only to find it only supports up to Office 2007 – and I don’t mean that Office 2010 won’t work 100%, or will be a little eratic – it won’t work at all. Feck!

Okay, so I can always run it through virtualisation (i.e. a VirtualBox or VMWare instance running some variety of Windows), but I didn’t fancy running the latest, greatest Office on a shonky old copy of XP, so I ponied up (again) for a copy of Windows 7 64-Bit Upgrade (that’s another $49AUD through It’s Not Cheating) and created a new virtual machine, installed Windows 7, entered the key at the end of the install, and it told me it wasn’t valid! Double feck!

At this point I’m $150AUD out of pocket with nothing to show for it, and am starting to furrow my brow.

Trying to deal with the key issue later – I just left the key out to get 7 up and running (it’ll go for 30 days without activation) and tried the key again from within the OS rather than from the installer; this time instead of just key invalid I got an error message stating that this key is not valid for a clean install of Windows… Okay.. now we’re getting somewhere – let’s fix this bad boy.

The Fix

There’s a bunch of stuff on the Web about forcing Windows 7 to accept a clean install from an upgrade disc by creating registry keys, running arcane commands (slmgr -rearm etc.), removing config files from the ISO before install etc. – and to be perfectly honest I didn’t fancy re-installing so I had a quick whirl at all of ’em. And guess what? They didn’t work, so I’m not going to post them here. Instead I’ll tell you what worked for me [drumroll please….]:

Installing another version of Windows first.

No, really.

It doesn’t have to be 64-bit if you’re migrating 32-bit to 64, it doesn’t have to be one step below Windows 7 (i.e. Vista), it doesn’t even have to be a legal, valid version of Windows! It just has to be some incarnation of Bill’s Marvelous Blue-Screen Machine, and then when you install Windows 7 on top of the existing install, it’ll recognise a prior version of Windows existed, and your “upgrade” key will work perfectly.

Windows 7 Activation
Ba-da-bing Ba-da-BOOM! Shamone! =P

So in my case, this just meant slapping a copy of XP onto a new virtual machine, then the instant that’s finished installing, just changing over the ISO image mounted on the virtual DVD drive from XP to 7, rebooting, and letting this second version of Windows install.

Once you’ve got Windows 7 up and running, your “old” copy of windows will be sitting in C:\Windows.old, and you can either use the built-in Disk Cleanup tool to remove it or just delete that folder and you’re as good as new*.

* = If you’re doing a native Windows 7 install, once you’ve removed the old install then you’re quite literally good as new. If you’re installing on a virtual box using a hard drive which uses dynamic storage (i.e. you allocate, say, 60GB for the HD, but it doesn’t take up any space to begin with, it only takes up space when data is added to the drive) then the space allocated for the old Windows install can’t be fully recovered because dynamic disks can take up more space, but do not resize back down to take up less space when you remove data! But you’re going to put more than 700MB of additional stuff on it anyway, right? So just remove the old Windows install before installing new apps and the like and you’ll break even!

Windown 7 - Remove Previous Windows Installations

It’s not a glamorous hack or sneaky workaround, but it does work, and who doesn’t have an old copy of Windows sitting around somewhere? If you’re feeling particularly cheeky you could try it with a copy of Windows 3.1 or 95 installed and see if it still upgrades clean ;-)

Update: I was discussing this with some colleagues the other day who clued me in to the following rather sneaky (but perfectly legitimate) method of installing Windows 7 Upgrade as a “fresh install”:

  1. Install Windows 7 as a fresh install and do not enter your key while installing.
  2. From within your installed and running (but not activated) version of Windows 7, go to your Windows 7 disc and install it again!
  3. If your Windows 7 Update disc doesn’t show setup type stuff (because it’s UDF and there’s all sorts of issues), just reboot the machine and install Windows 7 over Windows 7, um, dawg ;)

Cheers!!
Flattr this

How To: Switch a VirtualBox Windows Guest Hard Drive from IDE to SATA Mode

By default, any Hard Drives you create for your Virtual Machines use a virtual IDE controller, which takes more CPU to operate and is slower in operation than a virtual SATA controller. So, it’d be nice to just flick a switch and say Use a virtual SATA controller instead and get instantly higher disk performance, right? Only Windows will BSOD on you if you try that, so you have to do a bit of tweaking first for it to work.

1.) While Vista and Windows 7 come pre-installed with SATA drivers, XP does not – so if your virtual guest OS is XP you’ll need to go get the Intel Matrix Storage Driver from here. Note: Please see the bottom of this article for Windows 7 IDE to SATA instructions.

Update: Some people have reported that Intel have changed the version of the Matrix Manager and it no longer works with VirtualBox (see comments), so instead, why not try this, which is the version of the Intel SATA Matrix Manager driver I used when I did this originally. Launch the installer and slap Next/Next/Finish until it’s installed.

Install Intel Matrix Storage Driver

2.) Next we need to remove our current IDE/ATAPI Drive Controllers from the Device Manager, so right click on My Computer and select Manage from the pop-up menu, then click on Device Manager in the left pane of the Computer Management window and expand the IDE ATA/ATAPI controllers section in the right pane.

Manage My Computer

IDE ATA/ATAPI Controllers

3.) You should see Primary and Secondary IDE Channels, plus some other bits as pieces as shown in the screenshot above – now it’s time to delete them by selecting each one in turn and then pressing the delete key on the keyboard. It might look like a dodgy thing to do, but trust me – I found this trick out while working as a Subsystem Integration bod. If you’ve got one build running on one piece of hardware, and you want to transfer the entire build (via ghost or whatever you want) to another piece of hardware with different controllers, you’ll get a BSOD unless you first delete the drive controllers like this, backup your build, and then ghost it to your new hardware setup.

After you delete each one Windows will say you need to reboot for changes to take effect – don’t. Get rid of as many device controllers as you can, and don’t worry if the Primary IDE controller comes back on its own as soon as you’ve removed it, it’s just there to keep things ticking over until you finally do reboot.

Remove IDE Controller

Don't Reboot Windows Yet

4.) Power off (not suspend) your Virtual Machine then click on the Settings button with the machine you’re working on selected. Then, under the Storage item of the left pane remove your virtual machines hard drive from the IDE Controllers section, add a New Controller and choose SATA Controller, then add your virtual hard drive to the new SATA Controllers section as shown below:

Switch Virtual Hard Drive From IDE to SATA

5.) Boot up your virtual machine and once logged in let it thrash around setting up your new devices. Once it’s done that, it’s gonna be rather keen to reboot. Let it.

Windows is keen to reboot

6.) After you’ve rebooted from the above step, hover your mouse cursor over the drive activity icon and you’ll see it’s running under a SATA controller; lower cpu usage and faster disk throughput is deservedly yours :)

VirtualBox running SATA controller

Note: VirtualBox will set SATA Controllers 0 through 4 to work in IDE compatibility mode by default, so you might want to switch to SATA Controller port 5, or anything higher than 4 to run in true SATA mode, only when I tried this (after first leaving it as port 0 and booting, admittedly) the machine couldn’t find the drive if I switched it to 5. Could be try that before rebooting after IDE -> SATA controller change, but I’m not in the mood to go through all that again.

If you want more info, try: Understanding and Configuring Virtual Box Hard Disks

Cheers!

Credits: Article based on and adapted from Matt Bottrell‘s IDE -> SATA changeover technique found here.

Update for Windows 7 IDE to SATA migration: If you want to switch a drive from a IDE controller to a SATA controller in Windows 7, then you need to perform the following steps:

  1. Make sure that both a SATA and your current controller are being presented to Windows. The SATA controller doesn’t need to have any disks attached to it. Once you have done so boot up Windows.
  2. Remove the IDE controller as described in the above URL [which is Step 2 in this article -r3dux]. Shutdown Windows from inside the guest.
  3. Move the image over to the SATA controller by removing it from your current controller and adding it to the SATA controller
  4. Boot up Windows again and it should boot into Windows, detect the changes and prompt you to restart when done as per the above instructions

Props to NetMusician.org for the Win 7 adaptation!