You are on page 1of 10

Red Hat Enterprise Linux 6.

x small tutorial - part 2



http://alexandreborges.org Pgina 1

Red Hat Enterprise Linux 6.x small tutorial -
part 2
author: Alexandre Borges
website: http://alexandreborges.org

Installing and administering a KVM virtual machine using Kickstart

This time Ill show you as easy is to create and administer a KVM virtual machine. Following the
same configuration of previous tutorial
(http://alexandreborgesbrazil.files.wordpress.com/2013/07/alexandre_blog_first_post_rhel_1
a.pdf) , Im using a VMware Workstation 8 with Red Hat Enterprise Linux 6.3 installed having 4
GB RAM, 80 HDD and were going to need of the RHEL 6.3 DVD.

KVM feature asks for hardware virtualization support on processor which its configured on
Red Hat virtual machine properties, then you should enable it. My RHEL VM is named
REDHAT_63_1 and VM Tools is installed. Lets go:

Select REDHAT_63_1 VM menu Settings Processors mark Virtualize Intel VT-
x/EPT or AMD-V/RVI Close



Figure 1
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 2


Done. You should boot this VMware virtual machine, login as root user and open a terminal.
Its recommended you mount RHEL 6.3 DVD into this RHEL VMware virtual machine. Its could
be done like that:

Select REDHAT_63_1 VM menu Setting CD/DVD select Use ISO image file
browse the RHEL 6.3 DVD Close

Dont forget to mark Connected after you have logged on RHEL host operating system !!!


Figure 2


Please, you shoud confirm if the following KVM packages are installed:

[root@redhat641 ~]# rpm -qa | grep -i kvm
qemu-kvm-0.12.1.2-2.355.el6_4.2.x86_64

[root@redhat641 ~]# rpm -qa | grep -i virt
virt-who-0.8-5.el6.noarch
virt-top-1.0.4-3.15.el6.x86_64
python-virtinst-0.600.0-15.el6.noarch
virt-manager-0.9.0-18.el6.x86_64
libvirt-client-0.10.2-18.el6_4.4.x86_64
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 3

libvirt-0.10.2-18.el6_4.4.x86_64
virt-viewer-0.5.2-18.el6_4.2.x86_64
virt-what-1.11-1.2.el6.x86_64
libvirt-python-0.10.2-18.el6_4.4.x86_64

Just in case these packages are still not installed in your RHEL host, you should install them
from DVD using the following syntax:

# rpm Uvh <package>

After packages installation,you must reboot your system, log in it using root user, open a
terminal and execute the following command:

[root@redhat641 ~]# lsmod | grep kvm
kvm_intel 53484 0
kvm 316602 1 kvm_intel

Its nice. Our KVM module is in use and it means that our job until here has worked.

Now you should copy the Red Hat DVD iso file into the system because it will make our job
easier. If youve installed VM Tools, the task is so quick as dragging and dropping the iso inside
the RHEL VM. As I dont want to enter every single configuration when our KVM virtual
machine is being installed, Ill use a kickstart configuration file and Ill to make it available using
an Apache web host like I already have done in the first part of this tutorial
(http://alexandreborgesbrazil.files.wordpress.com/2013/07/alexandre_blog_first_post_rhel_1
a.pdf). In my case, Im using a kickstart file at /var/www/html/software/kick.cfg, but Ill need
to adapt it to install a KVM virtual machine:

[root@redhat641 ~]# more /var/www/html/software/kick.cfg

# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
cdrom

lang en_US.UTF-8
keyboard br-abnt2

# Lets configure our system with a fixed IP address

network --device eth0 --bootproto static --ip 192.168.1.160 --netmask 255.255.255.0 --
gateway 192.168.1.1 --nameserver 8.8.8.8 --hostname test.example.com

# Root password will stay the same

rootpw --iscrypted
$6$aCITKaa7BiLM.6PQ$azGsYKTrg8N5YAzfS/liGr.uAREcjARfl7eEJx.UBRvwRuDSJjYyBSqk
WflcasZ4Dtk1qaHxmpsCi4tKauFyG0

# Our firewall will be disabled
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 4


firewall --disabled
authconfig --enableshadow --passalgo=sha512

# SELinux is enabled

selinux --enforcing
timezone --utc America/Sao_Paulo

# Our boot loader is installed at mbr

bootloader --location=mbr --driveorder=vda --append="crashkernel=auto rhgb quiet"

# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work

# Its necessary erase everything before starting the installation

zerombr
clearpart --all --drives=vda

# Our partitions, in MB, follow below:

part /boot --fstype=ext4 --size=500
part / --fstype=ext4 --size=10000
part swap --size=1500

#volgroup vg_redhat641 --pesize=4096 pv.008002
#logvol /home --fstype=ext4 --name=lv_home --vgname=vg_redhat641 --grow --
size=100
#logvol / --fstype=ext4 --name=lv_root --vgname=vg_redhat641 --grow --size=1024 --
maxsize=51200
#logvol swap --name=lv_swap --vgname=vg_redhat641 --grow --size=3968 --
maxsize=3968

# Specify our repository

#repo --name="blog" --baseurl=http://redhat641.example.com/software


# Reboot after installation be finished

reboot
firstboot --disabled

# A lot of packages were installed

%packages
@base
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 5

@cifs-file-server
@client-mgmt-tools
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@directory-client
@storage-client-fcoe
@ftp-server
@fonts
@general-desktop
@graphical-admin-tools
@identity-management-server
@input-methods
@internet-browser
@java-platform
@legacy-unix
@legacy-x
@nfs-file-server
@storage-server
@network-file-system-client
@network-tools
@performance
@perl-runtime
@print-server
@print-client
@remote-desktop-clients
@server-platform
@server-policy
@virtualization
@virtualization-client
@virtualization-platform
@virtualization-tools
@web-server
@x11
mtools
pax
python-dmidecode
oddjob
wodim
sgpio
genisoimage
device-mapper-persistent-data
abrt-gui
samba-winbind
certmonger
openldap-clients
pam_krb5
krb5-workstation
ldapjdk
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 6

slapi-nis
tcp_wrappers
libXmu
ebtables
sg3_utils
perl-DBD-SQLite
perl-Mozilla-LDAP
mod_auth_kerb
mod_nss
certmonger
perl-CGI
python-memcached
mod_revocator
memcached
%end


Please, you should pay attention on highlighted pieces of this file. You may have noticed that
the hard disk isnt sda but vda because its a virtual disk. Another change is that Im using
cdrom installation method to make simpler our task. A last remember about the file: Ive
named our KVM virtual machine as test.example.com.

Lets create and install our first KVM virtual machine:

[root@redhat641 software]# virt-install -n test -r 1024 --disk
path=/var/lib/libvirt/images/test.img,size=13 -l /root/Desktop/rhel-server-6.4-x86_64-
dvd.iso -x "ks=http://192.168.1.150/software/kick.cfg"

This whole line appear very difficult, but Its not. Detailing it:

-n virtual machine name
-r RAM memory (MB)
--disk path where the virtual machine is being installed
size virtual disk size (GB)
-l location of installation files
-x kernel extra arguments

Its sure nobody wants that something goes wrong, but just in case this to happen, you can
clean the virtual machine configuration and remove the virtual disk, correct your mistake and
run the same previous command. Executing the cleaning task is straight:

(power off the virtual machine)

[root@redhat641 software]# virsh destroy test

(remove virtual machine configuration)

[root@redhat641 software]# rm /etc/libvirt/qemu/test.xml

(removing the virtual disk image)

Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 7

[root@redhat641 software]# rm /var/lib/libvirt/images/test.img

(restarting the virtualization service)

[root@redhat641 software]# /etc/init.d/libvirtd restart

Its done. If you want, youre able to execute the virtual machine creation again. ;)

Follow few screens showing the middle of process of virtual machine installation:


Figure 3


Figure 4
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 8


Figure 5




Figure 6

Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 9

Now that our KVM virtual machine is installed and working, we can execute some
administration commands. For example, to list KVM virtual machines in our RHEL VM:

[root@redhat641 Desktop]# virsh list --all
Id Name State
----------------------------------------------------
2 test running
- vm1 shut off

Setting the KVM virtual machine to start during the boot process of the host machine is easy:

[root@redhat641 Desktop]# virsh autostart test
Domain test marked as autostarted

To disable the KVM virtual machine to start during the boot process of the host machine:

[root@redhat641 Desktop]# virsh autostart --disable test
Domain test unmarked as autostarted

To stop the KVM virtual machine:

[root@redhat641 Desktop]# virsh destroy test
Domain test destroyed

To start the KVM virtual machine:

[root@redhat641 Desktop]# virsh start test

Now, lets open the virtual machine display using virt-viewer:

[root@redhat641 Desktop]# virt-viewer test &

If you wish, its feasible to clone a KVM virtual machine. To execute the cloning job, its needed
that the original virtual machine is powered off:

[root@redhat641 Desktop]# virsh list --all
Id Name State
----------------------------------------------------
- test shut off
- vm1 shut off

[root@redhat641 Desktop]# virt-clone --prompt
What is the name of the original virtual machine?
test
What is the name for the cloned virtual machine?
test2
What would you like to use as the cloned disk (file path) for '/var/lib/libvirt/images/test.img'?
/var/lib/libvirt/images/test2.img
Allocating 'test2.img' | 13 GB 03:11

Clone 'test2' created successfully.
Red Hat Enterprise Linux 6.x small tutorial - part 2

http://alexandreborges.org Pgina 10


[root@redhat641 Desktop]# virsh list --all
Id Name State
----------------------------------------------------
- test shut off
- test2 shut off
- vm1 shut off

Nonetheless, before you can use this virtual machine, you should boot it into runlevel 1,
change the network configuration and, afterwards, you could boot it into runlevel 3.

Alternatively, if you wish to remove a virtual machine configuration (and its virtual disk), you
can do:

[root@redhat641 Desktop]# virsh undefine test2

Weve finished it. I hope youve enjoyed it. Have a nice day !!!

Alexandre Borges.

You might also like