Sunday, 6 March 2016

How to virtualise Linux – Part 2

Virtualise with KVM

A virtualisation tool built right into the Linux kernel, Kernel-based Virtual Machines are powerful and fairly easy to use.

Also known as Kernel-based Virtual Machine, this allows for a Linux distro itself to be the hypervisor for its own virtual machines. This requires hardware virtualisation support in Intel and AMD processors (Intel VT-x and AMD-V, respectively), but it supports a lot of different Linux distros and other operating systems. It can be managed graphically so it’s about as easy to use as VirtualBox while also being a little more efficient in some cases.

KVM is good for both desktops and servers used for creating virtual machines, but does require a little more setup than VirtualBox, while also being slightly easier than QEMU.

1. Test compatibility

It’s important to first find out whether your system can or cannot actually run virtual machines using  KVM, as it requires the hardware virtualisation support to be activated. To do this, open a terminal and use the following:

$ egrep -c ‘(svm|vmx)’ /proc/cpuinfo

If it returns a number of ‘1’ or higher, this means your CPU supports KVM, although you may need to activate it in the BIOS if the result of this tutorial doesn’t work.

kvmmain copy

2. Install KVM

Once you’re satisfied about whether your VMs will work or not, it’s time to actually install KVM – although it is part of the kernel, it’s not automatically activated all the time. To do this easily, simply open up the terminal again and then use:

$ sudo apt-get install qemu-kvm bridge-utils

This is purely the command line version, so if you want to add the graphical tools (which we’re covering), you can then install them with:

$ sudo apt-get install libvirt-bin virt-manager

3. Set up permissions

Normal users can’t use VMs in KVM, so you need to elevate any non-root users you’d like to have access these VMs by adding them to groups with the correct permissions. The group in question is libvirtd, and you can add your own username to it with:

$ sudo adduser [username] libvirtd

Log out and back in again, and check to make sure it worked by using:

$ virsh -c qemu:///system list

It will then list all of the working VMs, which at the moment will be none.

4. Create a virtual machine

In the menus of your distro you should be able
to find the Virtual Machine Manager. Open it up and you will be greeted with the graphical interface for the system. From here you can make a bit of a shortcut to creating your virtual machines by first clicking on the ‘Create a new virtual machine icon’.

We’re going to be working from an ISO, so choose that, and then select the ISO that you plan to use. Give the VM a set amount of RAM (we like to go with half of what you have, but refer to our boxout on CPU usage for specifics on the matter), and an amount of storage memory.

5. Install on the virtual machine

Click Finish and you’ll open the VM once it’s all ready to go. Depending on your selected distro, you’ll go through a different installation process – major distros will be easily able to recognise where and how to install with little trouble.

Unlike VirtualBox, you don’t quite have the right-hand Control button to use as a ‘host key’, so you’ll have to manually fullscreen and un-fullscreen it.

6. Manage virtual machines

Virtual machines can be paused, forced off, forced to reset and have standard reboot and shutdown signals sent to them. You can use the ‘Send key’ option in the interface while it’s running to send some of the standard Ctrl+Alt shortcuts to the machine, including ones using the F keys to go between different instances.

You can’t modify the virtual machines, but you can certainly create more to different specifications, or just delete them and start over. You can also ‘Redirect USB device’ from the ‘Virtual Machine’ menu on the top bar, allowing you to access external storage.

kvm4 copy

Choose a distro

Get your creative juices flowing with these ideas for Linux distributions to virtualise that can increase your productivity.

Fedora: getfedora.org

The benefit of using Fedora for development is that you always have access to the latest software to work on, and due to its use of only free and open source software it makes for a much cleaner working environment. A lot of build environments have versions available and optimised for Fedora, so you can either work in there if you really want to, or just run software in there to see how it reacts. As there’s a fair amount of time between each different Fedora, you’ll be able to use the virtual machine for a while without having to worry about doing a full update every six months or less. There’s also very good virtualisation support in the distro to make sure that it works well in conjunction with some of the virtualisation protocols.

fedora copy

Arch Linux: archlinux.org

This rolling Linux distro can be almost anything you want it to be. This makes it perfect for creating a testing environment requiring specific software, or a development environment that is efficient and separate from your normal system. The main difference when using Arch on a virtual machine is that you install a different graphics driver that makes better use of virtualisation (there’s a specific one for VirtualBox, for example). With the rolling updates, you can always test the latest versions of software, while it’s also easier to roll back and test with older bits and pieces for specific setups. You can also fairly easily create an ISO based on a particular setup, allowing you to create multiple VMs in a cloud environment with the very same setup, and very quickly as well. There are plenty of other handy features for virtualising, which you can read up on using the Arch wiki.

Kodibuntu: kodi.tv

If you want to turn your system into a media centre for brief periods of time, virtualising media centre software is an easy and quick way to switch into it without disturbing any of your currently running work. Probably the best media centre software available is Kodi, and the best version for virtualisation on normal systems is Kodibuntu. As the name suggests, it’s a spin of Ubuntu that only has the Kodi environment, making it an excellent virtualisation base to then use Kodi properly as well. Kodi is very easy to use in general, with logically laid-out menus and great support for connecting to shares over the network or on the host. Using USB passthrough, you can even allow for remotes and other IR receivers to control Kodi. It won’t be as good as a proper installation, but it will be a lot better than your normal distro.

Tails: tails.boum.org

Tails is the distro that allows you to have maximum privacy online. However, while it’s generally getting more user-friendly while still remaining very private, it’s not the best distro to use on a daily basis. Which is fine – it’s not designed that way – however, the privacy features can be very beneficial every now and then. Virtualising Tails isn’t perfect, and some aspects of its privacy won’t work as well as it would by running it natively on your hardware, but for sending the odd encrypted email and quickly connecting to Tor, it still works very well. Tails does have installation abilities, but it has very little benefit over live booting from the ISO as you would normally do anyway. All the other software works just fine virtualised, so even though it’s not really meant for use inside a VM, it has packages in place to allow it.

tails copy

Backup and restore

Make sure to keep your virtual operating systems backed up and safe with these handy software tips.

One of the benefits of using virtual machines is that they’re easier to create backups or snapshots of specific states so that you can revert back to them in the future, or launch from the previous one while preserving the latest version. This is a good way to test software and code on different versions of the same distro without requiring several installs at once.

Backing up and snapshots are quite different in the software, so it’s best to think about what you want to do. Do you want to restore an older version if something goes wrong with the VM, or if something goes wrong with the host device?

Back up and restore

As the virtual systems all exist on a virtual hard drive, it makes it a lot easier to back them up. In most cases, you can just copy the file and move it somewhere safe or secure. In something like VirtualBox, these virtual appliances also contain some of the information on how to boot the VM, which makes it easy to then restore it later without having to tweak the settings too much.

VirtualBox also has the ability to export virtual appliances into a file better suited for restoring later, which also then has all the system details of the VM. This creates an OVF (open virtualisation file) which is usable by other hypervisors and virtual machine software.

Restoring with just a virtual hard drive device is nice and easy. In VirtualBox, you can just create a new virtual machine and use an existing virtual hard drive from anywhere on your filesystem. You’ll have to double-check the settings in order to make sure everything is right so that everything works as well as it should.

Snapshots

An excellent feature of VirtualBox is the ability to create a snapshot of the virtual machine at its current state. These can then be used as reference points to start working from again using older software, cloned to create a different package and upgrade path, etc.

To create a snapshot, first select your virtual machine from the manager. At the top-right of the VirtualBox interface is the Snapshots tab – from here you can press the camera button to create a snapshot of the current system. You can then select which version to start up each time, but be warned that it does eat up extra storage space.



from Linux User & Developer – the Linux and FOSS mag for a GNU generation http://ift.tt/1X3VmfT
via IFTTT

No comments:

Post a Comment

Amazon

Donate

Donate Towards More Raspberry PI's for Projects