howto

KVM Linux Guests

QEMU/KVM Linux Guests installation and management examples

CentOS 6 Guest install

# Download CentOS minimal iso from CentOS mirrors
wget http://ftp.funet.fi/pub/Linux/INSTALL/Centos/6.4/isos/x86_64/CentOS-6.4-x86_64-minimal.iso

# Pre-create VM disk image
qemu-img create -f qcow2 -o preallocation=metadata /storage/local/images/centos6vm.qcow2 10G

# Launch installation inside screen
screen
virt-install --connect qemu:///system \
--name centos6vm --ram 1024 --vcpus 1 \
--disk path=/storage/local/images/centos6vm.qcow2,format=qcow2,bus=virtio,cache=none \
--network=network:default,model=virtio --vnc --os-type=linux --os-variant=rhel6 \
--cdrom /storage/local/iso/CentOS-6.4-x86_64-minimal.iso --accelerate --noautoconsole --keymap=en-us
# Detach screen
CTRL+A+D

# Run virt-manager for VNC display
# (make sure you have X forwarding enabled on your ssh session for remote display)
virt-manager
# OR
virt-viewer -c qemu:///system centos6vm

VM export/import

# Export KVM VM definition on export node and copy it to target node - together with VM disk image(s)
virsh -c qemu:///system dumpxml domain > /storage/local/images/domain.xml
rsync -av --progress /storage/local/images/domain.xml root@targethost:/storage/local/images/
rsync -av --progress /storage/local/images/domain_disk1.qcow2 root@targethost:/storage/local/images/

# Define KVM VMs on target node
virsh -c qemu:///system define /storage/local/images/domain.xml