Install Type

  • Non-interactive
  • Network boot
  • Commandline
  • Paravirtualized

Prerequisites

  • XCP/Xenserver
  • Access to Internet
  • Working DHCP server
  • Working DNS name resolution

Introduction

This tutorial was written in the spirit of my CentOS 6 virtual machine (64 bit) installation on Xen howto. In that tutorial I created a disk, downloaded a kernel, kickstart file plus a xen config file which installed CentOS using the kickstart file. This has proven very popular since you can't install a paravirtualized domain using an install disk. This has been a very nice installation howto because you don't have to download any install CD/DVDs and you could create VMs using nothing more than a commandline login. It's also very nice because it can be mirrored locally if you're doing a bunch of them just by rsyncing a CentOS mirror locally then downloading my files and editing them.

I now use Xenserver and it's a very different animal indeed. However, I still needed a system of creating CentOS Virtual Machines in that same manner. I didn't want to download a CentOS install DVD or need a graphical login to install the OS thus this tutorial was born.

Warning! This tutorial is for CentOS version 7 on Xenserver 6.5. To use Xenserver 6.2 or later you will need to shoehorn grub-legacy into it. I've managed to get CentOS7 to run in Xenserver 6.2 but I had to do the following. 

  1. Install CentOS7 in Xenserver 6.5 
  2. Boot the VM and login
  3. Uninstall grub2
  4. Manually download grub-legacy and install
  5. Download grub.conf file to /boot/grub/grub.conf (edit if necessary)
  6. Run the grub command to install it
    1. # grub
    2. grub> device (hd0) /dev/xvda
    3. grub> root (hd0,0)
    4. grub> setup (hd0)
    5. grub> quit
  7. Place exclude=grub* in your /etc/yum.conf
  8. Shut down the VM and export it using vm-export
  9. Copy the VM to the Xenserver 6.2 host and vm-import

 

 Note: This tutorial is designed so you can copy and paste the text inside the boxes. I don't actually type any of this in and neither should you.

 

1. Getting the network info

This line gets the Network UUID for xenbr0. If you're using a different bridge you will want to insert it here. Get a list of XCP networks with xe network-list. This network is connected to the outside interface. This tutorial requires there to be a DHCP server on this network answering requests and providing network access to the Internet.

NETUUID=$(xe network-list bridge=xenbr0 --minimal)

2. Creating the VM and setting parameters

Here we create the VM from the RHEL6 template, create a network interface and add it to our network from step one. Additional settings are for configuring the install repository and specifying the kickstart file from my site. The last setting turns off VNC so we can watch the install via a text console (very important in my environment).  Even if you can't see all the text below just highlight and paste. The text is there even if it's not visible.

TMPLUUID=$(xe template-list | grep -B1 'name-label.*Red Hat.* 6.*64-bit' | awk -F: '/uuid/{print $2}'| tr -d " ")
VMUUID=$(xe vm-install new-name-label="CentOS7" template=${TMPLUUID})
xe vif-create vm-uuid=$VMUUID network-uuid=$NETUUID mac=random device=0
xe vm-param-set uuid=$VMUUID other-config:install-repository=http://mirror.centos.org/centos/7/os/x86_64
xe vm-param-set uuid=$VMUUID PV-args="ks=http://grantmcwilliams.com/files/kickstart-minimal7-x86_64.cfg ksdevice=eth0"

3. Starting the VM and watching the install

The VM installs without any interraction from the user at this point. It is however, nice to watch it using xenconsole. Once it's done installing it will shutdown.

If you're using XCP 1.0/1.1 (see note above about pre-6.5 Xenserver)

xe vm-param-set uuid=${VMUUID} other-config:disable_pv_vnc=1
xe vm-start uuid=$VMUUID
DOMID=$(xe vm-list uuid=${VMUUID} params=dom-id --minimal)
/usr/lib/xen/bin/xenconsole ${DOMID}

If you're using XCP 1.5b or Xenserver 6.2 or higher (see note above about pre-6.5 Xenserver)

xe vm-start uuid=$VMUUID
xe console uuid=$VMUUID

4. Starting the VM and configuring settings

We need to boot the VM up again and using xenconsole log in as root to configure the network and reset the root users password.

If you're using XCP 1.0/1.1

xe vm-start uuid=$VMUUID
DOMID=$(xe vm-list uuid=${VMUUID} params=dom-id --minimal)
/usr/lib/xen/bin/xenconsole ${DOMID}

If you're using XCP 1.5b and Xenserver

xe vm-start uuid=$VMUUID
xe console uuid=$VMUUID

Now that your CentOS 6 VM is running you can login. The password was automatically set by the kickstart file.

  • Username: root
  • Password: password

Reset the root users password and change the network settings to static IP using system-config-network. If you want to keep the IP assignment dynamic note the ip address.

5. Shutting down the VM and re-enabling VNC

If you're going to use XVP or some other method of connecting to the VMs direct VNC connection you'll need to enable it.

xe vm-shutdown uuid=$VMUUID
xe vm-param-remove uuid=${VMUUID} param-name=other-config param-key=disable_pv_vnc
xe vm-start uuid=$VMUUID

6. Add RPMforge and EPEL repositories

I almost always install RPMforge. It is very stable and doesn't replace standard packages.

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

7. Export our VM for safe keeping

Before you start modifying the base CentOS image you should back it up.

xe vm-export uuid=$VMUUID filename=CentOS7-base.xva

Be aware that you may not have enough space on the Control Domain's disk to export it. A good solution (and shorter than explaining how to add disks to the control domain) is to mount an nfs volume and export it there.

mount nfsserver:/share /media/share
xe vm-export uuid=$VMUUID filename=/media/share/CentOS6-base.xva

This would mount the NFS share on nfsserver to /media/share. The exported disk would be saved on the NFS share.

 xe vm-param-remove uuid=${VMUUID} param-name=other-config param-key=disable_pv_vnc