Libvirt command line document

Source: Internet
Author: User

Libvirt command line document
Libvirt has two control modes: Command Line and GUI Gui: Execute the name virt-manager to start the libvirt GUI. In the GUI, you can create and manage virtual machines step by step, you can also directly control the desktop of a virtual machine. Command Line: virsh list # display local active virtual machine virsh list-all # display all local virtual machines (Active + inactive) virsh define ubuntu. xml # define a virtual machine through the configuration file (this virtual machine is not active yet) virsh start ubuntu # start an inactive virtual machine named ubuntu virsh create ubuntu. xml # create a virtual machine (after creation, the virtual machine is executed immediately and becomes an active host) virsh suspend ubuntu # Pause the Virtual Machine virsh resume ubuntu # Start the paused Virtual Machine virsh shutdown ubuntu # Shut down the Virtual Machine virsh destroy ubuntu # force shut down the Virtual Machine virsh dominfo ubuntu # display the basic information of the Virtual Machine virsh domname 2 # display the Virtual Machine name virsh domid ubunt with ID 2 U # display Virtual Machine ID virsh domuuid ubuntu # display Virtual Machine uidvirsh domstate ubuntu # display the current state of the Virtual Machine virsh dumpxml ubuntu # display the current configuration file of the Virtual Machine (may be different from the configuration when defining the virtual machine), when a virtual machine is started, the virtual machine must be assigned an ID number, uuid, vnc port number, and so on) virsh setmem ubuntu 512000 # Set the memory size for the inactive Virtual Machine virsh setvcpus ubuntu 4 # set the number of CPUs for the inactive Virtual Machine virsh edit ubuntu # edit the configuration file (generally after the virtual machine is defined) libvirt also provides a shell: virsh. You can directly execute the name virsh to obtain a special shell: virsh. In this virsh, You can execute the preceding command (remove the previous virsh) to interact with the local libvirt, you can also use the command conn The ect command connects to the remote libvirt and interacts with it, for example, connect xen + ssh: // root@10.4.122.11. In addition, you can execute only one remote libvirt command: virsh-c xen + ssh: // root@10.4.122.11 list -- all ubuntu. xml configuration file example: <domain type = 'xen'> <name> ubuntu </name> <memory> 1048576 </memory> <currentMemory> 524288 </currentMemory> <vcpu> 2 </vcpu> <OS> <type> hvm </type> <loader>/usr/lib/xen/boot/hvmloader </loader> <boot dev = 'hd'/> </OS> <features> <acpi/> <apic/> <pae/> </features> <clock offset = 'utc'/> <on_poweroff> destroy </on_poweroff> <on_reboot> restart </on_reboot> <on_crash> restart </on_crash> <devices> <emulator>/usr/lib64/xen/bin/qemu-dm </emulator> <disk type =' file 'device = 'disk'> <driver name = 'file'/> <source file = '/opt/awcloud/ubuntu. img '/> <target dev = 'hda' bus = 'ide'/> </disk> <disk type = 'file' device = 'disk'> <driver name =' file '/> <source file ='/opt/awcloud/ubuntu/sdb. img '/> <target dev = 'hdb' bus = 'ide'/> </disk> <disk type = 'file' device = 'cdrom '> <driver name =' file '/> <source file ='/opt/awcloud/forest/ubuntu-10.04.3-desktop-i386.iso '/> <target dev = 'hdc' bus = 'ide '/> <readonly/> </ disk> <serial type = 'PTY'> <target port = '0'/> </serial> <console type = 'PTY'> <target port = '0'/> </console> <interface type = 'bridge '> <mac address = '00: 16: 36: 1e: 1d: 04 '/> <source bridge = 'virbr0'/> </interface> <graphics type = 'vnc' autoport = 'yes' keymap = 'en-us'/> </ devices> </domain> note: generate an empty 4G file: dd if =/dev/zero of =. /disk bs = 1024 count = 'expr 4 \ * 1024 \ * 100' modify the Startup Device of the VM: <boot dev = 'hd'/> Start from the hard disk; <boot dev = 'cdrom '/> enable network parameters from CD, for example, ubuntu. in the xml configuration file, both the kvm Virtual Machine and the xen Virtual Machine only need to be configured according to the following template. the MAC address is required, and the bridage name may be different on different hosts, it may be virbr0 or br0, but the type must be in bridge Mode. <interface type = 'bridge '> <mac address = '00: 16: 36: 1e: 1d: 04 '/> <source bridge = 'virbr0'/> </interface> kvm vm migration: Migration command: virsh migrate-live <id or name> qemu + ssh: // <dstip>/system tcp: // <dstip>: After the migration of 49152, the local machine may still be in the defined status. Run virsh undefine <name> to clear
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.