Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The host server (running CentOS 6.0) only has one public IP address and will be hosting many KVM guests so it needs to use a virtual network switch configuration in NAT mode.

I have previously used pxelinux for automated installation of physical machines and would like to continue to use pxelinux for installation of KVM-guests. The reason for this is that I already have written some scripts that generate pxelinux configuration files and I would like to reuse them.

Could someone provide a step-by-step instruction of how to install a CentOS 6.0 KVM guest on a CentOS 6.0 host server?

I would like to use the command line as much as possible so I prefer virt-install to virt-manager.

The host server has only one LVM volume group: vg0

[root@server ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree 
  vg0    1   3   0 wz--n- 8.18t 97.90g
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

First install some requirements. (This might be more than actually needed)

yum -y groupinstall "X Window System"
yum -y groupinstall "Virtualization Client" 
yum -y groupinstall "Virtualization" 
yum -y groupinstall "Virtualization Platform" 
yum -y groupinstall "Virtualization Tools"
yum -y groupinstall "Desktop"
yum -y install xorg-x11-fonts-100dpi
yum -y install xorg-x11-fonts-75dpi
yum -y install xorg-x11-fonts-Type1 xorg-x11-font-utils
yum -y install man
yum -y install emacs

As stated in the question we already have an LVM volume group

[root@server ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree 
  vg0    1   3   0 wz--n- 8.18t 97.90g

First we create and define a libvirt storage pool from that LVM volume group

[root@server ~]# cat /tmp/foobar
<pool type='logical'>
  <name>pool0</name>
  <target>
    <path>/dev/vg0</path>
  </target>
</pool>
[root@server ~]# virsh pool-define /tmp/foobar
Pool pool0 defined from /tmp/foobar

[root@server ~]# virsh pool-start pool0
Pool pool0 started

[root@server ~]# virsh pool-autostart pool0
Pool pool0 marked as autostarted

[root@server ~]# virsh pool-list
Name                 State      Autostart 
-----------------------------------------
pool0                  active     yes       

Per default libvirt already has a virtual network configured. It is named default. In this example we will redefine that virtual network so that we can use it for PXE install.

[root@server ~]# virsh net-list
Name                 State      Autostart
-----------------------------------------
default              active     yes       

[root@server ~]# emacs /tmp/default.xml
[root@server ~]# cat /tmp/default.xml
<network>
  <name>default</name>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0' />
  <ip address='10.0.0.1' netmask='255.255.0.0'>
    <tftp root='/var/lib/dnsmasq/tftpboot' />
    <dhcp>
      <range start='10.0.0.2' end='10.0.255.255' />
      <host mac='02:54:00:13:be:e4' name='virt1.example.com' ip='10.0.0.2' />
      <host mac='02:52:2c:a3:11:42' name='virt2.example.com' ip='10.0.0.3' />
      <bootp file='/pxelinux.0' />
    </dhcp>
  </ip>
</network>

The MAC addresses, 02:54:00:13:be:e4 and 02:52:2c:a3:11:42 seen above are just some random MAC addresses. (see the serverfault question: how to generate a random MAC address from the Linux command line)

[root@server ~]# virsh net-destroy default
Network default destroyed

[root@server ~]# virsh net-undefine default
Network default has been undefined

[root@server ~]# virsh net-define /tmp/default.xml
Network default defined from /tmp/default.xml

[root@server ~]# virsh net-start default
Network default started

[root@server ~]# virsh net-autostart default
Network default marked as autostarted

[root@server ~]# mkdir /var/lib/dnsmasq/tftpboot      
[root@server ~]# ls -lZd /var/lib/dnsmasq/tftpboot
drwxr-xr-x. root root unconfined_u:object_r:dnsmasq_lease_t:s0 /var/lib/dnsmasq/tftpboot
[root@server ~]# yum install syslinux
[root@server ~]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@server ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/dnsmasq/tftpboot/
[root@server ~]# cd /var/lib/dnsmasq/tftpboot/
[root@server tftpboot]# wget -O centos-6-vmlinuz.x86_64 http://ftp.funet.fi/pub/Linux/mirrors/centos/6.0/os/x86_64/images/pxeboot/vmlinuz
[root@server tftpboot]# wget -O centos-6-initrd.img.x86_64 http://ftp.funet.fi/pub/Linux/mirrors/centos/6.0/os/x86_64/images/pxeboot/initrd.img
[root@server tftpboot]# mkdir /var/lib/dnsmasq/tftpboot/pxelinux.cfg
[root@server tftpboot]# cd /var/lib/dnsmasq/tftpboot/pxelinux.cfg

The MAC address 02:54:00:13:be:e4 used above needs the configuration filename 01-02-54-00-13-be-e4. In other words prepend 01- and convert : into -.

[root@server pxelinux.cfg]# emacs 01-02-54-00-13-be-e4
[root@server pxelinux.cfg]# cat 01-02-54-00-13-be-e4
default local
prompt 1
timeout 50

label local
  localboot 0

label install
  kernel /centos-6-vmlinuz.x86_64
  append initrd=/centos-6-initrd.img.x86_64 ks=http://www.example.com/kickstart-files/virt1.example.com.txt device=eth0 ramdisk_size=9216 lang= devfs=nomount  

[root@server pxelinux.cfg]# cd

Here we assumed that the kickstart file for virt1.example.com can be downloaded from http://www.example.com/kickstart-files/virt1.example.com.txt

Now we run service libvirtd reload. This seems to be required for the dnsmasq tftpserver to run properly.

[root@server ~]# service libvirtd reload
Reloading libvirtd configuration:                          [  OK  ]

Now run virt-install to create the KVM guest virt1.example.com with 20 Gb disk space.

[root@server ~]# virt-install --debug --hvm --vnc --name virt1.example.com --os-type=linux --os-variant=rhel6 --pxe --network network=default,model=e1000,mac=02:54:00:13:be:e4 --disk pool=pool0,size=20 --ram 1024 --vcpus=1 

Now the graphical program virt-viewer will pop up an X-window. When you see "boot: " during the boot sequence, type install.

A note about the virt-install command line options: Using model=virtio didn't work for me, but luckily model=e1000 worked just fine.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.