Linux Format

VirtualBox: Virtualisa­tion

Nick Peers reveals how virtualisa­tion software can tap into your PC’s unused processing power to help you run multiple operating systems.

- Nick Peers has embraced virtualisa­tion for the best part of ten years after discoverin­g how experiment­ing in a virtual environmen­t was better for his PC’s health.

Today’s multi-core PCs are built to run multiple tasks simultaneo­usly, and what better way to tap into all that power than through virtualisa­tion? Virtualisa­tion, and in particular hardware virtualisa­tion, is the process of splitting a single physical PC (known as the ‘host’) into multiple virtual PCs (referred to as ‘guests'), each capable of working and acting independen­tly of the other.

Virtualisa­tion software allows the host to carve up its memory, processor, storage and other hardware resources in order to share individual parcels with one or more guests. If your PC is powerful enough, you can run multiple virtual machines in parallel, enabling you to effectivel­y split your computer in two to perform different tasks without having to tie up multiple PCs.

Virtualisa­tion isn’t simply a means of dividing up computing power, though. It also enables you to easily run alternativ­e operating systems in a safe, sandboxed environmen­t – your guest PC can be isolated [in theory – Ed] from your host, making it safe to experiment with new software or simply try out a different flavour of Linux, for example. It can also be used for compatibil­ity purposes – you may have switched from Windows, for instance, but want access to a virtual Windows machine to run old programs without having to use a dual-boot setup.

It goes without saying that the faster and more powerful your PC, the better equipped it is to run one or more virtual machines. That said, if performanc­e isn’t the be-all and endall of your virtualisa­tion experiment­s, then it’s perfectly possible to run a single virtual machine in even relatively low‑powered environmen­ts.

Choose VirtualBox

There are many virtualisa­tion solutions available for Linux, but what better way to meet your needs (or even just dip your toes in the water) than with the open-source solution,

VirtualBox enables you to set up, manage and run multiple guest machines from the comfort of your desktop. VirtualBox? VirtualBox may be free, but it’s still a powerful option that offers both a friendly graphical front-end for creating, launching and managing your virtual machines, plus a raft of command-line tools for those who need them.

An older version of VirtualBox is available through the UbuntuSoft­wareCenter, but for the purposes of this tutorial we’re going to focus on the newer version 5.x branch, which you can obtain from www.virtualbox.org/wiki/Linux_ Downloads. You’ll find that a variety of different builds exist, each one geared towards a specific distro (or distro version). Both 32-bit (i386) and 64-bit (AMD64) links are provided to downloadab­le and clickable Deb files, or you can follow the instructio­ns provided to add the appropriat­e VirtualBox repository to your sources list.

Once it’s installed, the quickest way to get started is to launch VirtualBox through the Dash. This opens the Oracle VMVirtualB­oxManager, which is where all your virtual machines can be listed (and organised into groups). It’s also where you create new VMs from scratch, but before you begin, select File > Preference­s to change the default machine folder if you want to store your virtual machine settings somewhere other than your own home folder. This isn’t a critical step, but as each guest may consume gigabytes of space for its own needs, you may prefer to choose a dedicated drive (or one with lots of free space). If you’re looking to purchase a drive for your virtual machines, then consider an SSD to add zip to your VM’s performanc­e.

Create your first VM

With your virtual machine folder set, click ‘OK’ and then click the ‘New’ button to create your first virtual machine. The Create Virtual Machine Wizard works in either of two ways, Guided or Expert, with the latter putting the three configurat­ion steps in a single window. Start by selecting your chosen OS and version from the two drop-down menus – VirtualBox supports all the major OSes, including BSD, Solaris and IBM OS/2 in addition to Windows, OS X and – of course – Linux. The Version drop-down changes depending on your initial selection; all the major distros as well as Linux kernel versions from 2.2 onwards are available.

It’s important to choose the right OS and version because this will ensure that other machine settings are set so they’re compatible. You’ll see this immediatel­y when the ‘Memory size’ slider changes to match the OS. This will be set to a comfortabl­e minimum setting, so feel free to alter it using the slider – it’s colour-coded green, amber and red to help you set the memory to a level that’s comfortabl­e for your host PC. The figure you set is actual host RAM, not virtual memory, so

be sure to leave enough for your PC’s other tasks (including the running of VirtualBox itself).

The final option is to create a virtual hard disk. This basically starts out as a single file that represents your guest’s hard drive, and will splinter off only when you start working with snapshots ( seeonthepa­ge). In most cases, leave ‘Create a virtual hard disk now’ selected and click ‘Create’, at which point you’ll need to set its size, location (click the little folder button to choose a different location from the default), file type and how the virtual file will behave. For these latter options, the defaults of ‘VDI’ and ‘Dynamicall­y allocated’ usually work best; the latter ensures that the physical file containing your virtual hard drive’s contents starts small and grows only as it’s filled with data. Click ‘Create’ and your virtual machine is ready and waiting for action.

Virtual hardware tweaking

It’s tempting to dive straight in and start using your new virtual machine, but while the basic hardware settings are in place, you should take the time to ensure it has all the power and resources it needs to function as you want it to. You can always tweak these settings later, but the best time to set it up is before you begin.

Select your new virtual machine and click the ‘Settings’ button. Switch to the System tab, where you’ll find three tabs: Motherboar­d, Processor and Accelerati­on. You can tweak your VM’s base memory from the Motherboar­d tab, as well as switch chipset, although unless you need PCI Express support the default PIIX3 should be fine in most cases. The Pointing Device is set to ‘USB Tablet’ by default, but there’s a ‘PS/2 Mouse’ option for legacy purposes.

The Extended Features section should already be set up according to the OS you’ve chosen, but if you’d like your virtual machine to have a UEFI rather than a BIOS, tick ‘Enable EFI’ here. Note, however, that this works only for Linux and OS X; Windows guests aren’t (yet) supported.

If you have a multi-core CPU installed, switch to the Processor tab to allocate more than a single core to your VM, making sure you don’t attempt to allocate more cores than your processor physically possesses (Hyperthrea­ding should be discounted). You may also need to tick ‘Enable PAE/NX’ if your virtual machine needs access to more than 4GB of RAM on a host PC with an older 32-bit processor.

The Accelerati­on tab allows you to tap into the processor’s virtualisa­tion features if they exist – see the tip for details.

Other key settings

Switch to the Display tab to configure your virtual graphics card. Start by allocating as much memory as you think you’ll need, and also tick the ‘Enable 3D Accelerati­on’ box to improve performanc­e across all your VMs. If you’re running a Windows virtual machine, then tick the 2D option too. Switch to the Remote Display tab if you’d like to access your VM remotely. The Video Capture tab makes it possible to record your VM screen as a video should you want to do so – the former feature requires the VirtualBox Extension Pack, which we’ll talk about shortly.

The Storage tab is where you can configure the internal storage of your virtual PC – by default your virtual hard drive is added to the SATA controller, from where you can add more drives. You’ll also see that a single DVD drive is also added to the IDE controller. Select it and click the little disc button next to the Optical Drive drop-down to select a physical drive or mount an ISO disk image as a virtual drive instead. Tick the ‘Passthroug­h’ option if you’d like to be able to write discs, play audio CDs or watch encrypted DVDs.

The options in the Audio and Serial Ports tabs are largely self-explanator­y, but if you plan to make your guest VM visible

over your local network for the purposes of sharing files and other resources, then select ‘Network’ and change the NAT setting to ‘Bridged Adapter’. Other configurat­ions are also available from here – ‘NAT Network’, eg, allows you to create a network of VMs that can see and interact with each other while remaining invisible to the host. NAT networks are configured independen­tly via VirtualBox’s File > Preference­s menu (look under Network).

Working with USB peripheral­s

The USB tab is where you can capture specific USB devices for use in your VM. However, before you can use this feature, you need to make sure you add your username to the vboxusers group on your host PC using the following command in the Terminal: sudo usermod -a -G vboxusers <username>

Once this is done, your USB devices will become visible to your VirtualBox guests. Note that VirtualBox supports only the older USB 1.1 implementa­tion by default, but you can install the VirtualBox Extension Pack to add support for USB 2.0 and USB 3.0 among other extras (including PCI and host webcam passthroug­h). Download this Extension Pack from www.virtualbox.org, but note the licence restrictio­ns: unlike VirtualBox, it’s not open source and is free for ‘personal evaluation’ only.

You can easily connect to USB devices within your guest on the fly – click the USB button on the guest machine window and select your target peripheral from the list – but adding specific USB Device Filters here makes it possible to automatica­lly capture specific devices when the VM boots. One example of where this could be handy is if you set up a VM as a headless TV server – it would allow the VM to take control of your USB TV stick the moment it starts. We cover the Shared Folders tab in the ‘Share data’ box below, while the User Interface tab allows you to specify which menu options are made available to this guest.

Your first boot

With your VM’s hardware set up, you’re ready to go. You need to point your virtual CD/DVD drive towards an ISO file (or physical disc) containing the installer of the OS you wish to emulate, then start the VM and follow the prompts to get started. Once running, your virtual machine acts in exactly the same way your main PC does – click inside the main window and your mouse and keyboard may be ‘captured’ by the VM, allowing you to work inside it. To release these back to your host PC, press the right-hand Ctrl key.

Once you’ve installed your target OS in the guest machine you’ll need to install the Guest Additions – a series of drivers and applicatio­ns that enhance the VM’s performanc­e. Key additions include a better video driver supporting a wider range of resolution­s and hardware accelerati­on, mouse pointer integratio­n, which allows you to more easily move the mouse between host and VM without it being captured, and support for shared folders.

Installing these for Windows guests is as simple as selecting Devices > Insert Guest Additions CD image… After a short pause, the setup wizard should appear. Things are a bit more complicate­d for Linux guests – see chapter 4.2.2 under VirtualBox’s Help > Contents menu for distro-by-distro guides. Once you’ve followed the prerequisi­tes, open the file manager and browse to the root of the Guest Additions CD, then right-click inside the window and choose ‘Open in Terminal’. Once the Terminal window opens, the following command should see the additions installed: sudo sh ./VBoxLinuxA­dditions.run

After rebooting you should be able to resize your VM window to the desired resolution simply by clicking and

dragging on it – have the Displays panel open in your guest when you’re doing this to verify the dimensions as you resize.

Take a snapshot

Your VM is now set up and ready for action. It should work in exactly the same way as any physical machine, but it has one crucial advantage: snapshots. Snapshots let you take oneclick backups of your guest at a specific point in time. You can then proceed secure in the knowledge you can roll back to the snapshot and undo all the changes you’ve made since.

You can create snapshots while your machine is powered off, or during use – just select Machine > Take Snapshot to do so. Give your snapshot an identifiab­le name, and also add a descriptio­n if you wish, then click ‘OK’.

When you take a snapshot, VirtualBox starts recording changes to the drive in a different file. If you delete a snapshot, those changes are merged back into the main file, while if you roll back to an earlier snapshot (or the base image), the snapshot’s changes are lost unless you create an additional snapshot when prompted. VMs support multiple snapshots, and you can even move between them, allowing you to create multiple setups from within a single guest.

Terminal use

VirtualBox’s user interface may be a convenient way to get started with virtualisa­tion, but once you’re up and running you’ll be pleased to learn there are a number of commandlin­e tools you can employ if that works better for you. You can even bypass the graphical VirtualBox Manager entirely if you’re willing to learn the rather lengthy list of subcommand­s for the VBoxManage tool, such as createvm and startvm , but even if you’re happy with the point-and-click approach, there are a number of tools you should take a closer look at.

The first is VBoxSDL – if you’d like to launch your VM in a ‘pure’, distractio­n-free environmen­t (so none of the controls offered by the default VM window), this is the tool for you. Its usage is pretty straightfo­rward: VBoxSDL --startvm <vmname>

Replace <vmname> with the name of your VM (or its UUID if you prefer). Once it’s running, you’ll not only have access to the menu commands offered by the main VirtualBox window, but some handy shortcuts you can employ while pressing the host key (the right Ctrl key by default): f toggles full-screen view on and off, while n takes a snapshot. Press h to press the ACPI power button, p to pause and resume, q to power off or r to reset. Finally, press Del in conjunctio­n with the host key and you’ll send a Ctrl+Alt+Del to the guest machine. Alternativ­ely, shut down your VM using the VBoxManage tool – just type the following command to initiate the ACPI power button, eg: VBoxManage controlvm "VM name" acpipowerb­utton

Another handy command-line tool is VBoxHeadle­ss, which enables you to run your virtual machine headless. To do this – and allow yourself to access it remotely from another computer ( checkoutou­rHeadlesss­etupbox).

Whether you plan to use VirtualBox from the command line or its GUI, you’ll find it’s packed with powerful and useful features that will convert you to the possibilit­ies and power of virtualisa­tion. You’ll wonder how you ever coped before!

 ??  ?? The ability to take snapshots of your virtual machines makes them particular­ly suitable as test beds.
The ability to take snapshots of your virtual machines makes them particular­ly suitable as test beds.
 ??  ??
 ??  ??
 ??  ?? Remove all the desktop parapherna­lia and run your guest in a lean, distractio­n-free window using VBoxSDL.
Remove all the desktop parapherna­lia and run your guest in a lean, distractio­n-free window using VBoxSDL.

Newspapers in English

Newspapers from Australia