Recently I wanted to start playing with CloudStack.  Doing so required a Linux VM on my XenServer.  I decided to opt for CentOS 6.3 x64.  From my previous work with Ubuntu I knew that switching to PV mode could lose me access to the console.  So I started scouring the Internet in search for how to get VNC up and running for console access before enabling PV mode.

1)      Install CentOS 6.3 x64 using Other install media template and the CentOS DVD.

2)      Remember to su to root before you continue.

3)      Start sshd and tell it to start at boot.  This is generally just a good practice when you might lose access to the console.  You may want to reboot and connect to confirm it automatically starts.

  • /etc/init.d/sshd start
  • chkconfig --level 2345 sshd on
  • alternatively you can run system-config-services and use the GUI to set sshd to start automatically

4)      Install both xinetd and Tight VNC.

  • yum install xinetd vnc-server

5)      Open /etc/gdm/custom.conf in your favorite Linux text editor. Under the XDMCP section add the following line and save the file:

  • Enable=true

6)      Create a new file under /etc/xinetd.d and name it something descriptive.  I used Xvnc.  Add the following contents.  Note:  The service name should match what is in /etc/services for that port.

service vnc-server
{
disable = no
protocol = tcp
socket_type = stream
wait = no
user = nobody
server = /usr/bin/Xvnc
server_args = -inetd -query localhost -once -geometry 1024x768 -depth 16 -SecurityTypes=None
port = 5900
}

7)      Open /etc/sysconfig/iptables and add the following line before the first REJECT statement:

  • -A INPUT -m state --state NEW -m tcp -p tcp --dport 5900 -j ACCEPT

8)      Now restart iptables and start xinetd.

  • /etc/init.d/iptables restart
  • /etc/init.d/xinetd start

9)      Confirm iptables has the run added.  It will probably show “vnc-server” as the port instead of 5900.

  • iptables –L

10)   Don’t forget to add xinetd to the proper run levels.

  • chkconfig --level 2345 xinetd on

11)   At this point if you connect via VNC you will get a black screen.  The XDMCP setting is not yet in effect.  The easiest way to solve this is to reboot the VM.  It will also tell you if xinetd is starting at boot.  If you cannot wait, ssh to the box and run these telinit commands to reset the run level.  Gdm-restart no longer exists in CentOS 6.x.

  • telinit 3
  • telinit 5

12)   Now try connecting to the VMs IP with your favorite vnc viewer.  The service is running on the default port of 5900.  You will notice that XenCenter is still unaware of this.  That will be the case until the tools are installed.  If you cannot connect and you see the rule in the iptables list, restart xinetd and immediately tail /var/log/messages as it will note any issues loading the service you created.

13)   Mount the xs-tools.iso and copy the following two files onto the VM.

  • xe-guest-utilities-xenstore-6.0.2-756.x86_64.rpm
  • xe-guest-utilities-6.0.2-756.x86_64.rpm

14)   Eject the ISO and shutdown the VM.

15)   Connect to the XenServer console in XenCenter or ssh to the host.  Get the VMs uuid.  You can also find this on the General tab for the VM in XenCenter.

  • xe vm-list name-label="<vm name in XenCenter>"

16)   Turn off the HVM boot policy.  Note that is a space after HVM-boot-policy.  This clears the value.  If you need to set it back to boot in HVM move, use “BIOS order”.  It is case-sensitive.  If this is your first time using the XenServer CLI, you can hit tab after you start typing the uuid and it will autocomplete.  If it does not the command name is probably mistyped or you are using the wrong type of uuid.  For instance using the VM’s uuid when the command needs the uuid of a VBD on the VM.

  • xe vm-param-set HVM-boot-policy= uuid=<VM uuid>

17)   Set the PV bootload to pygrub.

  • xe vm-param-set PV-bootloader=pygrub uuid=<VM uuid>

18)   Find the VBD uuid for the VM’s disk.

  • xe vm-disk-list uuid=<VM uuid>

19)   Set the VBD to bootable.  Note you are using the VBD uuid here, not the VM or VDI uuid.

  • xe vbd-param-set bootable=true uuid=<VBD uuid>

20)   You should now be able to boot the VM.  None of the previous commands return anything if successful.  If the VM does not boot, check the Log tab on the VM.  If the error is too many bootable disks, make sure to eject the mapped ISO.

21)   Now in the console you may see messages about PCI warnings or BIOS firmware errors.  The normal output of booting is not going to this console.  Just wait and be patient and a login prompt will appear once booting is complete.  Whenever I enable PV mode the keyboard does not work in the console until I close and reopen XenCenter.  Do so once you get the login prompt.

22)   Once logged in browse to where you copied the xs-tools rpms.  Install the rpms in the following order:

  • rpm -ivh xe-guest-utilities-xenstore-6.0.2-756.x86_64.rpm
  • rpm -ivh xe-guest-utilities-6.0.2-756.x86_64.rpm

23)   On the General tab for the VM it will now state that the tools are installed.  After 30s-60s the “Switch to Graphical Console” button will become available.

24)   You are now ready to play with CentOS in PV mode on XenServer.

Update:  To install the tools if you forgot to copy the files before switching to PV mode, log into a terminal session.  Mount the xs-tools.iso in XenCenter.  Immediately tail /var/log/messages to see what device it was added as.  For me it was /dev/xvdd.  Then mount it manually.

  • mount /dev/xvdd /mnt

Don’t forget to un-mount it after you are done.

  • umount /mnt