Linux Format

Make use of Vagrant

Vagrancy is generally not a trait to be encouraged, but we can heartily recommend Vagrant for your VM pleasure.

-

Setting up virtual machines from scratch is all well and good, but if you wanted to set up a whole fleet of them (or even if you keep breaking one and having to set it up again from scratch), then some degree of automation is desirable. There are a few options here. One would be to take regular snapshots of the VMs state, so that if it breaks you can revert it to a known good state. Boxes has a simple Snapshot option in the options menu and Virt-manager’s is available from the toolbar. VMs (and snapshots of VMs) in virt-manager can also be cloned, so it’s possible to set up several copies once you’ve got one set up just the way you like it.

However, none of that obviates the initial effort of setting up a VM, tweaking the OS and updating everything. So if you find yourself often in this cycle, don’t fret – let Vagrant take care of all this grunt work instead. Hashicorp’s Vagrant is a tool for provisioni­ng and managing VMs, with an emphasis on setting up developmen­t environmen­ts. Vagrant VMs are known as Boxes (which hopefully we won’t confuse with Gnome Boxes here) and are easy to set up, either from scratch or from a prepared offering from www.vagrantclo­ud.com.

There are official boxes from Hashicorp and distro teams, as well as unofficial boxes from the community (available from www.vagrantbox.es). There are Vagrant boxes for almost any use case you can imagine, but be aware that the unofficial ones aren’t vetted or guaranteed. We’d advise exercising a degree of caution when dealing with these.

Get Vagrant up and running

Vagrant is a largely frontend-agnostic tool, in that it can create VMs for VirtualBox, Hyper-V and Docker. Additional providers are available as plugins. These include VMware (recommende­d where performanc­e is critical), libvirt (which we’re about to make use of) as well as cloud providers such as AWS. Our first task will be to install Vagrant, which on Debian-like distros (including Ubuntu) is achieved as follows (don’t worry about the message that apt-key is deprecated):

$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add $ sudo apt-add-repository “deb [arch=amd64] https:// apt.releases.hashicorp.com $(lsb_release -cs) main” $ sudo apt update && sudo apt install vagrant

Shockingly, Curl wasn’t present on our Ubuntu 22.04 install, so you may need to install that first. For other distros (or cloud installs on Amazon Linux) see the instructio­ns at www.vagrantup.com/downloads. Vagrant and its (sprawling) dependenci­es will only occupy about 150MB, but beware that VMs have a habit of growing and filling up your disks. So make sure that you have plenty of space on the partition which they’re stored.

Vagrant’s default provider is VirtualBox, which we’re shunning slightly for this particular adventure. So let’s

get the libvirt provider installed, so that we may continue to use Virt-manager:

$ vagrant plugin install vagrant-libvirt

Arch Linux has a reputation of being tricky to install and, once installed, the distro takes days to set up to one’s liking. Without commenting on the veracity of this assertion, let’s get the official Vagrant Arch box spun up in mere seconds:

$ mkdir vagrant_arch

$ cd vagrant_arch

$ vagrant init archlinux/archlinux

You’ll see a message saying that a Vagrantfil­e has been set up in this directory, and that you’re now ready to go. Have a look at said Vagrantfil­e if you want (it’s somewhat minimal because we’re using an off-the-shelf configurat­ion, but there are some useful comments to help you understand how to tweak things). Then activate the VM with the following:

$ vagrant up

After a few moments’ setup and a request for a password you’ll be ready to go. Or hopefully. You might instead see a message about the NFS version or transport protocol not being supported. This happened to us, and if it happens to you too then edit (as root) /etc/nfs.conf, adding the line udp=y in the [nfsd] section. Then run:

$ sudo systemctl restart nfs-server

to effect the changes, and try again.

Access the Plasma desktop

All being well you should see a new VM appear in Virt-manager (in the standard KVM/QEMU connection this time, rather than the user session) called vagrant_ arch_default. And if you open it up, you can log in with using vagrant as both username and password. As you can see, it’s quite a lightweigh­t VM, but there’s no need for it to stay that way. Let’s install the barebones KDE Plasma package and see how easy it is to achieve a fully featured GUI.

$ sudo pacman -S plasma-desktop

The installati­on will ask you lots of questions – everything from audio systems to fonts – and there aren’t any right or wrong answers, so choose what you like. Pacman will then jump into action and set up almost everything we need for our desktop. We still need some more (fairly critical) packages, in the form of a display (login) manager, X.org itself and a terminal emulator:

$ sudo pacman -S sddm xorg-server konsole

There are still some important bits missing, but we’re now in a position to start and login to our desktop with:

$ sudo systemctl start sddm

You’ll notice that only the US keymap is available at the login screen, and that

SDDM’s default theme is rather spartan.

Once logged in, you’ll see that very few applicatio­ns are installed, and that some shortcuts are missing their applicatio­ns.

It’s quite hard to remedy this without a terminal, so it’s just as well that we installed

Konsole earlier. We can fix our keymap by editing /etc/locale.gen (you may wish to install Nano too) and uncommenti­ng the line en_GB.utf-8 (or whichever keymaps you require) and running:

$ sudo locale-gen $ sudo localectl set-x11-keymap gb

You’ll also need to update /etc/locale.conf with the new locale (but really you should read the Arch Wiki for all these set up details). We’ll leave you to find some nice themes for SDDM. If you want to auto start the GUI on each boot then run:

$ sudo systemctl enable sddm

By this point you’ve probably noticed that our VM is much slower than our simple Gnome Boxes box. But don’t lose hope. We’re using the emulated Cirrus video card and have zero graphical accelerati­on. Fix this by shutting down the VM, going to its Hardware Informatio­n page, selecting Add Hardware>Graphics and setting up a Spice Server. As before, we need to check the OpenGL box and make sure that Address Type is set to None.

Now click Finish and navigate to the Video Cirrus section. Change this to VirtIO and check the 3D accelerati­on box. You might have also noticed that the Vagrantfil­e only assigned 512MB of memory to our box. This certainly will not do, so change this to something bigger.

 ?? ?? A box for all seasons. Whatever you need there’s likely a Vagrant Box that does it.
A box for all seasons. Whatever you need there’s likely a Vagrant Box that does it.
 ?? ??
 ?? ?? Behold, Arch Linux with KDE Plasma, set up in no time and with no cursing, either. Unreal. Virtual.
Behold, Arch Linux with KDE Plasma, set up in no time and with no cursing, either. Unreal. Virtual.
 ?? ?? You’ll need your best Arch-fu to install SDDM themes from the AUR.
You’ll need your best Arch-fu to install SDDM themes from the AUR.
 ?? ??
 ?? ??
 ?? ??

Newspapers in English

Newspapers from Australia