Many documents describing the use of desktop
virtualization focus typically on having a Linux desktop and running
Windows as an aside. Here we describe a situation where an intrepid
Windows user may wish to make use of the flexibility of Linux to
overcome many of the artificial restrictions imposed on Windows. A
minimal Linux installation with a virtualization package can be
completed in a matter of 30 minutes, whereas trying to recover a badly
corrupted Windows installation can take many hours, particularly if a
complete reinstall is to be done. My experience typically puts this
time at
18 hours. If careful backup management of the Windows virtual machine
(VM) is carried
out, using simple Linux scripts, restoration of a VM can be a snap.
Similarly transfer of VMs to updated machines is much simplified. This
solution is an alternative to commercial and often costly backup
solutions that run inside Windows, such as Norton's Ghost.
If you are worried, Microsoft allows installation on a VM provided it never moves from the hardware machine.
If Windows is to be run as a VM it must be
understood that its performance will be reduced compared to a native
install, in many cases by more than half. Most hardware is virtualized
and is
therefore not available directly to the VM. This is particularly the
case for the video hardware, for which the higher level acceleration
technologies are not yet available. For that reason this solution is
only
useful for applications that make moderate demands on the video.
Currently KVM is under investigation as a possible hypervisor but it continues to have "issues".
The best virtualization solution for this
purpose appears to be VirtualBox.
Some
of
the
more
important
features
provided
are:
-
support for 3D acceleration.
-
runs 32 bit clients without VT extensions.
-
very simple setup for all hardware support
such as network, sound, SATA disks.
-
sharing of host folders with Windows.
-
USB and DVD drive passthrough.
We can use this to
run
Windows
over Ubuntu for desktop use. VirtualBox is extensively documented in an
on-line manual.
Installation
Install the
latest version of Ubuntu, creating
a
non-privileged user and automatic login.
If Ubuntu isn't going to be used
very much for desktop work, many of the applications can be omitted to
keep its footprint small, but keep a web browser and text editor at
least for administrative work. Also install an ssh server to allow
remote
access.
Create a
small 5 or 10 GB
ext4 partition for Ubuntu (mount at /), a small partition for
swap, an xfs partition greater than 40 GB for the VMs (mounted at /vm).
Remember that Windows may install in only 10GB or so, but will quickly
blow out beyond 40GB after updates, users and programs are installed.
If data files are to be kept apart from user files, add a separate
partition or disk drive
for
these
and format it as NTFS (formatting can be done in the Windows VM). It's
best not to use a virtual disk for data files as it can be a major
hassle trying to access individual files if the virtual disk becomes
corrupted.
Do not use
NTFS formatted partitions for VM files. My experience is that the
performance of NTFS is extremely poor for these large files.
From within the non-privileged user account,
install libqt4-network libqt4-opengl libqtcore4
libqtgui4
Download the VirtualBox deb file from the VirtualBox
site
for the latest version of VirtualBox (currently 4.1.0) and for the
installed flavour of Ubuntu (currently Narwhal 11.04). Also obtain the
compatible VirtualBox extension pack which provides USB and
other hardware support. Note that the Ubuntu
repository version virtualbox-ose is the open source version which
currently is still at version 3. Version 4 from the VirtualBox download
site is released under GPLv2, while the extension pack is provided
under the VirtualBox PUEL.
Install VirtualBox from the deb file using gdebi
which will resolve any missing dependencies.
Also install the VirtualBox Extension
Pack either through the GUI or via the command
line using VBoxManage.
$ sudo VBoxManage extpack
install Oracle_VM_VirtualBox_Extension_Pack-4.1.0-73009.vbox-extpack
If the
Extension
Pack is to be updated, be sure to uninstall the old one first. This
can be done from the GUI with File->Preferences and the bottom
entry “Extensions”.
Create a launcher with command VirtualBox and use an
icon
from /usr/share/pixmaps/ where the icon can be found.
Install ssh server (openssh).
Use
visudo
to add the
line:
username
ALL=NOPASSWD: ALL
to
allow privileged commands to be executed without a
password (this is for convenience and can be omitted).
In
Nautilus->Preferences->Media turn off all the options to stop any
media being mounted and to
prevent a pop up box appearing at odd times. Newly added DVD/USB media
must be captured by the running VM.
In System->Preferences->Startup
Applications remove most of the unwanted applications, leaving Network
Manager, PulseAudio, and any others considered desirable.
Display
Most of the operations are done while logged in as the
unprivileged user. The VM can be run by the user and most configuration
can be done without root privileges.
When the VM
has been created, start it up and
install
the vboxguestadditions in safe mode.
-
Enable 2D and 3D
acceleration options should be ticked under the 'Display' options in
the
VirtualBox control panel for the VM.
-
Virtual machine guest
additions should be installed and working and the video display colour
depth set to 32 bits on both the host and guest OS. The host
OS should have latest video drivers installed.
-
If the processor supports the
Intel Virtualization technology (VT) or the AMD-V and Nested Paging,
then these options should be activated in the BIOS. Tick the check
boxes under the
'System' options in the VirtualBox control panel.
DVD
The DVD
drives should be writeable. In the VirtualBox
control panel Settings, with the
CD/DVD pointing to the physical drive, a checkbox allows passthrough
to be enabled. Alternatively this can be enabled from the command line:
$ VBoxManage storageattach <name>
--storagectl <name> - -port <number> - -device
<number>
- -type dvddrive - -medium host:<drive> - -passthrough on
The
various
parameters can be found by VboxManage queries (see manual). A blank
physical DVD must be mounted in order for the burning software to
recognise it.
Sound
Use the IHC AC97 driver and
Pulse Audio.
USB
There have been some
difficulties with this in recent VirtualBox 4 releases: when started
without any USB device inserted, VirtualBox did not subsequently
recognise any USB device. This may be fixed by now, but if not, ensure
that a USB device is plugged in (such as a mouse) when booting.
For recent editions of Ubuntu, simply add the
login users to the vboxusers group created
when VirtualBox was installed:
$ sudo
usermod -G vboxusers -a `whoami`
(log off and on again for this to be
recognised).
Once the VirtualBox Extension Pack has
been
installed
and
vboxguestadditions
installed, USB is enabled by adding a default filter.
USB needs particular attention in Ubuntu for
installs earlier than Lucid.
VM Autostart
Start the VM automatically at login by adding
to the GNOME
login script under System->Preferences->Startup Applications, the
following command:
$ VBoxManage startvm <name>
(where <name> is that given to the VM,
such as WinXPPro). It is useful to add a script that will automatically
shutdown, possibly also backing up. As an example (for mounted external
devices
starting at /dev/sdc):
#$/bin/bash
# Start Windows and wait until it shuts down
VBoxManage startvm WinXPPro
while [ `VBoxManage list runningvms | wc -l` != 0 ]; do
sleep 5s
done
# If an external disk is not present, shutdown the system
# Try a couple of possible mount points for the external disk
DRIVE=/dev/sdc1
sudo umount $DRIVE > /dev/null 2>&1
sudo mount $DRIVE /backup
if [ $? -gt 0 ]; then
DRIVE=/dev/sdd1
sudo umount $DRIVE > /dev/null 2>&1
sudo mount $DRIVE /backup
if [ $? -gt 0 ]; then
sudo shutdown -h now
fi
fi
# Check if enough space is available and copy VM files
if [ `mount | grep /backup | wc -l` != 0]; then
vmsize=`du -s --block-size=1G /vm | awk '{print $1}'`
backupfree=`df -h |grep $DRIVE | awk '{print $4}' |
sed s/.$//`
if [ "$vmsize" -lt "$backupfree" ]; then
sudo cp -a /vm /backup
fi
fi
sudo umount $DRIVE
sudo shutdown -h now
I use a
more extensive script that employs zenity to provide GUI
access to additional options after the Windows VM has powered down. The
shutdown command delayed for up to 10 seconds, giving the opportunity
to abort the shutdown and remain in Ubuntu, or restore or backup the
Windows VM.
Logging
In scripts, use logger to log to a file:
logger -f /var/log/virtualbox.log "..."
adding the
desired text message to the end of the
command.
In /etc/logrotate.d/virtualbox,
add:
/var/log/virtualbox.log
{
monthly
rotate
4
notifempty
missingok
}
Convert VMDK Images to VDI Images
Convert to a raw image using qemu, then use:
$ VBoxManage
convertfromraw image.raw image.vdi
It may be possible to convert from vdi to
other
formats using the clonehd
option of VBoxManage. Refer
to the VBoxManage
manual for more details.
Transfer
of VMs between Hosts
This can
be
done in a number of ways, the first is by far the simplest.
1 Copy
the VM
Simply
copy
the VM files across to the desired location on the new host and in
VirtualBox Manager choose Machine->Add. Navigate to the location
of the VM files and select the vbox file. If there are additional
disk drives these need to be added separately.
When copying
the VM, it will be necessary to give it a new MAC
address as it will clash with the original VM particularly when on the
same subnet. The following command will generate a new random MAC
address for the first NIC.
$ VBoxManage modifyvm
<name> --macaddress1 auto
2 Convert
to
Virtual
Appliance
Using the
export and import utility in the VirtualBox GUI to convert to a
virtual appliance, then import into the new machine. This failed on
the one and only attempt I made.
3 Clone
the vdi file
Use the VboxManage
utility to clone the vdi file:
-
Shutdown
the
Virtual
Machine
-
Release the .vdi file – File > Virtual
Media Manager > Select the virtual machine disk to be copied >
Click “Release”
-
In a terminal (use the full location paths
for .vdi locations)
$ VBoxManage clonevdi Original.vdi
NewCopy.vdi
-
Copy the new .vdi file to the new machine
-
Create a new VirtualMachine in VirtualBox
and use the copied .vdi as the HardDisk
Usage
To call
up a
menu in a full screen guest, use Host+Home
Remote
Desktop
VirtualBox
includes a remote desktop feature allowing a remote
administrator (or even a user) to connect to a running VM. This uses a
compatible adaptation of the remote desktop protocol (rdp) used in
Microsoft Windows products. It can be accessed from a Windows machine
using the remote desktop tool, and from Linux using rdesktop.
This is
enabled as described above in the VirtualBox GUI, or by the command:
$ VBoxManage modifyvm <name> --vrde on
The
VirtualBox extensions must be installed for this to work. Connections
are made by default on port 3389 which must be opened in any
intervening firewalls.
|