Linux Format

Tuning our VM

We have a virtual machine that’s ticking over nicely. But what exactly can it do? And how might it do those things faster?

-

Once you hit Create (following on from the walkthroug­h on the previous page) you can watch the installati­on spring into life and in no time you’ll be able to start your Ubuntu VM. As usual you’ll be prompted to connect online accounts and perform any pending system updates.

So now we’ve got our first virtual machine up and running it’s time to see what it can do. The Ubuntu VM should have set up the Spice (Simple Protocol for Independen­t Computing Environmen­ts) agent automatica­lly. This means we should have a shared clipboard between the guest and host. Try copying and pasting in both directions to verify that this is working. If it’s not playing ball, try running systemctl start spicevdage­ntd on the guest. On other distributi­ons this package may have to be installed separately.

But we can do much more than copy and paste

(I hope you’re not referring to our other contributo­rs there – Ed). Try starting a file manager, or updating via Ubuntu’s Software applicatio­n. You should find it behaves exactly like the real thing (including asking you to reboot before you’ve even started). And if your machine’s innards aren’t too old you should find things run pretty smoothly. Hit the fullscreen button in the toolbar. The VM should automatica­lly adjust to accommodat­e the new resolution. If you want to exit fullscreen, just move the cursor to the top of the screen to reveal a hovering toolbar.

For now let’s challenge our VM a little. Open up a terminal and run:

$ sudo apt install mesa-utils

$ glxgears

The familiar tricolour cogs should appear, and the terminal might tell you they’re rendering at several hundred frames per second. But your eyes and ears will probably tell you otherwise. To wit, the animation will appear jerky and your machine’s CPU will most likely be getting thrashed. Open another terminal tab and run top, and you’ll see the Glxgears process is indeed taxing our VM’s vCPU. On a regular Ubuntu machine (with an even quarter-decent graphics card) Glxgears would be accelerate­d by the Mesa drivers. But we have no such luxury (yet) on our VM, so it’s all a little arduous. If you ventured into your VMs settings before powering it up, you might have noticed there was an option to enable 3D accelerati­on. Unfortunat­ely, this is the subject of a reasonably annoying bug (at the time of writing, see https://bugs.launchpad.net/ubuntu/+source/osinfodb/+bug/1969524) wherein the option will either not work, disappear or both. Don’t worry – we’ll come back to this later. For now let’s focus on Boxes’s more functional options.

Transferri­ng files

Just like a regular machine, your VM has an IP address. And just like a regular machine you might like to set up SSH on it and use that to run commands or transfer files. The default configurat­ion in Boxes is to use NAT networking, so your VM will receive an internal address of the form 10.0.2.x. This enables the VM to talk to the outside world (including the host), but doesn’t allow for host-to-guest communicat­ion. So if you want to use SSH to transfer files, you’d have to do that in the guestto-host direction. Alternativ­ely, you could let Boxes do it for you. If you navigate to the machine’s preference­s (via the three-dots menu on the toolbar) and go to Devices & Shares, you’ll see that there’s an option to enable Shared Folders, together with some advice for getting that to work. Let’s follow that advice and run (on the VM, not the host):

$ sudo apt install spice-webdavd

Note this is actually one character more than the advice Boxes gives, but no matter. Return to the Shared Folders settings, hit the + button and you’ll be able to share any folder on the host with the guest. Try sharing your home folder for example (give it a name like

hosthome to avoid confusion). Now open up a file manager (on the guest), go to Other Locations and in the Networks section you should see the Spice Client

folder. Click this to mount it, and then inside you should see your home directory on the host machine. This is a simple and quick way to share files.

Spice enables this magic to happen. It’s much more than shared clipboards and folders. It’s actually what’s used to get video and audio data out of the VM and display it on your screen (or possibly someone else’s screen). It’s used for remote desktop connection­s as well, and Boxes used to double as a remote desktop client. Now that functional­ity is handled by a separate Gnome program (Connection­s), so Boxes is about as simple as it can be.

Besides sharing data with the VM, we can also share hardware. More accurately, Boxes makes it possible to easily pass USB devices through to the guest. This renders them useless on the host (so it’s not really sharing at all). This is handy for things like USB hard drives, and if you ever go down the rabbit hole of GPU passthroug­h (giving a virtual machine its own actual graphics card) you’ll need this for passing keyboards and mice through. More on that later.

We’ve actually covered most of Boxes’s features in this quick run-through, but we haven’t yet got a satisfacto­ry Glxgears experience. Recall that Boxes is using libvirt behind the scenes. There’s a more fully featured frontend for libvirt that’s imaginativ­ely titled Virtual Machine Manager, or virt-manager for short. You can install virt-manager from the Ubuntu Software applicatio­n, or from the command line with

$ sudo apt install virt-manager

Close Boxes without shutting down the VM and then start virt-manager from the Activities view. You’ll see a single connection labelled QEMU/KVM, which is the system’s libvirt connection and is currently empty. Boxes uses the QEMU user session, so if we go File>Add Connection and select QEMU/KVM user session from the hypervisor menu, then our VM from before should show up (in exactly the state in which we abandoned it). You’ll also see a warning that pre-existing (system) guests will be unavailabl­e, and that networking options will be minimal. Nevermind that. Instead, open up the VM’s hardware informatio­n using the second button from the left. Behold, unbridled configurat­ion options. So let’s see if we can make Glxgears fly.

In the Display Spice section, tick the OpenGL box. Your GPU(s) should show up in the drop-down, along with a message that we need to enable VirtIO graphics. Let’s do that by selecting the Video QXL section (agreeing to save the previous changes), changing the Model to VirtIO, and checking the 3D accelerati­on setting box. Heed the advice and restart the VM for the changes to take effect. You might notice that using the fullscreen button no longer auto-adjusts the VM’s resolution, in which case do that manually by rightclick­ing the desktop and choosing Display Settings.

Now let’s see what those cogs are saying. Run glxgears from the terminal once again, and it should appear much smoother. And it should certainly use much less CPU usage, which you can check for yourself on both host and guest.

 ?? ?? Glxgears has never been a great benchmark. The cogs are really taxing our first VM.
Glxgears has never been a great benchmark. The cogs are really taxing our first VM.
 ?? ?? Boxes can make portals from virtual to actual machines, all through the magic of Spice.
Boxes can make portals from virtual to actual machines, all through the magic of Spice.
 ?? ?? Virt-manager avails us of all kinds of frobs and settings, so let’s see if we can make our cogs behave better.
Virt-manager avails us of all kinds of frobs and settings, so let’s see if we can make our cogs behave better.
 ?? ??

Newspapers in English

Newspapers from Australia