QEMU/KVM and virt-manager
QEMU/KVM is a full virtualisation solution supported by Linux via a kernel module. virt-manager is a gui tool to easily create and manage virtual machines using QEMU/KVM.
- You may need to enable virtualisation technology in the BIOS
apt install virt-manager qemu-kvm- For a non-root user to be able to use virtual machines, add it to the groups
libvirt,libvirt-qemuandkvm(usermod -aG libvirt,libvirt-qemu,kvm {user}, the user may need to relog)
Create and run a machine
Just launch the virtual-manager gui.
QEMU/KVM has a concept of "sessions", which are groups of virtual machines. The "QEMU/KVM user session" contains only machines of the current user, the "QEMU/KVM (session:///system)" contains the machine of the whole system (as if root were running the commands) and allows for more configuration (e.g. network interface creation and configuration).
Clipboard share between host and guest
On a Debian guest with Debian host combo, just installing the spice-vdagent package in the guest and then rebooting it works for bidirectional sharing of clipboard.
Otherwise, connecting to the machine using ssh is a good solution
Share folders between host and guest
- Create a folder in one of the storage locations set up in virt-manager
- Give read/write/execute access to the folder to group
libvirt-qemu:chmod g+rwx {folder}chown :libvirt-qemu {folder}
- Open the machine settings in virt-manager and click Add hardware -> Filesystem: set driver to "default", mode to "mapped", path to the folder and target path to anything
- In guest:
- Create a folder where the share will be mounted
- Execute as root:
mount -t 9p -o trans=virtio,version=9p2000.L {target path set up in virt-manager} {mount folder}
Have multiple disk images share the same base
In order to save space, a machine disk can be created which is based on another disk. This uses the qcow2 (Copy On Write) format: only the differing sectors are written to the new file.
qemu-img info {filename}to obtain information about the base image. Note its format.qemu-img create -f {format for new image (e.g. qcow2)} -F {format for backing image (e.g. qcow2)} -b {backing image file} {new image file}qemu-img info {new image file}to verify that the new image indeed uses the other one as backing image. Check that backing image format is specified.
Virtualbox
- Install virtualbox package using of the methods below
- During the installation a warning may be raised to "install the Linux kernel "header" files matching the current kernel". In that case
apt install linux-headers-amd64/sbin/vboxconfig
Install from debian repository
This guide is for debian 9.
- Install apt repository
stretch-backports,contribsection as well asmain(virtualbox packages are not available in debian 9):- Edit
/etc/apt/sources.list- Add
deb {your debian mirror (e.g. http://ftp.debian.org/debian)} stretch-backports main contrib
- Add
apt update
- Edit
apt install virtualbox
Install from virtualbox repository
See Install packages not in repository.
This guide is for debian 9.
- Repository key is
https://www.virtualbox.org/download/oracle_vbox_2016.asc -
Repository apt entry is
deb http://download.virtualbox.org/virtualbox/debian stretch contrib -
apt install virtualbox
Download package from official site
- Download the package from official download page
dpkg -i {package}
Disable virtualbox services
During setup, virtualbox sets its services to be enabled to automatically start at boot time. To disable this, run
pushd /lib/systemd/system/ && for s in vbox* ; do systemctl disable $s ; done && popd
If you do this, in order to use virtualbox you must first execute:
pushd /lib/systemd/system/ && for s in vbox* ; do systemctl start $s ; done && popd