{"revision": {"id": "f1e0ccfa-2f95-11f1-9d0a-e86a64d24d78", "node_id": "f1df5bd8-2f95-11f1-9651-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "KVM guest management\r\n=======================\r\n\r\n.. contents:: \r\n\r\n\r\nInstall packages \r\n===============================\r\n\r\n**Debian or Ubuntu**\r\n\r\n* sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils\r\n\r\n\r\n**Redhat or Fedora** \r\n\r\n* yum install kvm \r\n* yum install virt-manager libvirt libvirt-python python-virtinst \r\n* chkconfig libvirtd on \r\n* service libvirtd start \r\n\r\n\r\nKVM virsh cheat sheet!\r\n============================\r\n\r\nThis is a list of commands to use in the virsh cli.\r\n\r\nTo start the virsh cli run the following cmd:\r\n\r\n.. code-block:: bash\r\n  \r\n  $ virsh\r\n\r\nor:\r\n\r\n.. code-block:: bash\r\n\r\n  virsh --connect qemu:///system\r\n\r\nKVM has its own commands, but we like to use virsh.   \r\n\r\nHere is a list comparing Xen and KVM (virsh) commands. \r\n\r\nList running guests \r\n---------------------------------------------- \r\n\r\n**xen** \r\n | xm list \r\n\r\n**kvm** \r\n | virsh list \r\n | virsh dominfo <dom name> \r\n\r\nStart a guest \r\n---------------------------------------------- \r\n\r\n**xen** \r\n | xm create /etc/xen/<dom name>\r\n\r\n**kvm** \r\n | virsh create /etc/libvirt/qemu/<dom name>.xml\r\n | virsh start <dom name>\r\n\r\nConsole to guest\r\n---------------------------------------------- \r\n\r\n**xen** \r\n xm console <dom name>\r\n\r\n**kvm** \r\n virsh console <dom name>\r\n\r\nShutdown a guest \r\n---------------------------------------------- \r\n\r\n**xen** \r\n xm shutdown <dom name> \r\n\r\n**kvm** \r\n virsh shutdown <dom name> \r\n\r\nThis command doesn't always work...  \r\n\r\nBe sure the guests XML file has the following entry:\r\n\r\n | <feature> \r\n |  <acpi/>\r\n | </feature>\r\n\r\nAlso make sure the apci is installed on the guest operating system.\r\n\r\n**debian / ubuntu**\r\n sudo apt-get install acpid\r\n\r\n**fedora / redhat**\r\n yum install acpid\r\n\r\nAutostart guest on reboot \r\n---------------------------------------------- \r\n\r\n**xen** \r\n ln -s /etc/xen/<dom name> /etc/xen/auto/<dom name>\r\n\r\n**kvm** \r\n virsh autostart <dom name>\r\n\r\nEdit a guests configuration file\r\n-----------------------------------\r\n**xen**\r\n  NA\r\n\r\n**kvm**  \r\n virsh edit <dom name>\r\n\r\n\r\n\r\n\r\nPull the power on a guest\r\n----------------------------\r\n**xen**\r\n xm destroy <dom name>\r\n\r\n**kvm**\r\n virsh destroy <dom name>\r\n\r\nQuit virsh cli\r\n-----------------\r\n\r\n**kvm** \r\n virsh quit\r\n\r\n\r\n\r\n\r\n\r\nNote\r\n------\r\nTypically the guests harddrive is not attached, you must add it in the configuration.\r\n\r\nTypically the guests memory is set to 100mbs, you might want to change that in the configuration.\r\n\r\nOnce booted and ssh'd into the VM, cat /etc/network/interfaces to verify that the DNS settings are correct.\r\n\r\nDebian/ubuntu guest don't have acpid installed by default. (Could change the vmbuilder string)\r\n\r\n\r\nVmbuilder Example\r\n======================\r\n\r\nThis example assumes ubuntu linux.\r\n\r\nInstall vmbuilder\r\n---------------------\r\n\r\n.. code-block:: python\r\n\r\n sudo apt-get install python-vm-builder\r\n\r\nDisplay Help vmbuilder\r\n--------------------------------\r\n\r\n.. code-block:: python\r\n\r\n vmbuilder kvm ubuntu --help\r\n\r\nCustom vmbuilder string\r\n-------------------------------\r\n\r\nmbison example \r\n\r\n.. code-block:: bash\r\n\r\n VMNAME=mbison\r\n mkdir /vms/$VMNAME\r\n\r\n sudo vmbuilder kvm ubuntu --libvirt=qemu:///system --suite=lucid --flavour=virtual \\\r\n --hostname=$VMNAME --domain='foxhop.net' --rootsize='10240' --mem='1024' \\\r\n --ip=192.168.1.51 --gw=192.168.1.254 --dns=192.168.1.22 --bridge=br0 \\\r\n --addpkg=openssh-server --addpkg=acpid --timezone=EDT --verbose\r\n\r\ncammy example\r\n\r\n.. code-block:: bash\r\n\r\n VMNAME=cammy\r\n mkdir /vms/$VMNAME\r\n\r\n sudo vmbuilder kvm ubuntu --libvirt=qemu:///system --suite=lucid --flavour=virtual \\\r\n --ip=192.168.1.52 --gw=192.168.1.254 --dns=192.168.1.22 \r\n --hostname=$VMNAME --domain='foxhop.net' --bridge=br0 \\\r\n --raw=/vms/$VMNAME --rootsize='20480' --mem='1024' \\\r\n --addpkg=openssh-server --addpkg=acpid --timezone=EDT --verbose\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nMount a qcow2 or raw image file\r\n=================================\r\n\r\nThe following procedures allow a host to mount a guest image file.  This is useful when trouble shooting issues with the guest.  The following procedures require root access (you can sudo).\r\n\r\n**qcow2**\r\n\r\n.. code-block:: python\r\n\r\n modprobe nbd max_part=63\r\n qemu-nbd -c /dev/nbd0 image.img\r\n mount /dev/nbd0p1 /mnt/image\r\n\r\n**raw**\r\n\r\n.. code-block:: python\r\n \r\n losetup /dev/loop0 image.img\r\n kpartx -a /dev/loop0\r\n mount /dev/mapper/loop0p1 /mnt/image\r\n\r\nIf there is an LVM present on the image file, you can initialize it by running\r\n\r\n.. code-block:: python\r\n\r\n vgscan\r\n vgchange -ay\r\n mount /dev/VolGroupName/LogVolName /mnt/image\r\n\r\nRun the following when finished\r\n\r\n.. code-block:: python\r\n\r\n umount /mnt/image\r\n vgchange -an VolGroupName\r\n killall qemu-nbd\r\n kpartx -d /dev/loop0\r\n losetup -d /dev/loop0\r\n\r\nreference: http://en.wikibooks.org/wiki/QEMU/Images\r\n\r\n\r\nBacking up kvm guests with virtback\r\n=======================================\r\n\r\nhttp://russell.ballestrini.net/virtback-a-python-libvirt-backup-utility-for-kvm/\r\n\r\ndownload virtback and place it into usr/local/bin \r\n\r\nrun: *virtback -h* for a list of options\r\n", "source_format": "rst", "revision_number": 38, "created": 1309382757000}}