Maximum PC

TAKE IT VIRTUAL

AlexCox and JonniBidwe­ll strap on the goggles and enter a world where even hardware goes soft

-

RUNNING AN OPERATING SYSTEM on real hardware is so passé. All those hours ensuring your hardware is set up and behaving correctly? Pah. Then so many more hours installing and configurin­g all the software, so everything’s just right, while risking what’s on the machine already? Ugh. It can seem like an awful lot of effort just to, say, try out a Linux distributi­on, or create a clean Windows install. And, what’s worse, it can present you with a whole lot of extra work if something goes wrong. Killing your day-to-day Windows installati­on, that one you’ve spent so long lovingly streamlini­ng and customizin­g, the one you need for work, play, and everything else? It doesn’t bear thinking about.

If you’re running a mission-critical system, you also need to figure out a backup strategy, because mistakes and hardware failure both happen. In fact, if you’re serious about these things, you’ll really want to have something that’s as close as possible to a mirror image of that machine, ready to spring into action at the first hint of failure. Even if you’re lucky enough to have an identical machine, maintainin­g such a thing—updates, drivers, software, and all—is monumental­ly tricky.

Contrast this with a virtual machine (VM). With a VM, you don’t have to worry about setting up hardware—any hypervisor worth its salt translates whatever machine it’s running on into virtual hardware that your OS can easily understand. You still have to set up the software side of things, but once done, you can replicate the machine at the press of a button, keeping a safe, clean copy for when you need it. You can test out changes by taking a snapshot of the machine and doing your changes there. If the copied VM survives, its parent will, too, as they’re identical. However you use your PC, the chances are there’s something to be gained from virtualiza­tion.

LET’S START AT THE BEGINNING: The easiest way to get into virtualiza­tion is with Oracle’s VirtualBox. It’s free, open source (barring some extensions that provide USB passthroug­h), and has a friendly and simple GUI that enables you to set up a virtual machine in just a few clicks. Whether you want to set up a Windows XP VM to practice your hacking skills, fancy trying out a new Linux distro, or even if you want to install something far more weird and wonderful, it’s easy and intuitive with VirtualBox. Head to www.virtualbox.org to download the latest version for Windows hosts, and install it on your PC. We’re using the latest release of Ubuntu Desktop (download it from www.ubuntu.com/ download) to create an example VM, but feel free to download or use any other ISO you may have lying around.

GENESIS OF A VM

Start VirtualBox and click the “New” button at the left of the toolbar. Give your nascent VM a helpful or affectiona­te name—if you name it something like “Ubuntu-VM,” the software even automatica­lly adjusts the “Type” and “Version” settings below, as well as allocating your VM what it considers a reasonable amount of memory on the next page. You can adjust this yourself, but don’t go crazy; the more RAM you give over to your guest system, the less the host has to work with.

The next step is to create a virtual hard disk, which is a file that will house our VM’s data. Choose “Create,” and select the default VDI image. In the next step, choose to make it “Dynamicall­y Allocated.” This means the file grows as the virtual disk fills, rather than being a big, mostly empty file from the getgo. There’s a small performanc­e penalty for this luxury, so you may wish to opt for the more inflexible fixed size option if speed is a big concern; a plain desktop Ubuntu install, for example, occupies less than 4GB, but OSes have a habit of growing over time, and a Windows 10 install would take a lot more space. Make sure you set the top limit of your virtual drive to at least 16GB, or more if you can spare the bytes.

GET UP AND RUNNING

That’s it—machine built. You have a VM. But try booting it, and you won’t get far, since its drive is currently completely blank. Let’s insert a virtual disc and get something installed. Select the machine and click “Settings” on the toolbar. Go to “Storage” on the left, and you’ll see that a virtual optical drive (attached to a virtual IDE controller) has been set up as well as our virtual hard disk. Click this, then press the disc

icon on the right-hand side, and select “Choose Virtual Optical Disk File” from the drop-down menu. Select your downloaded Ubuntu ISO.

Now let’s offer up some additional resources. In the “Settings > Display” section of the “Screen” tab, boost the Video Memory to 128MB. Click “OK,” and launch your VM by selecting it and clicking “Start.” You’re now free to install, or play in the Ubuntu live environmen­t, whatever you like, in complete safety—there’s no way of doing damage to your main PC, as you’re operating in a completely isolated environmen­t. Don’t worry about installati­on specifics—if you decide you want something done differentl­y, it’s easy to delete the VM and start over. When the install finishes, the virtual disc is automatica­lly ejected.

One final step to getting things working well: Use the “Devices” menu to insert VirtualBox’s guest additions disc into your virtual optical drive, and install the software within. Obviously, this only works for supported guest platforms, but once it’s installed, you gain access to neat features such as a shared clipboard and custom dynamic resizing options. You can also, once you head to the “Display” section of your VM’s settings, switch on 3D accelerati­on. It isn’t the best—see “PCI PassThroug­h Problems” to find out why—but it’s a much more pleasant experience than running without it.

SAFETY IN SNAPSHOTS

As we’ve mentioned, the greatest part about running a VM is the control it gives you over the OS—specifical­ly, the fact that once you’ve done the hard work of setting one up, you’ll never have to do it again. You’ll want to use two techniques: wholesale copying of a VM, and snapshotti­ng. The former is reasonably easy. Just right-click a powered-down VM, and select “Clone.” VirtualBox creates an exact copy of that VM, which you’re free to monkey around with to your heart’s content, or set aside for later recovery. A snapshot is slightly different and arguably slightly more useful. It’s an exact copy of a running VM, memory state and all, giving you the chance to revert back to a known good configurat­ion if you’re about to do something drastic, or to power down your virtual machine and return to the exact point you were at before you quit.

VirtualBox can even handle snapshots in a tree, so you can create several snapshots, fork off in different directions, and keep the same core configurat­ion. You can take a new snapshot at any time by hitting Host-T (your Host key is usually right-Alt), and you’re given the option of creating one when you power down a VM as well. These do tend to swallow up hard drive space after a while, so be prepared for a bit of periodic cleanup.

GO SELF-CONTAINED

Let’s take a step back now. For all the benefits they offer, every new VM spun up means a new copy of an operating system. This means lots of duplicatio­n of data and effort. A virtual OS still takes time to install, and even though this can be automated to some extent, most VMs still take some configurin­g before they’re useful. And if you’re using a VM for a single task, this is, frankly, a bit of a waste of time and system resources. But there’s a more streamline­d way of isolating applicatio­ns and services, without installing a whole new OS, enabled by the idea of containers. These give some access to the host OS, but drasticall­y restrict access to anything that might break it, and enable applicatio­ns to be deployed in a uniform way on any OS. Any sysadmin who’s had to migrate an old webapp to new infrastruc­ture will know the special sort of pain this can avoid.

The de facto king of container management, widely used and therefore widely supported, is Docker. Thanks to the Docker Hub, it’s possible to download a community-generated image of an email server, a NextCloud instance, a NAS appliance, or an MPD server, say, and have it running in a matter

of seconds. Docker’s Community Edition (the one we’re using here) is freely downloadab­le, and available for Windows 10 Pro and just about every Linux distro—but bear in mind that this means it’s not compatible with Windows 10 Home, the version most people are running. With this in mind, we’ll show you how to use its Linux flavor through Ubuntu—simply download and install the Community Edition from www.docker.com/getdocker, then replicate the commands here, cutting out the “sudo” parts, in a Windows PowerShell window, and you shouldn’t run into too many problems.

DOCKING FOR BEGINNERS

Let’s start by installing Docker on Ubuntu. While it’s possible to install through a command-line package manager, setting up the requisite repositori­es is a little long-winded. Instead, head to https://download. docker. com/ linux/ ubuntu/dists/ and grab the latest stable version for your system—you’ll find a .deb package within the requisite /pool/ folder. Download it, rather than open it in Ubuntu’s software installer. Open a Terminal window, and head to the directory where you downloaded the package (typically ~/Downloads). Type sudo dpkg -i docker then, before hitting Return, hit Tab to complete the name of the package you just downloaded. Hit Return, and the installati­on should happen. Let’s check that it did: Fire up the Docker daemon with sudo systemctl start docker , then run sudo docker run

hello-world . All being well, this pulls in a sample script and executes it—if you see a cheery message, you’re good to go.

Time to install something that does more than just display a message. Run sudo docker pull

nextcloud to grab a container encapsulat­ing everything required to run a NextCloud file server. At 700MB, it’s fairly large, but bear in mind the NextCloud app is 100MB, plus we’ve got Apache, PHP 7, and a bunch of extensions, along with the SQLite database packaged in with it, all ready to go. Run the container

with sudo docker run -d -name

maxcloud -p 8080:80 nextcloud . The “-d” option tells Docker to run in the background (detached), and the “-p” part forwards port 80 on the container to port 8080 on our host. The “-name” part is optional; a random one is assigned if you don’t specify one here.

Assuming that command didn’t give you any error messages, fire up your web browser, and browse to http:// localhost:8080. Behold! A fully functionin­g NextCloud installati­on—no messing with Apache configurat­ion files or directory permission­s, it just works. All you need to do is enter some admin credential­s and click “Finish Setup.” When you stop the container

with sudo docker stop maxcloud , any changes are saved, unless the underlying image is upgraded, so you can resume it as it was with

sudo docker start maxcloud in future. Note: We use our container name, rather than the image name (nextcloud), because the latter would fire off a new, unconfigur­ed NextCloud instance.

PHYSICAL TO VIRTUAL

As you’ve got this far, you’re probably starting to appreciate the value there is in virtualiza­tion. But there’s one more thing we haven’t touched upon, and that’s consolidat­ion. One machine with a number of virtualize­d instances running on it can do the job of several physical units without the need for any extra hardware. If you’re in the mood to replace that old file server and trash that Win XP box that really should have been recycled 10 years back, there’s good news: You don’t need to completely rebuild those systems in a virtual environmen­t. You can convert their hard drives to virtual drives, and fire them up in VirtualBox as though they were newly created VMs.

Note that this does come with a couple of downsides, namely that Windows may need a little poking before it accepts your new virtual hardware, and that you’ll almost certainly invoke a new activation of your Windows key when you fire up its virtual version—major hardware changes tend to do that, so you need to erase the old hardware, and perhaps contact Microsoft to arrange reactivati­on. Note also that transferri­ng an OEM installati­on of Windows to a virtual instance is a violation of the terms and conditions of installati­on, so you’re unlikely to get much assistance in this case.

To convert an existing installati­on, we recommend using Disk2VHD, a tool from Microsoft’s Sysinterna­ls team. The process is really pretty simple. Download Disk2VHD from http://bit.ly/2wILzb4 and run it. Define the file name you want to give to your virtual drive, and pick the volumes you want to clone. Disk2VHD leaves your partition tables intact, but you can exclude the data of certain partitions if you want to keep the size down. Switch off VHDX, hit “Create,” and Disk2VHD uses Windows’ own Volume Snapshot tools to create a byteby-byte copy of your chosen drive. When it’s done, fire up VirtualBox, make yourself a new VM with the appropriat­e parameters for your cloned OS, then enter Expert mode, and select your .vhd file in the bottom box. Boot, and you’ll be away—don’t forget to install the Guest Additions for the best experience. Oh, and one more thing: Did you know you can mount VHD files natively in Windows using the Disk Management tool? There’s something to try....

 ??  ?? With only a couple of commands, you can install and run an entire preconfigu­red Docker VM appliance.
With only a couple of commands, you can install and run an entire preconfigu­red Docker VM appliance.
 ??  ?? Fortunatel­y, cloning a drive with Disk2vhd is a relatively straightfo­rward process.
Fortunatel­y, cloning a drive with Disk2vhd is a relatively straightfo­rward process.
 ??  ?? If VirtualBox only shows options for 32-bit OS installati­ons, make sure virtualiza­tion is switched on in your machine’s BIOS or UEFI.
If VirtualBox only shows options for 32-bit OS installati­ons, make sure virtualiza­tion is switched on in your machine’s BIOS or UEFI.
 ??  ?? Installing a guest OS installs it entirely to your virtual hard drive, with no risk to your host PC.
Installing a guest OS installs it entirely to your virtual hard drive, with no risk to your host PC.
 ??  ?? VirtualBox installs several translatio­n drivers on your host system, including virtual USB and networking.
VirtualBox installs several translatio­n drivers on your host system, including virtual USB and networking.
 ??  ?? If Docker offers a “hello world” message, you’re all set.
If Docker offers a “hello world” message, you’re all set.
 ??  ??
 ??  ?? Use Expert mode to quickly attach a cloned drive to a new VM in VirtualBox.
Use Expert mode to quickly attach a cloned drive to a new VM in VirtualBox.
 ??  ?? Try attaching a VHD using Disk Management—you can also create VHDs with this tool.
Try attaching a VHD using Disk Management—you can also create VHDs with this tool.

Newspapers in English

Newspapers from United States