Run virtual machines in Gnome Boxes
Boxed
In the past, using virtual machines required expensive programs such as VMware or open source add-ons such as VirtualBox. Gnome Boxes brings a convenient virtualization option to the Linux desktop.
If you want to set up a virtual machine (VM) with a graphical user interface on Linux, you might be inclined to go with VirtualBox or VMware's commercial offerings. These applications, which have been established for years, offer many functions. However, due to their full version's proprietary licenses, they are not found in the package sources of popular Linux distributions.
With VirtualBox, you would have to install the Extension Pack alongside the program to use the application's full functionality. In addition, it is important to pay attention to licences. VirtualBox's source code is released under the GPL v2.0, but you can only use the proprietary add-on free of charge [1] for personal use or testing purposes.
Boxes Out of the Box
Because Gnome Boxes, a front-end tool for Kernel-based Virtual Machine (KVM), is created within the framework of the Gnome Desktop Environment [2], it does not require the installation of any additional software (see the "SPICE Mix" box). With KVM directly integrated into the Linux kernel, Boxes does not have to worry about virtualization. The software simply provides the VM with the environment, using existing libraries and applications such as libvirt and Qemu [3].
SPICE Mix
Boxes uses the SPICE protocol [4] for communicating between the desktop and the VM. Much like VNC, SPICE transfers the screen content, plus mouse and keyboard input. However, it is not limited to the image; it also transmits audio and couples USB devices with the VM.
Distributions that deliver a complete Gnome desktop include Gnome Boxes. Examples include Arch Linux, which automatically packs the application onto the hard disk along with the gnome metapackage. Other distributions, such as Ubuntu, do not include Boxes during the system's initial installation, but do include the application in the software sources (the gnome-boxes package).
When first launched, Boxes boots up in a very tidy window. Pressing New in the upper left corner launches the setup of an initial VM. A wizard pops up to help you (Figure 1). Thanks to the Source Selection option, you don't even have to load an image of the distribution you want to install. The program directly downloads variants of the most popular distributions. If the desired variant is missing, the search function in the window titlebar quickly finds a matching entry.
However, the database is not up to date. As of November 2018, Boxes did not know anything about Ubuntu 18.10, which was released earlier in October. In such a case, you need to manually download the system image as an ISO file off the web and then enter it as a boot image via the Select a file option. Following the selection, Boxes then jumps directly to the next step.
You can customize the VM to your needs by setting the RAM size for the VM and the virtual disk's size. A click on Create then starts the VM installation; the installation wizard in your chosen distribution will guide you. (See the "Tip" box for information on the directory path.)
Tip
Gnome Boxes stores the VMs under ~/.local/share/gnome-boxes/
. Boxes does not offer an option to change this path. If you prefer a different location, the directory can still be changed. To do this, stop all VMs, and then move the directory. Then create a symbolic link between the old and new storage locations (Listing 1).
Listing 1
Linking Storage Locations
$ mv ~/.local/share/gnome-boxes /<I>Path<I>/<I>Folder<I>/ $ ln -s /<I>Path<I>/<I>Folder<I>/gnome-boxes ~/.local/share/
The process is faster if you install distributions or operating systems supported by libosinfo [5]. In addition to Debian 9, this also includes Windows 7 or Windows 10, but not Ubuntu 18.04 or the recently released Ubuntu 18.10. In this case, Boxes offers an Express installation, which loads the system into the VM in a completely automated process. The only option (at least for Linux guests) is the ability to specify the username and password (Figure 2). Pressing Next then continues the installation without any further intervention.
During the install, you will already find the new VM in the application's main screen (Figure 3). When the VM is active, the icon shows a colored live image of the system in the thumbnail. An inactive VM appears as a gray thumbnail. Clicking on the icon opens the VM in large format (Figure 4).
To return to the overview, use the left arrow in the top left corner of the application window; the VM continues to run in the background. You need to explicitly shut down the VM before Boxes really switches it off. If the mouse pointer is trapped in a VM, you can free it using the Ctrl+Alt keyboard shortcut.
Using the context menu in the overview (or the active VM's hamburger menu), you can access Properties. This is where you can share the contents of the clipboard between the VM and the host system (see "File Sharing" box) and forward devices connected to the host to the VM below Devices and Shares. In the System tab, you will find graphical history displays of CPU load, read/write operations, and network traffic. You can also adjust the size of the working memory and the virtual hard disk (Figure 5).
File Sharing
With the Properties | General option enabled below Share clipboard, you can easily exchange data between the guest and host systems. Texts are transferred in both directions using Ctrl+C and Ctrl+V. Simply drag files and folders from the File Manager to the VM application window. You will then be taken to the Downloads/
folder of the corresponding user. Alternatively, load files into the VM via the hamburger menu and the option Send file …. For the opposite direction, that is, from guest to host, this method does not yet work.
To copy data from the VM to the host or to set up a permanent data channel between the VM and the host system, configure a new shared folder below Properties | General | Devices and shares. In the file manager, the share will appear as Spice client folder under + Other locations (Figure 6).
If a VM no longer reacts, you can also force a restart or shutdown here. If you only need the machine for services in the background (such as a network stack for the web server and database – see the box entitled "User Mode Networking"), the Run in background option in this window can also be used to prevent the VM interface from opening. An interface configured in the VM is not affected by this option and still requires resources. It is therefore best to switch off the launch of the graphical environment completely in the corresponding VM or install the system without a GUI from the outset.
User Mode Networking
In the basic configuration, Qemu/KVM sets up a separate network between the host system and the guest. From the guest system you can reach the host via IP address 10.0.2.2 or 192.168.122.1 depending on the distribution. However, guests are not allowed to communicate with each other, and the guest cannot be reached from the host. To run a LAN-accessible service, such as a mail or database server, on the guest, you first need to configure a network bridge on the host [8].
The last tab, Snapshots, offers the possibility to take snapshots of the system loaded in the VM – handy if you want to experiment with the system or gain experience with a new distribution. All you have to do is click on the plus button. Using the gear menu next to the individual snapshots, you can restore an old state at the push of a button, rename the snapshot, or delete it from the hard disk.
Conclusions
In everyday life, Gnome Boxes impresses as an easy-to-use virtual system. In particular, current distributions with Gnome desktops fit seamlessly into the host system, from installation to a running system (see the "Guests" box). However, Boxes does not yet support advanced functions, such as dragging virtualized applications into the host system's window manager.
Guests
For the guest and host to understand each other perfectly, the SPICE Guest Agent (the binary is usually named spice-vdagent
) needs to be running on the guest – the service can be compared with the VMware tools or VirtualBox's Guest Extensions. For guest systems with Gnome desktops (since version 18.04 this also includes Ubuntu), this is usually the case by default. The resolution of the guest system is automatically adjusted to the window size in the live system; files can be transferred using drag and drop and the guest and host clipboards are synchronized. In addition, the image build-up in the VM with the SPICE Agent enabled is considerably accelerated.
However, on systems with other desktops, such as KDE Plasma or Xfce, you need to install the SPICE Agent retroactively. For Debian based distributions, do this as shown in Listing 2. Depending on the distribution, the virtualized system needs a reboot afterwards. In our lab, KDE Plasma 5.12.2 proved to be fully compatible with Netrunner 18.03. With Xfce 4.12 under Linux Mint Xfce 19, the clipboard worked in our lab, but transferring files failed. Also, the VM's resolution was not adjusted after changing the window size, until we ran the command:
xrandr --output Virtual-1 --auto
Exotic desktops like Moksha 0.3.0 from Bodhi Linux 5.0.0 didn't really understand what to do with the SPICE Guest Agent. According to the developers responsible for the SPICE agent at Red Hat, the fault lies with the desktops themselves [6].
For Windows guests, you need to load and install the SPICE Guest Tools [7] on the VM (Figure 7). On Windows 7 and Windows 10, the clipboard can be synchronized and files can be transferred using drag and drop, but automatic resolution adjustment does not work. For an optimized display, there is only the possibility to configure the resolution manually in the Windows system's settings or to switch the graphic back end to QXL, which is not possible with Boxes itself.
Listing 2
Installing the SPICE Agent on Debian
$ sudo apt install spice-vdagent $ sudo systemctl enable spice-vdagent $ sudo systemctl start spice-vdagent
The most important functions work without too much overhead. No guest extensions are needed for copying and pasting texts between Linux guests and the host system if you choose the right system. Adjusting the resolution of the virtual system to the size of the application window also works for current distributions without installing additional drivers on the guest system.
All in all, Gnome Boxes is an impressively simple and unpretentious VM solution. A Linux VM can be set up with a few clicks, from downloading the ISO image to setting up the graphical desktop. However, it lacks options for controlling the virtual system. For example, there is no option for managing the number of virtual CPU cores in Boxes. For some, this restriction to the bare essentials may be welcome; for others, Boxes offer enough to justify a switch from VirtualBox. Good thing there's a range of great VM options on Linux.
Infos
- Oracle VM VirtualBox Extension Pack Personal Use and Evaluation License: https://www.virtualbox.org/wiki/VirtualBox_PUEL
- Gnome Boxes: https://wiki.gnome.org/Apps/Boxes
- Qemu: https://www.qemu.org
- SPICE: https://www.spice-space.org
- libosinfo: https://libosinfo.org
- "Auto-screen-resolution change of qxl/spice guest not working": https://bugzilla.redhat.com/show_bug.cgi?id=1290586
- SPICE Guest Tools download: https://www.spice-space.org/download.html
- Bridged networking in Ubuntu: https://help.ubuntu.com/community/KVM/Networking#Bridged_Networking
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.