个人工具
登录
查看“UbuntuHelp:KVM/Managing”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:KVM/Managing”的源代码
来自Ubuntu中文
←
UbuntuHelp:KVM/Managing
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{From|https://help.ubuntu.com/community/KVM/Managing}} {{Languages|UbuntuHelp:KVM/Managing}} #title KVM Guest Management <<Include(KVM/Header)>> == Manage your virtual machines == === From the shell === You can manage your VMs from the shell using [http://linux.die.net/man/1/virsh virsh]. You can get a list of the available commands if you type "help". Type "help command" to get additional infos for a particular command. ==== Define your new VM ==== Before you can manage your new VM with virsh, you must define it: <pre><nowiki> $ virsh --connect qemu:///system Connecting to uri: qemu:///system Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # define /etc/libvirt/qemu/newvm.xml Domain newvm defined from /etc/libvirt/qemu/newvm.xml </nowiki></pre> Note that to list newvm, you must use 'list --inactive' or 'list --all', since list without any options will only list currently running machines. ==== List your VMs ==== Virsh allows you to list the virtual machines available on the current host: <pre><nowiki> yhamon@paris:/etc/libvirt/qemu$ virsh --connect qemu:///system Connecting to uri: qemu:///system Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # help list NAME list - list domains SYNOPSIS list [--inactive | --all] DESCRIPTION Returns list of domains. OPTIONS --inactive list inactive domains --all list inactive & active domains virsh # list Id Name State ---------------------------------- 15 mirror running 16 vm2 running virsh # list --all Id Name State ---------------------------------- 15 mirror running 16 vm2 running - test5 shut off </nowiki></pre> ==== Define, undefine, start, shutdown, destroy VMs ==== The VMs you see with list --all are VMs that have been "defined" from an XML file. Every VM is configured via a XML file in /etc/libvirt/qemu. If you want to remove a VM from the list of VMs, you need to undefine it: <pre><nowiki> virsh # undefine test5 # WARNING: undefine will delete your XML file! Domain test5 has been undefined virsh # list --all Id Name State ---------------------------------- 15 mirror running 16 vm2 running </nowiki></pre> To be able to undefine a virtual machine, it needs to be shutdown first: <pre><nowiki> virsh # shutdown mirror Domain mirror is being shutdown </nowiki></pre> This command asks for a nice shutdown (like running shutdown in command line) - but you can also use "destroy", the more brutal way of shutting down a VM, equivalent of taking the power cable off: <pre><nowiki> virsh # destroy mirror Domain mirror destroyed </nowiki></pre> If you have made a change to the XML configuration file, you need to tell KVM to reload it before restarting the VM: <pre><nowiki> virsh # define /etc/libvirt/qemu/mirror.xml Domain mirror defined from /etc/libvirt/qemu/mirror.xml </nowiki></pre> Then, to restart the VM: <pre><nowiki> virsh # start mirror Domain mirror started </nowiki></pre> ==== Suspend and resume a Virtual Machine ==== Virsh allows you to easily suspend and resume a virtual machine. <pre><nowiki> virsh # suspend mirror Domain mirror suspended virsh # resume mirror Domain mirror resumed </nowiki></pre> == Editing the attributes of a Virtual Machine == libvirt stores it's configuration as xml in '/etc/libvirt/qemu'. The xml is easy to understand, and is similar to [[UbuntuHelp:VMware|VMware]] *.vmx files. While it is possible to edit these files in place and restart libvirt-bin for the changes to take affect, the recommended method for modifying the attributes of a virtual machine is via virsh (or virt-manager, if it supports changing the hardware you want to change). The concept is simple: <ol><li>export (aka 'dump') the xml of the virtual machine you want to edit </li><li>edit the xml </li><li>import (aka 'define') the xml</li></ol> For example, to edit the machine named 'foo' (you can get a list of your machines with 'virsh list --all'), do:<pre><nowiki> $ virsh dumpxml foo > /tmp/foo.xml (edit /tmp/foo.xml as needed) $ virsh define /tmp/foo.xml </nowiki></pre> === Adding CPUs === KVM allows you to create SMP guests. To allocate two CPUs to a VM, dump the xml as above, then edit your xml to have:<pre><nowiki> <domain type='kvm'> ... <vcpu>2</vcpu> ... </domain> </nowiki></pre> Now define the VM as above. === Adding Memory === To change the memory allocation in a VM, dump the xml as above, then edit your xml to have:<pre><nowiki> <domain type='kvm'> ... <memory>262144</memory> <currentMemory>262144</currentMemory> ... </domain> </nowiki></pre> Now define the VM as above. Keep in mind that the memory allocation is in kilobytes, so to allocate 512MB of memory, use 512 * 1024, or 524288. === Changing the Network Card Model === kvm and qemu currently default to using the rtl8139 NIC. Supported NICs in Ubuntu 8.04 LTS are i82551, i82557b, i82559er, ne2k_pci, pcnet, rtl8139, e1000, and virtio. To use an alternate NIC, dump the xml as above, then edit your xml to have:<pre><nowiki> <domain type='kvm'> ... <interface type='network'> ... <model type='e1000'/> </interface> ... </domain> </nowiki></pre> Now define the VM as above. === Adding USB Device Pass-through === ==== Limitations ==== * USB protocol 1.1 only * Device must be plugged in before KVM starts * Apparmor modifications needed ==== Apparmor Modification ==== In order for a software program to access the usb device correctly the apparmor must be changed. Edit '''/etc/apparmor.d/abstractions/libvirt-qemu''' and uncomment some lines.: <pre><nowiki> # WARNING: uncommenting these gives the guest direct access to host hardware. # This is required for USB pass through but is a security risk. You have been # warned. /sys/bus/usb/devices/ r, /sys/devices/*/*/usb[0-9]*/** r, /dev/bus/usb/*/[0-9]* rw, </nowiki></pre> After making the changes apparmor must be restarted.: <pre><nowiki> $ sudo /etc/init.d/apparmor restart </nowiki></pre> ==== Adding USB devices ==== First find the usb Vendor ID and Product ID.: <pre><nowiki> $ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 005 Device 012: ID 0a5c:2110 Broadcom Corp. Bluetooth Controller Bus 005 Device 003: ID 0483:2016 SGS Thomson Microelectronics Fingerprint Reader Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub </nowiki></pre> In the event that the '''Broadcom Corp. Bluetooth Controller''' wans to be selected the vendor and product ids are '''0a5c''' and '''2110''' respectively. These can be entered into the xml profile. This can be done through virsh through the '''edit <domain>''' command.: <pre><nowiki> <domain type='kvm'> <name>windowsxp</name> … <devices> … <hostdev mode='subsystem' type='usb'> <source> <vendor id='0x0a5c'/> <product id='0x2110'/> </source> </hostdev> </devices> </domain> </nowiki></pre> === Get new IDs === To get a new mac address to paste into your xml file, use this command: MACADDR="52:54:$(dd if=/dev/urandom count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4/')"; echo $MACADDR To get a new uuid for your xml file, use: uuidgen <<Include(KVM/Header)>> ---- [[category:CategoryVirtualization]] [[category:UbuntuHelp]]
该页面使用的模板:
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
返回至
UbuntuHelp:KVM/Managing
。