Introduction to virtualisation
Scientific Linux allows you to run virtual machines (VMs) on your physical machine. A virtual machine is a machine that has access to virtual, not real, hardware devices – but from the perspective of the operating system this doesn’t matter. Virtual machines allow a complete operating system installation to be isolated from the host operating system (the host is the computer hosting the virtual machine – the virtual machine is also known as a guest). Project groups can be given their own virtual machines to work on without endangering the work of other groups. Services can be isolated within virtual machines so that they do not interfere with other services.
The Scientific Linux virtualisation system is built on the KVM kernel module and the QEMU machine emulator. These are managed by a management layer called libvirt. To install the virtual machine manager do:
sudo yum install -y virt-manager qemu-kvm libvirt virt-viewer
This will install virt-manager and create a menu item in the Applications -> System Tools menu. You need to change some access control settings in /etc/libvirt/libvirtd.conf. Edit this as the root user and set:
- unix_sock_group to “kvm” (line 81)
- unix_sock_rw_perms to “0770” (line 98)
- auth_unix_rw to “none” (line 138)
Now start the libvirt daemon:
sudo service libvirtd start
and add the user that will be managing virtual machines to group kvm. If the user is named myuser do:
sudo usermod -a -G kvm myuser
You might need to log out and log back in for this change to be reflected. After all these changes you will be able to run the Virtual Machine Manager as as an ordinary user.
Creating a virtual machine
For a graphical guide to how to install a new virtual machine using Virtual Machine Manager (also known as *virt-manager) consult this guide from Slackware. The steps are:
- Select the Create a Virtual Machine icon (on the top left)
Choose a name and installation method. For this example choose Local media install and:
- Use ISO Image then select
- Browse and select
- Browse local and then finally select the Scientific Linux Install ISO and select Open
- Select Linux for the OS Type
- Select Red Hat Enterprise Linux 6 for the Version and then choose Forward
- Choose a reasonable amount of RAM (e.g. 1024MB) and CPUs (e.g. 1)
- Enable storage for the Virtual Machine and create a disk image. You can choose a small size (e.g. the default 8GB) for this demo install and you don’t need to allocate entire disk now.
- Finally when you choose Finish the virtual machine will be created and it will boot into the Scientific Linux install. Because only 1024MB RAM was selected this might use the text-based installer. If the graphical installer is used, you might have to use the virtual machine console’s scroll bars to see all the options on the screen.
An alternative to using virt-manager is doing the install from the command line using virt-install. A sample of virt-install (with bridged networking) is show in this [Howto]. Something similar to the above virt-manager install can be achieved using:
virt-install --connect qemu:///system --name sl1 --ram=1024 --vcpus=1\ --cdrom=/path/to/SL-6.6-x86_64-2014-11-05-Install-DVD.iso\ --os-type=Linux --os-variant=rhel6\ --disk=/var/lib/libvirt/images/sl1.img,size=8,format=qcow2\ --network="network=default" --graphics=spice
Managing your virtual machines with virsh
To test that your virtual machine environment is working you can use the libvirt shell virsh.
virsh -c qemu:///system sysinfo
Note that when you are running virsh as a non-root user (one that has been given permissions to manage VMs via the steps outlined above), you have to include the -c qemu:///system to specify the connection to use. This is not necessary when running virsh as root.
To list existing virtual machines use virsh list.
$ sudo virsh -c qemu:///system list Id Name State ---------------------------------------------------- 3 vm1 running
Other useful virsh commands are:
- virsh start
– start a virtual machine named
- virsh create
– create a new virtual machine from the definition in
- virsh shutdown
– send a shutdown signal to the virtual machine named
- virsh destroy
– immediately halt the virtual machine named
- virsh dumpxml
– dump the XML format definition of
Each virtual machine has a specification in XML format. These are stored in
/etc/libvirt by default and are only readable by the root user. In these definition files all the disks, network interfaces and other details of the virtual machine are specified.