Final Case Study
Chapter 6: Red Hat Enterprise Linux Virtualization
Objectives
After completing this chapter, you should be able to:
• Implement Red Hat Virtualization
• Understand the requirements for Red Hat Virtualization
• Create a guest operating system
• Install Red Hat Enterprise Linux 5 as a paravirtualized guest
• Install Windows XP as a fully virtualized guest
• Create a virtualized floppy disk controller
• Add storage devices to guests
Key Terms
Full virtualization
a type of virtualization that does not require any modifications to guest
operating systems
Introduction to Red Hat Enterprise Linux Virtualization
Red Hat Linux is one of the most popular lightweight, open-source platforms. The
enterprise version of Red Hat Linux provides a multilayered virtualization system
driven by the Red Hat Virtualization component. This chapter teaches you how to
implement this virtualization system.
Red Hat Enterprise Linux Virtualization Basics
Red Hat Enterprise Linux can host multiple guest operating systems, with each
guest operating system running in its own domain. It schedules the virtual CPUs
within the virtual machines in order to make the best use of the available physical
6-1
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
CPUs. Each guest operating system handles its own applications and schedules each
application accordingly.
Red Hat Virtualization can be deployed in two ways: full virtualization and
paravirtualization. Full virtualization creates a new virtual machine in which the
guest operating systems can run. It does not require any modification to the guest
operating system or application; the guest OS or application is not aware of the
virtualized environment. Paravirtualization requires user modification of the guest
operating systems that run on the virtual machines. These guest operating systems
are aware that they are running on a virtual machine. Paravirtualization provides
near-native levels of performance.
The first domain, known as Domain0, is automatically created when the user boots
the system. Domain0 is an authorized guest that creates domains and manages
virtual resources. It manages physical hardware and performs administrative tasks
such as resuming, suspending, or shifting guest domains to other virtual machines.
Red Hat’s Virtual Machine Monitor, called the hypervisor, is a virtualization
platform that allows multiple operating systems to run on a single host
simultaneously within a full virtualization environment. A guest is an OS that runs
on a virtual machine in addition to the host or main OS.
The user can configure guest machines with a number of virtual CPUs (called
VCPUs). The Virtual Machine Manager schedules the VCPUs according to the
workload on the physical CPUs. The user can grant any number of virtual disks, as
well as network and other interfaces, to the guest.
System Requirements
Running virtualization on Red Hat Enterprise Linux requires the following:
• Computer system running Red Hat Enterprise Linux 5 Server with
virtualization packages
• Configured hypervisor host
• 6 GB of free disk space per guest
• 2 GB of RAM per guest
• 6 GB plus per guest
6-1
6-2
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
• One processing core or hyperthread for each guest and one for the hypervisor
(recommended)
Paravirtualized guests require the Red Hat Enterprise Linux 5 installation tree be
available over NFS, FTP, or HTTP. Fully virtualized guests require an installation
disc, as well as CPUs with hardware virtualization extensions. To verify whether
the virtualization extensions are enabled or disabled in the BIOS of an Intel-based
machine, users can follow these steps:
1. Run the xm dmesg | grep VMX command. The output should display:
(XEN) VMXON is done
(XEN) VMXON is done
2. Run the cat /proc/cpuinfo | grep vmx command to verify that the CPU flags
have been set. The output should display:
flags:fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36
clflush
dts acpi mmx fxsr sse sse2 ss ht tm syscall lm constant _
tsc pni
monitor ds _ cpl vmx est tm2 cx16 xtpr lahf _lm
Users can run the following commands to verify the virtualization extensions on
systems with AMD-V architectures:
1. Run the xm dmesg | grep SVM command. The output should look like the
following:
(XEN) AMD SVM Extension is enabled for cpu 0
(XEN) AMD SVM Extension is enabled for cpu 1
2. Run the cat /proc/cpuinfo | grep svm command to verify that the CPU flags
have been set. The output should look like the following:
flags:fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36
clflush mmx
fxsr sse sse2 ht syscall nx mmxext fxsr _ opt lm 3dnowext
3dnow pni cx16
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
lahf _lm cmp _legacy svm cr8legacy ts fid vid ttp tm stc
Supported guest storage methods include the following:
• Files on local storage
• Physical disk partitions
• Locally connected LUNs
• LVM partitions
• iSCSI and Fibre Channel–based LUNs
Installing Red Hat Enterprise Linux Virtualization
Users should perform the following steps prior to the Red Hat installation:
• Enable Red Hat Network (RHN) entitlements for the Red Hat Virtualization
packages.
• Enable all entitlements to install and update the virtualization packages on Red
Hat Enterprise Linux.
• Register the machines with RHN and create a valid Red Hat Network account
for the installation process at http://rhn.redhat.com.
To add a virtualization element with RHN, users can follow these steps:
1. Enable RHN entitlements for the Red Hat Virtualization packages.
2. Enter the RHN username and password to log on to RHN.
3. Select the systems on which to install Red Hat Virtualization.
4. Check the Virtualization check box in the System Properties section where the
system entitlements are listed.
After completing the above steps, the system should start receiving the Red Hat
Virtualization packages.
Installing Using the yum Command
Installing Red Hat Virtualization on Red Hat Enterprise Linux requires the
following packages:
6-2
6-3
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
• xen: This package contains the fundamental virtualization tools and the
hypervisor.
• kernel-xen: This package contains the modified Linux kernel that works as a
virtual machine guest on the hypervisor.
Users can follow these steps to install the xen and kernel-xen packages:
1. Type the following command:
yum install xen kernel-xen
2. Fully virtualized guests on systems with Itanium architecture require the guest
firmware image package (xen-ia64-guest-firmware) from the installation DVD.
To install this package, run the following command:
yum install xen-ia64-guest-firmware
3. To install other recommended virtualization packages, run the following
command:
yum install virt-manager libvirt libvirt-python libvirt-
python
python-virtinst
The following Linux virtualization packages are recommended:
• python-virtinst: This package provides the virt-install command for creating
virtual machines.
• libvirt: This is an API library used to interact with hypervisors, as well as
control and manage virtual machines.
• libvirt-python: This package allows applications written in the Python
programming language to use the interface provided by the libvirt API.
• virt-manager: This package provides a graphical tool for creating and
managing the virtualized guests.
Creating Guests with virt-manager
6-3
6-4
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
virt-manager (Virtual Machine Manager) is a package that provides a graphical tool
for creating and managing virtualized guests. Users can perform the following
steps to create guests with virt-manager:
1. Start virt-manager by typing the following command:
sudo virt-manager &
2. Click the Connect button in the Open connection dialog box.
3. Click the New button in the Virtual Machine Manager window to create a new
guest.
4. Read the information on the screen and click the Forward button.
5. In the Choosing a virtualization method window, select the virtualization type
and then click the Forward button.
6. In the Locating installation media window, specify the installation media and
then click the Forward button.
7. In the Assigning storage space window, select a disk partition, select a LUN, or
create an image file for guest storage. The installation process automatically
selects the size of the guest’s swap file according to the amount of RAM
allocated to the guest. Click the Forward button when finished.
8. In the Allocate memory and CPU window, choose the appropriate values for
the virtualized CPUs and memory allocation and then click the Forward
button.
9. The Ready to begin installation window presents a summary of all
configuration information. Review the information and, if necessary, use the
Back button to make changes. Otherwise, click the Finish button to begin the
installation process.
Installing Guest Operating Systems
Various operating systems can be installed as guest operating systems in a
virtualized environment on Red Hat Enterprise Linux. There are several types of
guest operating system installation processes, including the following:
• Installing Red Hat Enterprise Linux 5 as a paravirtualized guest from a shell
• Installing Windows XP as a fully virtualized guest
• Creating a fully virtualized Windows Server 2003 SP1 guest
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Installing Red Hat Enterprise Linux 5 as a Paravirtualized Guest
Paravirtualization is faster than full virtualization and has most of the same
advantages. Paravirtualization requires the kernel-xen kernel. The
paravirtualization installation process requires root privileges or sudo access.
Users can use the virt-manager or virt-install command to create paravirtualized
Red Hat Enterprise Linux 5 guests. They can run the following command to open
the Virtual Machine Console window:
virt-install -n rhel5PV -r 500 -fvar/lib/xen/images/rhel5PV.dsk
-s 3
--vnc -p -l\ftp://10.1.1.1/trees/RHEL5-B2-Server-i386/
In this command the --vnc option specified a graphical installation, rhel5PV is the
name of the guest, rhel5PV.dsk is the disk image, and ftp://10.1.1.1/trees/RHEL5-B2-
Server-i386/ is the local mirror of the Red Hat Enterprise Linux 5 installation tree.
After completing the initial boot phase, the standard installation process for Red
Hat Enterprise Linux starts. Users can follow these steps to install Red Hat
Enterprise Linux as the guest OS:
1. Select the proper language and select OK.
2. Select the keyboard layout and select OK.
3. Choose the TCP/IP options and select OK.
• If DHCP is selected, the installation process attempts to obtain an IP
address. Otherwise, manually enter the IP information and select OK.
4. The installation process now retrieves the files it needs from the server. Once
the initial steps are complete, the graphical installation process starts. Click the
Next button.
• If installing a beta version of Red Hat Enterprise Linux 5, the warning
shown in Figure 6-1 will appear. Click the Install anyway button, and then
click the Next button.
6-4
6-5
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Figure 6-1
Click the Install anyway button if this warning appears.
5. Enter a valid registration code in the Installation Number field and click the
OK button.
6. The installation process asks to confirm the deletion of all data on the storage
device. Click the Yes button.
7. Review the storage configuration and partition layout. Click the Advanced
storage configuration button to use iSCSI. Otherwise, click the Next button.
8. Click the Yes button to confirm that Linux partitions will be removed.
9. Configure networking and hostname settings and click the Next button.
10. Select the time zone for the environment and click the Next button.
11. Enter the root password for the guest and click the Next button.
12. Check the boxes corresponding to the software packages to install. Select the
Customize Now radio button and click the Next button.
13. The installer will check software dependencies. Click the Next button.
14. Click the Next button once more to begin the installation process.
15. After the installation is finished, click Reboot to restart the guest.
16. Once the system reboots, open virt-manager. Select the name of the guest OS,
click Open, and then click Run.
17. At the Welcome window, click the Forward button.
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
18. Read and accept the license agreement and click the Forward button.
19. Enable the firewall, check the boxes for the trusted services, and click the
Forward button.
20. Set SELinux to enforcing mode and click the Forward button.
21. If required, enable kdump and click the Forward button.
22. Set the date and time for the guest and click the Forward button. This date
and time must match that of the hypervisor.
23. In the Set up software updates window, click the Forward button.
24. Confirm the choices for RHN and click the Forward button.
25. At the Finish Update Setup window, click the Forward button.
26. Create a nonroot user account and click the Forward button.
27. Set up the sound card, if required, and click the Forward button.
28. At the Additional CDs window, install any additional software packages from
the CD and click the Finish button to complete the installation.
29. The Red Hat Enterprise Linux 5 login screen will appear. Log in using the
username created in Step 26.
30. A window containing a paravirtualized Red Hat Enterprise Linux guest will
appear.
Installing a Windows XP Guest
To install Windows XP as a fully virtualized guest, users can follow these steps:
1. Go to Applications, then System Tools, and then Virtual Machine Manager to
open the virtual machine manager.
2. Click File and then Open Connection to open a connection to the host.
3. Click the New button to create a new virtual machine.
4. At the Naming your virtual system screen, enter the system name and click
the Forward button.
5. At the Choosing a virtualization method window, select the fully virtualized
option and click the Forward button.
6. On the Locating installation media window, specify the location of the
Windows installation disc and click the Forward button.
7. In the Assigning storage space window, choose a disk partition, choose a LUN,
or create an image file for guest storage. The installation process automatically
6-5
6-6
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
selects the size of the swap file based on the amount of RAM assigned to the
guest. Click the Forward button.
8. In the Allocate memory and CPU window, choose the appropriate values for
the virtualized CPUs and memory allocation and click the Forward button. Do
not allocate more virtual CPUs than physical processors (or hyperthreads)
available on the host system.
9. In the Ready to begin installation window, click the Finish button to proceed
to the OS installation.
10. Once the installation process starts, switch to the virt-manager summary
window.
11. Select the newly started Windows guest. Double-click on the system’s name to
open the console window.
12. Quickly and repeatedly press F5 to select a new HAL.
13. When the Windows install select dialog box appears, select the Generic i486
Platform tab.
14. The Windows installation process starts. Press Enter to install Windows XP.
15. Proceed through the Windows XP installation as normal, until the first reboot.
16. Halt the virtual machine after the initial reboot using the following command,
where <WindowsGuest> is the name of the guest:
xm destroy <WindowsGuest>
17. Edit the guest’s configuration file, located in /etc/xen/, with the same filename
as the guest’s name.
18. Locate the following entry in the configuration file:
k = [‘file:/var/lib/xen/images/winxp.dsk,hda,w’]
Change this entry to the following:
disk = [‘file:/var/lib/xen/images/winxp.dsk,hda,w’,
file:/xen/pub/trees/
MS/en _ winxp _ pro _ with _ sp2.iso,hdc:cdrom,r’,]
19. Restart the Windows guest with the xm create <WindowsGuest> command.
20. Continue with the Windows XP installation as normal. If the installation
freezes for an extended period of time, restart the guest operating system with
the virsh reboot <WindowsGuest> command.
21. Once setup is finished the window should show a Windows desktop.
6-6
6-7
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Configuring Red Hat Enterprise Linux Virtualization
Creating a Virtualized Floppy Disk Controller
Floppy disk controllers are needed for many older operating systems, particularly
those that do not natively support CD or DVD controllers. A virtualized floppy disk
controller must be created to access the floppy disk devices. This requires the
image file of a floppy disk. Users can use the dd command to create a floppy disk
image file as follows:
sudo dd if=/dev/fd0 of=~/legacydrivers.img
In the above example, /dev/fd0 can be replaced with the name of a floppy disk
device. A virtualized floppy disk controller can be created by following these steps:
1. On a running guest operating system, create the XML configuration file for the
guest image using the virsh command:
virsh dumpxml rhel5FV > rhel5FV.xml
2. Create a floppy disk image for the guest using the following command:
sudo dd if=/dev/zero of=/var/lib/xen/images/rhel5FV-
floppy.img bs=512
count=2880
3. Add the following to the guest’s configuration XML file:
<disk type=‘file’ device=‘floppy’>
<source file=‘/var/lib/xen/images/rhel5FV-floppy.img’/>
<target dev=‘fda’/>
</disk>
4. Stop the guest by running the virsh stop rhel5FV command.
5. Restart the guest by using the XML configuration file as follows:
virsh create rhel5FV.xml
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Adding Storage Devices to Guests
After creating guests, storage devices must be added to each virtual guest machine.
Supported storage devices and protocols include the following:
• Local hard drive partitions
• Logical volumes
• Fibre Channel or iSCSI directly connected to the host
• File containers residing in a file system on the host
• NFS file systems mounted directly by the virtual machine
• iSCSI storage directly accessed by the guest
• Clustered file systems
Users can perform the following steps to add file-based storage to a guest OS:
1. Create an empty container file using the dd command. Create a sparse file by
using the following command:
sudo dd if=/dev/zero of=/xen/images/FileName.img bs=1M
seek=4096
count=0
Alternatively, create a nonsparse file using the following command:
sudo dd if=/dev/zero of=/xen/images/FileName.img bs=1M
count=4096
2. Dump the configuration for the guest:
sudo virsh dumpxml Guest1 > ~/Guest1.xml
3. Open the configuration file in a text editor, as shown in Figure 6-2.
6-7
6-8
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Figure 6-2
Open the configuration file in a text editor.
4. Add additional storage by modifying the end of disk = entry, as shown in
Figure 6-3.
Figure 6-3
Modify the end of disk = entry to add additional storage.
5. Restart the guest operating system from the updated configuration file:
sudo virsh create Guest1.xml
6. The guest operating system now uses the file FileName.img as the device
called /dev/hdb. On the guest operating system, partition the device into one
primary partition for the complete device and format the device as follows:
• Run the following command and then press n for a new partition:
fdisk /dev/hdb
• Press p for a primary partition and choose an available partition number.
Partition number (1−4): 1
• Enter the default first cylinder by pressing Enter.
First cylinder (1−400, default 1):
• Select the size of the partition.
Last cylinder or +size or +sizeM or +sizeK (2–400, default 400): 6-8
6-9
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
• Set the type of partition by pressing t.
Command (m for help): t
• Choose the partition created in the previous steps.
Partition number (1-4): 1
• Enter 83 for a Linux partition.
Hex code (type L to list codes): 83
• Write the changes to disk and quit.
Command (m for help): w
Command (m for help): q
• Format the new partition with the ext3 file system
mke2fs -j /dev/hdb
7. Mount the disk on the guest OS.
mount /dev/hdb1 /myfiles
Adding a Virtualized CD-ROM or DVD Device to a Guest
To attach an ISO file to a guest when the guest is online, users can use the virsh
command with the attach-disk parameter as follows:
virsh attach-disk [domain-id][source][target]--driver file
-type
cdrom --mode readonly
In the above example, [source] represents the path for the files and devices on the
host, and [target] represents the path for the files and devices on the guest.
Configuring Networks and Guests
Configuring networks and guests in Red Hat Virtualization involves installing
multiple Ethernet interfaces and setting up bridging. Every domain network
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
interface is directly connected by a point-to-point link to a virtual network
interface.
Red Hat Virtualization’s virtual networking is controlled by two shell scripts:
network-bridge and vif-bridge. xend calls these scripts when certain events occur.
Queries are directly passed to the scripts to provide extra information. These
scripts are located in the /etc/xen/scripts directory. The user can modify script
properties by changing the xend-config.sxp configuration file in the /etc/xen
directory.
• network-bridge
• Use the network-bridge command when xend starts or stops.
• This command generates the bridge xenbr0 and moves eth0 onto that
bridge, changing the routing accordingly.
• When xend finally exits, it deletes the bridge and removes eth0, restoring
the original IP and routing configuration.
• vif-bridge
• This is a script invoked for each virtual interface on the domain.
• It configures firewall rules and configures a virtual interface in bridged
mode.
Configuring Multiple Guest Network Bridges to Use Multiple Ethernet Cards
To set up multiple Red Hat Virtualization bridges, users can follow these steps:
1. By using the system-config-network application, configure another network
interface. Create a new configuration file named ifcfg-eth1 in
the /etc/sysconfig/network-scripts/directory, as shown in Figure 6-4.
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Figure 6-4
Create a new configuration file with these contents.
2. Copy the file /etc/xen/scripts/network-bridge
to /etc/xen/scripts/networkbridge.xen.
3. Comment out any existing network scripts in /etc/xen/xend-config.sxp and add
the following line:
network-xen-multi-bridge
4. Create a custom script to create multiple Red Hat Virtualization network
bridges, as shown in Figure 6-5.
6-9
6-10
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml
Figure 6-5
Create a custom script like this one to create multiple network bridges.
Laptop Network Configuration
Users can perform the following steps to configure a laptop network on host/Dom0:
1. Create a dummy0 network interface and allocate a static IP address to it.
PRINTED BY: Chandra Shrestha <[email protected]>. Printing is for personal, private use only. No part of this book may be reproduced or transmitted without publisher's prior permission. Violators will be prosecuted.
10/9/2018http://e.pub/b1r6lh8z0v8zakjlztzu.vbk/OPS/loc_007-print-1539145988.xhtml