Presentation is loading. Please wait.

Presentation is loading. Please wait.

KVM tutorial #3 Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010.

Similar presentations


Presentation on theme: "KVM tutorial #3 Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010."— Presentation transcript:

1 KVM tutorial #3 Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010

2 qemu-kvm QEMU is a generic and open source machine emulator and virtualizer. When used as a machine emulator, QEMU can run OSes and programs made for one machine (e.g. an ARM board) on a different machine (e.g. your own PC). By using dynamic translation, it achieves very good performance. When used as a virtualizer, QEMU achieves near native performances by executing the guest code directly on the host CPU. QEMU supports virtualization when using the KVM kernel module in Linux. qemu-kvm is the variant used by KVM Andrea Chierici2

3 qemu-kvm with command line It’s possible to use KVM without libvirt wrappers, with bare command line  virsh and virt-manager have no knowledge of VMs created this way  Can be useful in some testing environments See man qemu-kvm for reference qemu-kvm -hda /virtual/test_disk -net nic,model=e1000,macaddr=00:16:3e:00:00:2 a -net tap -m 1024 -vnc :4 Andrea Chierici3

4 qemu-kvm options Invocation:  usage: qemu [options] [disk_image] Some options: -hda file -cdrom file -smp n -vnc address:port -snapshot: write to temporary files instead of disk image files. In this case, the raw disk image you use is not written back. You can however force the write back by pressing Andrea Chierici4

5 qemu monitor The QEMU monitor is used to give complex commands to the QEMU emulator. You can use it to:  Remove or insert removable media images (such as CD-ROM or floppies).  Freeze/unfreeze the Virtual Machine (VM) and save or restore its state from a disk file.  Inspect the VM state without an external debugger.  Perform migration between hosts  Can be accessed with CTRL+ALT+2 Andrea Chierici5

6 qemu TAP: qemu-ifup -net tap: QEMU adds a virtual network device on your host (called tapN), and you can then configure it as if it was a real ethernet card. A script is required to create a bridged net connection: /etc/qemu-ifup #!/bin/sh switch=$(/sbin/ip route list | awk '/^default / { print $NF }') /sbin/ifconfig $1 0.0.0.0 up /usr/sbin/brctl addif ${switch} $1 Andrea Chierici6

7 Using qemu-img The qemu-img command line tool is used for formatting various file systems used by KVM. qemu-img should be used for formatting virtualized guest images, additional storage devices and network storage Formatting and creating new images or devices # qemu-img create [-6] [-e] [-b base_image] [-f format] filename [size] Andrea Chierici7

8 Qemu-img: supported formats Raw: Raw disk image format (default). This format has the advantage of being simple and easily exportable to all other emulators. If your file system supports holes (for example in ext2 or ext3 on Linux or NTFS on Windows), then only the written sectors will reserve space. Use qemu-img info to know the real size used by the image or ls -ls on Unix/Linux. Qcow2: QEMU image format, the most versatile format. Use it to have smaller images (useful if your file system does not supports holes, for example: on Windows), optional AES encryption, zlib based compression and support of multiple VM snapshots. Qcow: Old QEMU image format. Only included for compatibility with older versions. Cow: User Mode Linux Copy On Write image format. The cow format is included only for compatibility with previous versions. It does not work with Windows. Vmdk: VMware 3 and 4 compatible image format. Cloop: Linux Compressed Loop image, useful only to reuse directly compressed CD-ROM images present for example in the Knoppix CD- ROMs. Andrea Chierici8

9 Qemu-img examples Convert an existing image to another format # qemu-img convert [-c] [-e] [-f format] filename [-O output_format] output_filename  Image conversion is also useful to get smaller image when using a format which can grow, such as qcow or cow. The empty sectors are detected and suppressed from the destination image. getting image information  the info parameter displays information about a disk image. The format for the info option is as follows: # qemu-img info [-f format] filename Andrea Chierici9

10 Snapshot option With snapshot option it’s possible to “clone” several nodes starting from a single image  Configure the node with DHCP network  Remove all references to mac address  Use command line with --snapshot and different mac addresses for ((i=1;i<=$1;i++)) do /usr/libexec/qemu-kvm -m 2048 -smp 1 -name wn-test$i \ -boot c -drive file=/virtual/test.img,if=virtio,index=0,boot=on \ -net nic,macaddr=54:52:00:4f:02:3$i,vlan=0,model=virtio -net tap \ -vnc 127.0.0.1:$i -k en-us -snapshot & sleep 2 done Andrea Chierici10

11 Libvirt: low level cloning and VM management Libvirt stores by default xml profiles of VMs under /etc/libvirt/qemu/ virsh edit, without path  Manually editing xml profiles is not recommended vi /etc/libvirt/qemu/wn-test.xml  cp wn-test.xml wn-test2.xml  virsh define wn-test-2.xml, after customizations Consider copying disk image file Virsh dumpxml… Andrea Chierici11

12 Optimizations: swap KVM virtualized guests function as Linux processes. Linux processes are not permanently kept in main memory (physical RAM). The kernel scheduler swaps process memory into virtual memory (swap).  Swap, with conventional hard disk drives, is thousands of times slower than main memory in modern computers.  If a guest is inactive for long periods of time, the guest may be placed into swap by the kernel. Swap usage can be completely turned off to prevent guests from being unresponsive while they are moved back to main memory. This may improve performance but will expose the system to certain risks.  The swapoff command can disable all swap partitions and swap files on a system. Andrea Chierici12

13 Optimizations: smartd SMART disk monitoring can be safely disabled as virtual disks and the physical storage devices are managed by the host. # service smartd stop # chkconfig --del smartd Andrea Chierici13

14 Optimizations: shutdown (rhel6) Without the acpid package, the guest does not shut down when the virsh shutdown command is executed.  The virsh shutdown command is designed to gracefully shut down virtualized guests.  Install the acpid package # yum install acpid  Enable the acpid service # chkconfig acpid on # service acpid start Andrea Chierici14

15 Serial console Fully virtualized guest serial console output can be viewed with the virsh console command. The serial port is called ttyS0 on Linux or COM1 on Windows.  You must configure the virtualized operating system to output information to the virtual serial port. To output kernel information from a fully virtualized Linux guest into the domain modify the /boot/grub/grub.conf file by appending to kernel line: console=ttyS0,115200. Andrea Chierici15


Download ppt "KVM tutorial #3 Andrea Chierici Virtualization tutorial Catania 1-3 dicember 2010."

Similar presentations


Ads by Google