{"revision": {"id": "f1e04f80-2f95-11f1-a1cd-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 <guest name> \r\n\r\nStart a guest \r\n---------------------------------------------- \r\n\r\n**xen** \r\n | xm create /etc/xen/<guest name> \r\n\r\n**kvm** \r\n | virsh create /etc/libvirt/qemu/<guest name>.xml\r\n | virsh start <domain> \r\n\r\nConsole to guest\r\n---------------------------------------------- \r\n\r\n**xen** \r\n xm console <guest name> \r\n\r\n**kvm** \r\n virsh console <guest name> \r\n\r\nShutdown a guest \r\n---------------------------------------------- \r\n\r\n**xen** \r\n xm shutdown <guest name> \r\n\r\n**kvm** \r\n virsh shutdown <guest 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> <acpi/> </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/<guest name> /etc/xen/auto/<guest name> \r\n\r\n**kvm** \r\n virsh autostart <guest 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 <domain>\r\n\r\n\r\n\r\n\r\nPull the power on a guest\r\n----------------------------\r\n**xen**\r\n xm destroy <guest>\r\n\r\n**kvm**\r\n virsh destroy <domain>\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\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", "source_format": "rst", "revision_number": 17, "created": 1300229219000}}