KVM Virtualization in RHEL 6 Made Easy A Dell Technical White Paper Jose De la Rosa Dell Linux Engineering
Dell Inc. 2 KVM Virtualization in RHEL 6 Made Easy THIS WHITE PAPER IS FOR INFORMATIONAL PURPOSES ONLY, AND MAY CONTAIN TYPOGRAPHICAL ERRORS AND TECHNICAL INACCURACIES. THE CONTENT IS PROVIDED AS IS, WITHOUT EXPRESS OR IMPLIED WARRANTIES OF ANY KIND. © 2011 Dell Inc. All rights reserved. Reproduction of this material in any manner whatsoever without the express written permission of Dell Inc. is strictly forbidden. For more information, contact Dell.
Dell Inc. 3 KVM Virtualization in RHEL 6 Made Easy Contents 1. Introduction......................................................................................................................................... 4 1.1 Purpose of this document .............................................................................................................. 4 1.2 A very brief overview of KVM ........................................................................................................ 4 1.
Dell Inc. 4 KVM Virtualization in RHEL 6 Made Easy 1. Introduction 1.1 Purpose of this document This document describes how to quickly setup and manage a virtualized environment with KVM (Kernelbased Virtual Machine) in Red Hat Enterprise Linux 6 on a Dell PowerEdge server. This is not an indepth discussion of virtualization or KVM, but rather an easy-to-follow step-by-step description of how to install and manage Virtual Machines (VMs) on a physical server.
Dell Inc. 5 KVM Virtualization in RHEL 6 Made Easy 2. Preparing your environment 2.1 Hardware You don‟t need a top-of-the-line PowerEdge server, a 2-socket server (with 4-6 cores each), 8-16 GB of memory and 100 GB disk space is sufficient for 4 to 8 VMs, but of course it will depend on your needs. In my lab I have a PowerEdge T610 with 2 Intel Xeon 4-core 5520 processors, 16 GB of memory and about 160GB disk space and I can easily run 8-10 RHEL VMs without a sweat.
Dell Inc. 6 KVM Virtualization in RHEL 6 Made Easy 2.4 OS Installation Source You need to have an OS installation source ready. You can either have a RHEL iso on your host or a remote installation source which you can use via http, ftp or nfs. 2.5 Disk Space Verify you have enough disk space on the host. KVM creates image files (which look just like regular files in the file system) for each VM and assumes you are going to place them in directory /var/lib/libvirt/images.
Dell Inc. 7 KVM Virtualization in RHEL 6 Made Easy BOOTPROTO="dhcp" IPV6INIT="yes" IPV6_AUTOCONF="yes" NM_CONTROLLED="no" ONBOOT="yes" TYPE="Bridge" DELAY="0" 4. Create a FORWARD firewall rule for the bridge br0 so that VM network traffic can be forwarded through it. This rule works for all bridge devices: # iptables -A FORWARD -m physdev --physdev-is-bridged -j ACCEPT # service iptables save 5. Enable forwarding. Edit /etc/sysctl.conf: inet.ipv4.ip_forward = 1 And read the file: # sysctl -p /etc/sysctl.
Dell Inc. 8 KVM Virtualization in RHEL 6 Made Easy # restorecon -R -v /vm-images Verify that the context was changed: # ls –aZ /vm-images drwxr-xr-x. root root system_u:object_r:virt_image_t:s0 . dr-xr-xr-x. root root system_u:object_r:root_t:s0 .. 5. If you are going to export the directory /vm-images as a samba or NFS share, there are SELinux Booleans that need to be set as well: # setsebool -P virt_use_samba 1 # setsebool -P virt_use_nfs 1 3.
Dell Inc. 9 KVM Virtualization in RHEL 6 Made Easy This is the image file for the VM, the size is specified in GBs. --graphics none This tells the installer not to launch a VNC window to access the VM‟s main console. Instead, it will use a text console on the VM‟s serial port. If you rather use an X window with graphics to install the OS on the VM, omit this parameter. --location=http://my.server.com/pub/rhel6.1/install-x86_64/ This is the location of the RHEL 6.
Dell Inc. 10 KVM Virtualization in RHEL 6 Made Easy 1. Suspend the VM to be cloned. This is a requirement since it ensures that all data and network I/O on the VM is stopped. # virsh suspend vm1 2. Run the virt-clone command: # virt-clone \ --connect qemu:///system \ --original vm1 \ --name vm1-clone \ --file /vm-images/vm1-clone.img This operation will take 2-3 minutes, depending on the size of the VM. 3. When done, you can resume the original VM: # virsh resume vm1 4.
Dell Inc. 11 KVM Virtualization in RHEL 6 Made Easy # virt-top Show VM disk partitions: # virt-df vm1 Stop a VM (shutdown the OS): # virsh shutdown vm1 Start VM: # virsh start vm1 Mark VM for autostart (VM will start automatically after host reboots): # virsh autostart vm1 Mark VM for manual start (VM will not start automatically after host reboots): # virsh autostart –disable vm1 5.
Dell Inc. 12 KVM Virtualization in RHEL 6 Made Easy You can now access the USB storage device directly from your VM at /dev/vdb. When you are done with it, simply detach it from your VM: # virsh detach-disk vm1 vdb 5.4 GUI Tools Ok so now I will mention a couple of GUI tools which I admit can be useful when managing and interacting with VMs. virt-viewer – Launches a VNC window that gives you access to a VMs main console. virt-manager – Launches a window where you can manage all your VMs.
Dell Inc. 13 KVM Virtualization in RHEL 6 Made Easy Max memory: Used memory: 1048576 kB 524288 kB In our second example, let‟s increase the amount of memory in vm1 above from 512 MB to 2 GB: 1. In this case we will first need to increase the maximum memory setting. The best way to do it is by editing the VM‟s configuration file. Shutdown the VM or you might see unexpected results: # virsh shutdown vm1 2.
Dell Inc. 14 KVM Virtualization in RHEL 6 Made Easy 6.3 Disk capacity You can always add additional „disks‟ to your VMs by attaching additional file images. Say that you want to add an additional 10 GB of disk space in your VM, here is what you do: 1. Create a 10-GB non-sparse file: # dd if=/dev/zero of=/vm-images/vm1-add.img bs=1M count=10240 2. Shutdown the VM: # virsh shutdown vm1 3. Add an extra entry for „disk‟ in the VM's XML file in /etc/libvirt/qemu.
Dell Inc. 15 KVM Virtualization in RHEL 6 Made Easy Deleting a VM is a lot faster than creating one, just a few quick commands. Let‟s delete vm1-clone: 1. First, shutdown the VM: # virsh shutdown vm1-clone If the VM is not responding or fails to shut down, shut it down forcefully: # virsh destroy vm1-clone 2. Undefine the VMs configuration: # virsh undefine vm1-clone 3. Finally, remove the VM‟s image file: # rm /vm-images/vm1-clone.img 8. Conclusion 8.