User Tools

Site Tools


cloud:libvirt

libvirt

  • virsh
  • libvirtd
  • virt-install
  • virt-manager

Virsh

Storage pool and volume

create a file system directory storage pool

virsh # pool-create-as --name vm_pool --type dir --target <dir>
virsh # pool-list
 Name                 State      Autostart
-------------------------------------------
 default              active     yes      
 vm_pool              active     yes     
 
virsh # pool-info vm_pool
Name:           vm_pool
UUID:           9b092c41-3c54-4cd3-b569-e2b512340cbf
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       1.07 TiB
Allocation:     12.83 GiB
Available:      1.06 TiB
 
virsh # vol-list vm_pool
 Name                 Path                                   
------------------------------------------------------------------------------
 ovs143-v672_0.img    /u01/vm_pool/ovs143-v672_0.img          

Network

Create libvirt network

 # cat mynetwork.xml
<network>
  <name>mynetwork</name>
  <uuid>9252d9d4-f3ce-4814-8de3-adf8368671f7</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='mybr0' stp='on' delay='0'/>
  <mac address='52:54:00:f1:3e:cb'/>
  <ip address='192.168.0.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.0.2' end='192.168.0.254'/>
    </dhcp>
  </ip>
</network>
 
virsh # net-define mynetwork.xml
Network mynetwork defined from mynetwork.xml
 
virsh # net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 mynetwork            inactive   no            yes
 
virsh # net-start mynetwork
Network mynetwork started
 
virsh # net-autostart mynetwork
Network mynetwork marked as autostarted
 
virsh # net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 mynetwork            active     yes           yes
 
# brctl show
bridge name    bridge id        STP enabled    interfaces
mybr0        8000.525400f13ecb    yes        mybr0-nic
virbr0        8000.525400f13eca    yes        virbr0-nic

Bridge

virsh # iface-list
 Name                 State      MAC Address
---------------------------------------------------
 eno1                 active     00:10:e0:b3:b1:68
 eno2                 active     00:10:e0:b3:b1:69
 lo                   active     00:00:00:00:00:00
 
virsh # iface-bridge --no-stp eno2 br1
Created bridge br1 with attached device eno2
Bridge interface br1 started
virsh # iface-list
 Name                 State      MAC Address
---------------------------------------------------
 br1                  active     00:10:e0:b3:b1:69
 eno1                 active     00:10:e0:b3:b1:68
 lo                   active     00:00:00:00:00:00
 
# brctl show
bridge name    bridge id        STP enabled    interfaces
br1        8000.0010e0b3b169    no        eno2
virbr0        8000.5254004707ec    yes        virbr0-nic

Virtual machine

$ virsh define --fine /path/to/vm_pool/myvm.xml
cloud/libvirt.txt · Last modified: 2017/08/08 12:54 by frank