ubuntu virtualization virt command

View all created virtual machines
virsh list --all

boot
virsh start win7

shutdown
virsh shutdown win7

power off
virsh destroy win7


quote

3. Install the guest virtual machine

1. Install and manage the virtual machine directly through virt-manager (omitted)

2. Install the guest virtual machine through the command line
[root@target ~]# yum install virt-viewer #Open the graphical console to install the virtual guest machine needs,
[root@target ~]# virt-install \ #installation options can be viewed with virt-install --help
--name node4 \ #virtual machine name
--ram=1024 \ #allocated memory size, MB
--arch= x86_64 \ #Simulated CPU architecture
--vcpus=1 \ #Configure the number of vcpus for the virtual machine
--check-cpu \ #Check to see if the number of vcpus exceeds the number of physical CPUs, and if so, a warning will be issued.
--os-type=linux \ #The type of operating system to install, for example: 'linux', 'unix', 'windows'
--os-variant=rhel5 \ #The operating system version, such as: 'Fedora6', 'rhel5 ', 'solaris10', 'win2k'
--disk path=/virhost/node7.img,device=disk,bus=virtio,size=20,
--bridge=br0 \ #Specify the network, use a transparent bridge
--noautoconsole \ #Do not automatically open the console
--pxe #Network installation

4. Use virsh to manage virtual machines
1. Power on and off
[root@target ~]# virsh start node4 #Startup
[root@target ~]# virsh create /etc/libvirt/qemu/node4.xml #Start the host directly through the host configuration document
[root@target ~]# virsh shutdown node4 #Shutdown
[root@target ~]# virsh destroy node4 #Force power off
[root@target ~]# virsh list --all #View virtual machine status        
Id Name Status
----------------------- -----------
18 node4 running
  - node5 shutdown
  - win8 shutdown


2. Add and delete virtual machines
[root@target ~]# virsh define /etc/libvirt/qemu/node5.xml #Add a virtual machine according to the host configuration document
[root@target ~]# virsh list --all #node5 has added
Id Name Status
---- ------------------------------
18 node4 running
  - node5 shutdown
  - win8 shutdown

[root@target ~]# virsh undefine node5 # Remove virtual machine
[root@target ~]# ls /etc/libvirt/qemu
networks node4.xml win8.xml
[root@target ~]# virsh list --all #node5 has been removed
Id Name Status
---- ------------------------------
18 node4 running
  - win8 close


3. Remote management virtual machine (qemu+ssh connection)
[root@target ~]# yum install virt-viewer
[root@target ~]# export DISPLAY=192.168.40.18:0.0
[root@target ~]# virt-viewer -c qemu///system node4 #Local management virtual machine , system: get system permissions, note that there are three after qemu /
[root@manager ~]# virt-viewer -c qemu+ssh://[email protected]/system node4 #remote linux is managed by virt-viewer+ssh Virtual machine
Xlib: extension "RANDR" missing on display "192.168.40.18:0.0".
[email protected]'s password:
[email protected]'s password:
#The gtk management interface of virt-viewer will pop up


4. Use Install a new virtual machine from an existing virtual machine configuration file
[root@target ~]# qemu-img create -f qcow2 /virhost/kvm_node/node6.img 20G #Create
a disk image file for the new virtual machine


[root@target ~] # virsh list
Id Name Status
----------------------------------
18 node4 running


[root@target ~]# virsh dumpxml node4 >/etc /libvirt/qemu/node6.xml
#Export the hardware configuration information of virtual machine node6 as /etc/libvirt/qemu/node6.xml


[root@target ~]# vim /etc/libvirt/qemu/node6.xml
<domain type= 'kvm' id='20'> #Modify the id number of
  node6 <name>node6</name> #Name of virtual machine node6
  <uuid>4b7e91eb-6521-c2c6-cc64-c1ba72707fc7</uuid> #uuid must be modified, Otherwise it will conflict with node4
  <memory>524288</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>1< /vcpu>
  <os>
    <type arch='x86_64' machine='rhel5.4.0'>hvm< /type>
    < boot dev='network'/>
  </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/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/virhost/node4.img'/>         #指定新虚拟机的硬盘文件
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <mac address='54:52:00:69:d5:c7'/>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
    </interface>
    <interface type='bridge'>
      <mac address='54:52:00:69:d5:d7'/>
      <source bridge='br0'/>
      <target dev='vnet1'/>
      <model type='virtio'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/4'>
      <source path='/dev/pts/4'/>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5900' autoport='yes' keymap='en-us'/>
  </devices>
</domain>

[root@target ~]# virsh define /etc/libvirt/qemu/node6.xml #Use
the virtual description document to create a virtual machine, you can use virsh edit node6 to modify the configuration file of node6

[root@target ~]# virsh start node6 #Start
the virtual machine

5 Open vnc for the virtual machine
[root@target ~]# virsh edit node4 #Edit the configuration file of node4; it is not recommended to modify it directly through vim node4.xml.
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
   #port='-1' autoport='yes': port is automatically assigned , listen to the loopback network (virt-manager management requires listen='127.0.0.1'), no password is
changed to
<graphics type='vnc' port='5904' autoport='no' listen='0.0.0.0' keymap=' en-us' passwd='xiaobai'/> #fixed
   vnc management port 5904, not automatically assigned, vnc password xiaobai, monitor all networks

2.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326551579&siteId=291194637