KVM guest management
Install packages
Debian or Ubuntu
- sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
Redhat or Fedora
- yum install kvm
- yum install virt-manager libvirt libvirt-python python-virtinst
- chkconfig libvirtd on
- service libvirtd start
KVM virsh cheat sheet!
This is a list of commands to use in the virsh cli.
To start the virsh cli run the following cmd:
$ virsh
or:
virsh --connect qemu:///system
KVM has its own commands, but we like to use virsh.
Here is a list comparing Xen and KVM (virsh) commands.
List running guests
- xen
- xm list
- kvm
- virsh listvirsh dominfo <dom name>
Start a guest
- xen
- xm create /etc/xen/<dom name>
- kvm
- virsh create /etc/libvirt/qemu/<dom name>.xmlvirsh start <dom name>
Console to guest
- xen
- xm console <dom name>
- kvm
- virsh console <dom name>
Shutdown a guest
- xen
- xm shutdown <dom name>
- kvm
- virsh shutdown <dom name>
This command doesn't always work...
Be sure the guests XML file has the following entry:
<feature><acpi/></feature>
Also make sure the apci is installed on the guest operating system.
- debian / ubuntu
- sudo apt-get install acpid
- fedora / redhat
- yum install acpid
Autostart guest on reboot
- xen
- ln -s /etc/xen/<dom name> /etc/xen/auto/<dom name>
- kvm
- virsh autostart <dom name>
Edit a guests configuration file
- xen
- NA
- kvm
- virsh edit <dom name>
Pull the power on a guest
- xen
- xm destroy <dom name>
- kvm
- virsh destroy <dom name>
Quit virsh cli
- kvm
- virsh quit
Virtual Serial Console configuration
From the KVM host run:
virsh edit <dom>
Then add the following inside the <device></device> directives:
<serial type="pty">
<source path="/dev/pts/3" />
<target port="1" />
</serial>
From the Guest run:
sudo cp -p /etc/init/tty06.conf /etc/init/ttyS0.conf
sudo vi /etc/init/ttyS0.conf
sudo diff /etc/init/tty06.conf /etc/init/ttyS0.conf
Vmbuilder Example
This example assumes ubuntu linux.
Install vmbuilder
sudo apt-get install python-vm-builder
Display Help vmbuilder
vmbuilder kvm ubuntu --help
Custom vmbuilder string
mbison example
VMNAME=mbison
mkdir /vms/$VMNAME
sudo vmbuilder kvm ubuntu --libvirt=qemu:///system --suite=lucid --flavour=virtual \
--hostname=$VMNAME --domain='foxhop.net' --rootsize='10240' --mem='1024' \
--ip=192.168.1.51 --gw=192.168.1.254 --dns=192.168.1.22 --bridge=br0 \
--addpkg=openssh-server --addpkg=acpid --timezone=EDT --verbose
cammy example
VMNAME=cammy
mkdir /vms/$VMNAME
sudo vmbuilder kvm ubuntu \
--libvirt=qemu:///system \
--suite=lucid \
--arch=amd64 -o \
--flavour=virtual \
--hostname=$VMNAME \
--dest=/vms/$VMNAME \
--rootsize=20480 \
--mem=1024 \
--bridge=br0 \
--ip=192.168.1.52 \
--gw=192.168.1.254 \
--dns=192.168.1.22 \
--user=john \
--pass=doe \
--addpkg=openssh-server \
--addpkg=acpid \
--timezone=EDT \
--verbose
Mounting a qcow2 image on the host
Sometimes it is helpful to be able to mount a drive image under the host system. For example, if the guest doesn't have network support, the only way to transfer files into and out of the guest will be by the storage devices it can address or to restore files from a backup image.
To mount qcow2 images there is (at least in F-11 qemu) very useful qemu-nbd util. It shares image through kernel network block device protocol and this allows to mount it:
sudo modprobe nbd max_part=63
sudo qemu-nbd -c /dev/nbd0 image.img
sudo mount /dev/nbd0p1 /mnt/image
Add another disk image to a guest
This is how you add an additional disk to a guest. In this example I will be adding a 20GB disk image to a guest dom named cammy.
fallocate -l 20g /vms/cammy/cammy-aux.img
or
qemu-img create -f qcow2 /vms/cammy/cammy-aux.img 20G
If you want to look that the image statistics try this command.
qemu-img info /vms/cammy/cammy-aux.img
Comments
KVM, Port KVM Switches, KVM Switches, KVM Console, LCD KVM Console, KVM Console Switch, IP KVM Switches, KVM Console Switches dealers in India and KVM Console Switches suppliers in India.
KVM Console
For more details please visit http://www.kvmconsolesolutions.com/
KVM Console Switches suppliers in India (with KVM being an abbreviation for keyboard, video, or visual display unit, mouse) is a hardware device that allows a user to control multiple computers from a single keyboard, video monitor and mouse.
KVM Console
For more details please visit http://www.kvmconsolesolutions.com/
Leave a comment