特殊:Badtitle/NS100: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...' |
小无编辑摘要 |
||
第97行: | 第97行: | ||
virsh # resume mirror | virsh # resume mirror | ||
Domain mirror resumed | Domain mirror resumed | ||
</nowiki></pre> | </nowiki></pre> | ||
== Editing the attributes of a Virtual Machine == | == Editing the attributes of a Virtual Machine == |
2009年11月17日 (二) 19:43的版本
![]() |
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/KVM/Managing }} |
![]() |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/af | • {{#if: UbuntuHelp:KVM/Managing|Afrikaans| [[::KVM/Managing/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ar | • {{#if: UbuntuHelp:KVM/Managing|العربية| [[::KVM/Managing/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/az | • {{#if: UbuntuHelp:KVM/Managing|azərbaycanca| [[::KVM/Managing/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/bcc | • {{#if: UbuntuHelp:KVM/Managing|جهلسری بلوچی| [[::KVM/Managing/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/bg | • {{#if: UbuntuHelp:KVM/Managing|български| [[::KVM/Managing/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/br | • {{#if: UbuntuHelp:KVM/Managing|brezhoneg| [[::KVM/Managing/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ca | • {{#if: UbuntuHelp:KVM/Managing|català| [[::KVM/Managing/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/cs | • {{#if: UbuntuHelp:KVM/Managing|čeština| [[::KVM/Managing/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/de | • {{#if: UbuntuHelp:KVM/Managing|Deutsch| [[::KVM/Managing/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/el | • {{#if: UbuntuHelp:KVM/Managing|Ελληνικά| [[::KVM/Managing/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/es | • {{#if: UbuntuHelp:KVM/Managing|español| [[::KVM/Managing/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/fa | • {{#if: UbuntuHelp:KVM/Managing|فارسی| [[::KVM/Managing/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/fi | • {{#if: UbuntuHelp:KVM/Managing|suomi| [[::KVM/Managing/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/fr | • {{#if: UbuntuHelp:KVM/Managing|français| [[::KVM/Managing/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/gu | • {{#if: UbuntuHelp:KVM/Managing|ગુજરાતી| [[::KVM/Managing/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/he | • {{#if: UbuntuHelp:KVM/Managing|עברית| [[::KVM/Managing/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/hu | • {{#if: UbuntuHelp:KVM/Managing|magyar| [[::KVM/Managing/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/id | • {{#if: UbuntuHelp:KVM/Managing|Bahasa Indonesia| [[::KVM/Managing/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/it | • {{#if: UbuntuHelp:KVM/Managing|italiano| [[::KVM/Managing/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ja | • {{#if: UbuntuHelp:KVM/Managing|日本語| [[::KVM/Managing/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ko | • {{#if: UbuntuHelp:KVM/Managing|한국어| [[::KVM/Managing/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ksh | • {{#if: UbuntuHelp:KVM/Managing|Ripoarisch| [[::KVM/Managing/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/mr | • {{#if: UbuntuHelp:KVM/Managing|मराठी| [[::KVM/Managing/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ms | • {{#if: UbuntuHelp:KVM/Managing|Bahasa Melayu| [[::KVM/Managing/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/nl | • {{#if: UbuntuHelp:KVM/Managing|Nederlands| [[::KVM/Managing/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/no | • {{#if: UbuntuHelp:KVM/Managing|norsk| [[::KVM/Managing/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/oc | • {{#if: UbuntuHelp:KVM/Managing|occitan| [[::KVM/Managing/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/pl | • {{#if: UbuntuHelp:KVM/Managing|polski| [[::KVM/Managing/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/pt | • {{#if: UbuntuHelp:KVM/Managing|português| [[::KVM/Managing/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ro | • {{#if: UbuntuHelp:KVM/Managing|română| [[::KVM/Managing/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/ru | • {{#if: UbuntuHelp:KVM/Managing|русский| [[::KVM/Managing/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/si | • {{#if: UbuntuHelp:KVM/Managing|සිංහල| [[::KVM/Managing/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/sq | • {{#if: UbuntuHelp:KVM/Managing|shqip| [[::KVM/Managing/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/sr | • {{#if: UbuntuHelp:KVM/Managing|српски / srpski| [[::KVM/Managing/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/sv | • {{#if: UbuntuHelp:KVM/Managing|svenska| [[::KVM/Managing/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/th | • {{#if: UbuntuHelp:KVM/Managing|ไทย| [[::KVM/Managing/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/tr | • {{#if: UbuntuHelp:KVM/Managing|Türkçe| [[::KVM/Managing/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/vi | • {{#if: UbuntuHelp:KVM/Managing|Tiếng Việt| [[::KVM/Managing/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/yue | • {{#if: UbuntuHelp:KVM/Managing|粵語| [[::KVM/Managing/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/zh | • {{#if: UbuntuHelp:KVM/Managing|中文| [[::KVM/Managing/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/zh-hans | • {{#if: UbuntuHelp:KVM/Managing|中文(简体)| [[::KVM/Managing/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:KVM/Managing | UbuntuHelp:KVM/Managing | {{#if: | :}}KVM/Managing}}/zh-hant | • {{#if: UbuntuHelp:KVM/Managing|中文(繁體)| [[::KVM/Managing/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:KVM/Managing|:KVM/Managing|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :KVM/Managing/zh | | {{#ifexist: KVM/Managing/zh | | {{#ifeq: {{#titleparts:KVM/Managing|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:KVM/Managing|1|-1|}} | zh | | }}
- title KVM Guest Management
<<Include(KVM/Header)>>
Manage your virtual machines
From the shell
You can manage your VMs from the shell using 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:
$ 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
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:
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
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:
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
To be able to undefine a virtual machine, it needs to be shutdown first:
virsh # shutdown mirror Domain mirror is being shutdown
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:
virsh # destroy mirror Domain mirror destroyed
If you have made a change to the XML configuration file, you need to tell KVM to reload it before restarting the VM:
virsh # define /etc/libvirt/qemu/mirror.xml Domain mirror defined from /etc/libvirt/qemu/mirror.xml
Then, to restart the VM:
virsh # start mirror Domain mirror started
Suspend and resume a Virtual Machine
Virsh allows you to easily suspend and resume a virtual machine.
virsh # suspend mirror Domain mirror suspended virsh # resume mirror Domain mirror resumed
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 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:
- export (aka 'dump') the xml of the virtual machine you want to edit
- edit the xml
- import (aka 'define') the xml
For example, to edit the machine named 'foo' (you can get a list of your machines with 'virsh list --all'), do:
$ virsh dumpxml foo > /tmp/foo.xml (edit /tmp/foo.xml as needed) $ virsh define /tmp/foo.xml
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:
<domain type='kvm'> ... <vcpu>2</vcpu> ... </domain>
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:
<domain type='kvm'> ... <memory>262144</memory> <currentMemory>262144</currentMemory> ... </domain>
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:
<domain type='kvm'> ... <interface type='network'> ... <model type='e1000'/> </interface> ... </domain>
Now define the VM as above.
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)>>