Introduction to Virtualization, Virsh and Virt-Manager

Post on 25-Jan-2015

510 views 14 download

description

 

Transcript of Introduction to Virtualization, Virsh and Virt-Manager

Introduction to Virtualization, Virsh Commands and Virt-Manager

Chin Pin Chang

04/07/2014

1

Outline• Virtualization

– Introduction– Types of Virtualization – KVM– Practice: KVM Installation

• Virsh Commands– Introduction– Practice: 3 Units

• Virt-Manager • Conclusion• References

2

3

Virtualization Introduction

• Virtualization is a broad term that refers to the abstraction of computer physical resources such as servers, network, memory and storage

4

Virtualization Introduction (cont.)

• Without Virtualization • With Virtualization

5

Why Virtualization• Resource sharing• High utilization of resource• Reduce the number of physical servers• Ability to bring up new server quickly• Easy maintenance and monitoring

6

Types of Virtualization• Server Virtualization

– Full virtualization, Paravirtualization, Hardware-assisted virtualization

• Application Virtualization• Desktop Virtualization• Presentation Virtualization• Network Virtualization• Storage Virtualization

7

KVM Introduction• KVM (Kernel-based Virtual Machine)

– A Linux kernel module that turns Linux into a hypervisor– Full virtualization

8

Install KVM

• Check that your CPU supports hardware virtualization

– 0 indicates that your CPU doesn’t support hardware virtualization

– 1 or more indicates that it supports hardware virtualization

9

Install KVM (cont.)

• Check BIOS– Support

– Not support

10

Install KVM (cont.)

• Install necessary packages– qemu-kvm– libvirt-bin – ubuntu-vm-builder – bridge-utils

11

Add Users to Libvirtd and KVM Groups

• Add user "username" to libvirtd

• Add user " username" to KVM

• Need to re-login

12

Verify Installation

• Check groups

• Verify Installation

• Change the device's group

13

Install Virt-manager

• Install virt-manager

• Start virt-manager

14

Step 1 - Create new virtual machine

15

Step 2 – Locate install media

16

Step 3 – Specify CPU and Memory

17

Step 4 – Specify Storage

18

Step 5 – Specify Network

19

Install Ubuntu Server

20

Virsh Introduction

• Virsh is a command line interface tool for managing VM and the hypervisor

21

Virsh Introduction (cont.)

• Virsh Commands Classification– Domain management commands – Domain monitoring commands– Host and hypervisor commands– Interface commands– Network filter commands– Virtual networking commands– Node device commands– Secrets commands– Domain snapshot commands– Storage pool commands– Storage volume commands– Virsh commands

22

Virsh Commands

Unit 1Domain Management

23

Introduction

• Domain management– Is used to manage VM– Major commands: define, start, destroy, suspend,

resume and so on

How to use virsh

24

define

Item Content

Description Define, but don't start, a guest domain from an XML file

Input 1. XML file

Example # define vm1.xml

Response Domain vm1 defined from vm1.xml

25

Define a VM

26

XML for VM

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> <name>vm1</name> <uuid>b7cb10e2-c6af-a328-ad75-3e09747f0564</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu> <os> <type arch='armv7l' machine='vexpress-a15'>hvm</type> <kernel>/root/zImage</kernel> <cmdline>earlyprintk=ttyAMA0 console=ttyAMA0 mem=512M root=/dev/vda rw ip=192.168.20.56::192.168.20.101:vm1:eth0:off --no-log</cmdline> <dtb>/root/guest-vexpress.dtb</dtb> </os> <features> <acpi/> <pae/> </features><!-- <cpu> <model>cortex-a15</model> </cpu> -->

27

XML for VM (cont.)

<clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-arm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/root/nfs/ubuntu1G.img'/> <target dev='vda' bus='virtio'/> </disk> <interface type='bridge'> <source bridge='virbr0'/> <mac address='52:54:00:12:34:55'/> <model type='virtio'/> </interface> <console type='pty'/> </devices></domain>

28

XML parameters

• name– Virtual machine name

• uuid– A globally unique identifier for the virtual machine

• current memory– The actual allocation of memory for the VM

• type– The type of operating system in the virtual machine

• kernel– The fully-qualified path to the kernel image in the host OS

29

XML parameters (cont.)

• cmdline– The arguments to be passed to the kernel at boot time

• dtb– The fully-qualified path to the device tree binary image in

the host OS• emulator

– The fully qualified path to the device model emulator binary• disk

– The main container for describing disks• source file

– The resource on the host that is being accessed in the guest

30

XML parameters (cont.)

• target– The source can be accessed in the guest

• interface type– A network interface visible to the guest

• source bridge– The interface of the network

• mac address– The address of the network

• model type– The model of emulated network interface

31

start

Item Content

Description Start a guest domain, either from the last managed save state, or via a fresh boot if no managed save state is present

Input 1.domain

Example # start vm1

Response Domain vm1 started

32

Start VM

33

domid

Item Content

Description Convert a domain name or UUID to domain id

Input 1. domain

Example # domid vm1

Response 1

34

domname

Item Content

Description Convert a guest domain id or UUID to guest domain name

Input 1. domain

Example # domname 1

Response vm1

35

domuuid

Item Content

Description Convert a guest domain name or id to guest domain UUID

Input 1. domain

Example # domuuid vm1

Response b7cb10e2-c6af-a328-ad75-3e09747f0564

36

VM Information

• The domain ID

• The domain name

• The domain uuid

37

autostart

Item Content

Description Enable and disable the automatic starting of a guest domain when the libvirt daemon starts

Input 1. domain

Example # autostart vm1

Response Domain vm1 marked as autostarted

38

Auto start VM

39

list

Item Content

Description Returns a list of guest domains

Input N/A

Example # list

Response virsh # list Id Name State ---------------------------------------------------- 1 vm1 running

40

List VM

41

console

Item Content

Description Connect the virtual serial console for the guest

Input 1. domain

Example # console vm1

Response Connected to domain vm1 Escape character is ^]

42

Connect to VM

43

Connect to VM (cont.)

44

• Launch Apache service

• Check Apache service

Connect to VM (cont.)

• Check the IP of the VM

45

Connect to VM (cont.)

• Check /var/www/index.html

• Web page

46

suspend

Item Content

Description Suspend a running guest domain

Input 1.domain

Example # suspend vm1

Response Domain vm1 suspended

47

Suspend VM

• Web page

48

resume

Item Content

Description Resume a guest domain

Input 1.domain

Example # resume vm1

Response Domain vm1 resumed

49

Resume VM

• Web page

50

save

Item Content

Description Save the running state of a guest domain to a file

Input 1.domain 2.file

Example # save vm1 image

Response Domain vm1 saved to image

51

restore

Item Content

Description Restore a guest domain

Input 1.file

Example # restore image

Response Domain restored from image

52

53

Save and Restore scenario

S0

Save the VM

Restore the VM

Start the VM

Modify index.htm

S0S2S1

Step 4Step 3Step 2Step 1

Step 1

• Save the VM

• The saved file

54

Step 2 and 3

• Start the VM• Modify /var/www/index.html

• Web page

55

Step 4

• Restore the VM

• Web page

56

destroy

Item Content

Description Immediately terminates a running guest domain, releasing any resources in use by it

Input 1.domain

Example # destroy vm1

Response Domain vm1 destroyed

57

Destroy VM

58

The memory information of the host

• Before destroying the VM

• After destroying the VM

59

undefine

Item Content

Description Remove the configuration for an inactive guest domain

Input 1.domain

Example # undefine vm1

Response Domain vm1 has been undefined

60

Undefine VM

61

62

Virsh Commands

Unit 2Interface Management and

Network Management

63

Introduction

• Interface management– To create an interface on the host for VM

64

iface-define

Item Content

Description Define a physical host network interface

Input 1. XML file

Example # iface-define br1.xml

Response Interface br1 defined from br1.xml

65

Define an interface

• Interface br1

66

XML for Interface<interface type='bridge' name='br1'> <start mode='onboot'/> <bridge> <interface type='vlan' name='bond0.1'> <vlan tag='1'> <interface name='bond1'/> </vlan> </interface> </bridge> </interface>

XML parameters

• interface type– Network interface type

• interface name– The name of interface

• bridge type – The type of bridge

• vlan tag– Use to tag of the vlan

67

68

iface-start

Item Content

Description Enables and starts a physical host network interface

Input 1. interface

Example # iface-start br1

Response Interface br1 started

69

Start interface

70

iface-name

Item Content

Description Returns the physical host interface name for a MAC address

Input 1. interface(MAC address)

Example # iface-name 3a:a0:42:19:ca:b2

Response br1

71

iface-mac

Item Content

Description Returns the MAC address for a physical host network interface

Input 1. interface

Example # iface-mac br1

Response 3a:a0:42:19:ca:b2

72

Interface Information

• The interface name

• The interface mac

73

iface-destroy

Item Content

Description Shut down and disable a physical host network interface

Input 1. interface

Example # iface-destroy br1

Response Interface br1 destroyed

74

Destroy interface

75

iface-undefine

Item Content

Description Removes the configuration information for a physical host network interface

Input 1. interface

Example # iface-undefine br1

Response Interface br1 undefined

76

Undefine interface

77

Introduction

• Network management– Libvirt has the capability to define virtual networks

which can then be used by domains and linked to actual network devices

78

net-define

Item Content

Description Adds a new permanent virtual network from an XML file, without starting it

Input 1. file

Example # net-define vlan1.xml

Response Network vlan1 defined from vlan1.xml

79

Define network

• Network vlan1

80

XML for Network<network > <name>vlan1</name> <forward mode='bridge'/> <bridge name='br1' /></network>

XML parameters

• name– Virtual network name

• forward mode– Inclusion of the forward element indicates that the virtual

network is to be connected to the physical LAN

• bridge name– The name of a bridge device

81

82

net-start

Item Content

Description Starts a (previously defined) inactive virtual network

Input 1. network

Example # net-start vlan1

Response Network vlan1 started

83

Start network

84

net-autostart

Item Content

Description Enable or disable the automatic starting of a virtual network, when the libvirt daemon starts

Input 1. network

Example # net-autostart vlan1

Response Network vlan1 marked as autostarted

85

Auto start network

86

net-infoItem Content

Description Displays basic information for a virtual network

Input 1. network

Example # net-info vlan1

Response

Name vlan1 UUID f1f1cd7e-b623-4d7e-94c8-2047da1decef Active: yes Persistent: yes Autostart: yes Bridge: br1

87

Network Information

88

net-name

Item Content

Description When given a network UUID, returns its corresponding network name

Input 1. network

Example # net-name f1f1cd7e-b623-4d7e-94c8-2047da1decef

Response vlan1

89

net-uuid

Item Content

Description When given a network name, returns its corresponding UUID

Input 1. network

Example # net-uuid vlan1

Response f1f1cd7e-b623-4d7e-94c8-2047da1decef

90

Network Information

• The network name

• The network uuid

91

net-destroy

Item Content

Description Shuts down a running virtual network

Input 1. network

Example # net-destroy vlan1

Response Network vlan1 destroyed

92

Destroy network

93

net-undefine

Item Content

Description Removes an inactive virtual network from the libvirt configuration

Input 1. network

Example # net-undefine vlan1

Response Network vlan1 has been undefined

94

Undefine network

95

Interface and Network scenario

Hostvirbr0

br1 br2

VM1 VM2 VM3

IP: 192.168.1.101 192.168.1.102 192.168.1.103

vlan1

vlan2

96

Example

• Define the interfaces br1 and br2

97

XML for host

• br1.xml<interface type='bridge' name='br1'> <start mode='onboot'/> <bridge> <interface type='vlan' name='bond0.1'> <vlan tag='1'> <interface name='bond1'/> </vlan> </interface> </bridge> </interface>

98

XML for host (cont.)

• br2.xml<interface type='bridge' name='br2'> <start mode='onboot'/> <bridge> <interface type='vlan' name='bond0.2'> <vlan tag=‘2'> <interface name='bond2'/> </vlan> </interface> </bridge> </interface>

99

XML for VM• Modify VM1.xml

• Modify VM2.xml

• Modify VM3.xml

100

Define VM

• Define VM1, VM2 and VM3

101

Start VM

• Start VM1, VM2 and VM3

102

Start interface

• Start interface br1 and br2

103

Connect to VM

• Assign IP (192.168.0.101) to VM1

104

Connect to VM (cont.)

• Assign IP (192.168.0.102) to VM2

105

Connect to VM (cont.)

• Assign IP (192.168.0.103) to VM3

106

Result

• VM1 ping VM2

• VM1 ping VM3

107

Result (cont.)

• VM3 ping VM1

• VM3 ping VM2

108

Virsh Commands

Unit 3Snapshot and Migrate

109

Introduction

• Snapshot– Snapshots take the disk, memory, and device state

of a VM at a point-of-time, and save it for future use

• --disk-only– The snapshot will only include disk state

110

Snapshot scenario

Create a folder and

modify index.htm

Start the VM

Restart the VM

Revert the

snapshot

Step 4Step 3Step 2Step 1

S0 S3S2S1 S1

Step 5

111

snapshot-create

Item Content

Description Create a snapshot (disk and RAM) from XML

Input 1. domain 2. xml

Example # snapshot-create vm1 snaptest.xml

Response Domain snapshot snaptest created from 'snaptest.xml'

112

• Start VM• Take a snapshot

Create a snapshot for VM

113

Create a folder in VM

• Start VM• Create a folder "test"

Launch Apache service

• Check /var/www/index.html

• Web page

114

Launch Apache service (cont.)

• Modify the /var/www/index.html

• Web page

115

116

snapshot-revert

Item Content

Description Reverts a domain to a given snapshot

Input 1. domain 2. snapshotname

Example # snapshot-revert vm1 snaptest

Response N/A

117

Revert snapshot

• Folder

• Web page

118

snapshot-delete

Item Content

Description Removes a snapshot, and all of it's children, from a domain

Input 1. domain 2. snapshotname

Example # snapshot-delete --domain vm1 snaptest --metadata

Response Domain snapshot snaptest deleted

119

Delete snapshot

120

Introduction

• Migrate– Migration is the process of moving a virtual

machine from one host or storage location to another

121

Migration

Source

VMDownload

a file

Destination

VMDownload

a file

Migration

Network

IP: 192.92.26.120 IP: 192.92.26.108

NFS/Data/image

VMimage

122

Set up NFS server for images

• Install NFS server packages – nfs-common– nfs-kernel-server

• Set shared path and permission

123

Set up NFS server for images (cont.)

• Start NFS server

• Check NFS path

124

Set up NFS client – hypervisor

• Install NFS client packages – nfs-common

• Mount image

• Check

125

Set up NFS client – hypervisor (cont.)

• Restart NFS server

• Check image on client

126

migrate

Item Content

Description Migrates a guest domain to another host

Input 1.domain 2.dest uri

Example # migrate vm1 qemu+ssh://140.92.26.108/system

Response pass

127

Start VM

128

Download a file to VM

129

Migrate VM to destination host

• Source host

The URI of the destination host

130

After migration

• Destination host

131

Verify the file

• The file size

132

Virt-manager Introduction• The virt-manager (Virtual Machine Manager)

application is a graphic user interface for managing virtual machines through libvirt

133

Main window

134

Connection window

Define VM

135

Start VM

136

Connect to VM

137

Verify connection

138

• Virt-manager

Suspend VM

139

Resume VM

140

Save VM

141

Save VM (cont.)

142

Restore VM

143

Clone VM

144

Check CPU usage of VM

145

Destroy VM

146

Delete VM

147

148

Conclusion

• Virtualization– High utilization of physical resource

• Virsh – The main interface for managing virtualization

environment through Libvirt• Virt-manager

– Graphic user interface for managing virtualization environment through Libvirt

149

Question

• Mail:walkerchang@iii.org.tw

150

References• http://libvirt.org/• http://en.wikipedia.org/wiki/Virtualization• http://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine • http://www.slideshare.net/trupti242/virtuallization-

questions#• https://access.redhat.com/site/documentation/en-US/

Red_Hat_Enterprise_Linux/• http://trac.nchc.org.tw/cloud• https://help.ubuntu.com/community/KVM/Installation• http://www.ubuntu-tw.org/modules/tinyd0/