virsh使用

  1. 查看运行虚拟机列表
root@zh-450R5G-450R5U:~# virsh list
 Id    Name                           State
----------------------------------------------------

  1. 启动虚拟机
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh define ubuntu16.xml 
Domain ubuntu16 defined from ubuntu16.xml

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh start ubuntu16
Domain ubuntu16 started

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh list
 Id    Name                           State
----------------------------------------------------
 1     ubuntu16                       running

  1. 启动virt-manager 从 界面运行
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virt-manager 
root@zh-450R5G-450R5U:~/kvm/ubuntu16#

virsh使用_第1张图片
4 .查看虚拟机网络接口

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-info default
Name:           default
UUID:           9640e85f-15a6-4b96-aad8-d378f4f2a88d
Active:         yes
Persistent:     yes
Autostart:      yes
Bridge:         virbr0

root@zh-450R5G-450R5U:~/kvm/ubuntu16# brctl show virbr0
bridge name	bridge id		STP enabled	interfaces
virbr0		8000.5254007a4536	yes		virbr0-nic
							vnet0

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-dumpxml default
<network>
  <name>default</name>
  <uuid>9640e85f-15a6-4b96-aad8-d378f4f2a88d</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:7a:45:36'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

  1. 添加网卡设备
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-dumpxml default > net-default.xml
root@zh-450R5G-450R5U:~/kvm/ubuntu16# ls
net-default.xml  ubuntu16_kvm.qcow2  ubuntu16.xml

root@zh-450R5G-450R5U:~/kvm/ubuntu16# cp net-default.xml net-new.xml
root@zh-450R5G-450R5U:~/kvm/ubuntu16# ls
net-default.xml  net-new.xml  ubuntu16_kvm.qcow2  ubuntu16.xml

编辑修改
vi net-new.xml
{
xxx
}

root@zh-450R5G-450R5U:~/kvm/ubuntu16# cat net-new.xml 
<network>
  <name>net-new</name>
  <uuid>9640e85f-15a6-4b96-aad8-d378f4f2a88f</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr1' stp='on' delay='0'/>
  <mac address='52:54:00:7a:45:37'/>
  <ip address='192.168.123.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.123.2' end='192.168.123.254'/>
    </dhcp>
  </ip>
</network>

root@zh-450R5G-450R5U:~/kvm/ubuntu16# 
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-define net-new.xml 
Network net-new defined from net-new.xml

root@zh-450R5G-450R5U:~/kvm/ubuntu16# 
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-autostart net-new
Network net-new marked as autostarted

root@zh-450R5G-450R5U:~/kvm/ubuntu16# 
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-start net-new
Network net-new started

root@zh-450R5G-450R5U:~/kvm/ubuntu16# 
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 net-new              active     yes           yes

root@zh-450R5G-450R5U:~/kvm/ubuntu16# 
  1. 关闭虚拟机
root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh list
 Id    Name                           State
----------------------------------------------------
 1     ubuntu16                       running

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh destroy 1
Domain 1 destroyed

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh list
 Id    Name                           State
----------------------------------------------------

动态添加设备

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh list
 Id    Name                           State
----------------------------------------------------
 4     ubuntu16.04                    running

root@zh-450R5G-450R5U:~/kvm/ubuntu16# cat disk.xml 
<disk type='block' device='disk'>
	<source dev='/dev/sda7'/>
	<target dev='vdd' bus='virtio'/>
</disk>

root@zh-450R5G-450R5U:~/kvm/ubuntu16# virsh attach-device ubuntu16.04-config --live
Device attached successfully


你可能感兴趣的:(Ubuntu18使用,linux,命令)