HOWTO: CentOS 5 Medialess Remote Install Over VNC

| |

There have been a few occasions where I have wanted to install CentOS on a remote machine that already had a working flavor of Linux on it. Luckily RHEL / CentOS has a way to do this.

Basic Steps

  1. Download the PXE CentOS kernel and initrd image
  2. Configure the bootloader to boot the CentOS kernel by default
  3. Configure the bootloader with extra parameters for networking and remote VNC
  4. Reboot the machine
  5. Run the vncviewer in listen mode with port 5500 accessible

Download the kernel and initrd image

Login to the remote machine and use curl (or wget if you prefer) to download the needed kernel and initrd images and place them in the /boot directory:

cd /boot
curl -o vmlinuz-centos
curl -o initrd-centos.img

If you want the i386 flavor rather than the x86_64 flavor, replace x86_64 with i386.

Updating GRUB

Now that you the minimal pieces of the CentOS installer you have to update the bootloader configuration to give it enough information so the machine can get on the network and find the rest of the CentOS installer pieces. The following CentOS kernel parameters do the work for you:

vncconnect={IP address of machine where you will run vncviewer in listen mode}
ip={IP address for the remote machine}
netmask={netmask for the remote machine}
gateway={gateway IP address for the remote machine}
dns={IP address for the DNS server}
hostname={desired FQDN} 
ksdevice={name of network device}
method={URL to parent directory of images/state2.img}
lang={proper language code}
keymap={proper country code}

Putting it all together into into your bootloader config (usually /boot/grub/menu.list or /etc/grub.conf which may be a symlink):

title Remote CentOS Install
   root (hd0,0)
   kernel /vmlinuz-centos vnc vncconnect=n.n.n.n headless ip=n.n.n.n 
     netmask=n.n.n.n gateway=n.n.n.n dns=n.n.n.n hostname=x ksdevice=eth0 
     method= lang=en_US keymap=us
   initrd /initrd-centos.img

Please note that grub details may vary from machine to machine so use your existing, working stanzas as a guide with regards to the boot path and the boot drive device. If the specifics of your machine do not match my example, you are going to have to alter these instructions some to match your environment.

Of course you would replace you the "n.n.n.n" with the correct IP addresses and x with the desired hostname. The URL I gave for the method would work for the x86_64. If you'd prefer the i386 flavor, replace x86_64 with i386.

For a more readable output I wrapped the kernel line into three lines but it is really one line. Line 1 begins with "title", line 2 begins with "root", line 3 begins with "kernel", and line 4 begins with "initrd".

You'll want to browse to the URL with your web browser to verify that it is still available and that it hasn't changed after this article was published... or perhaps you want to use a different URL for a closer mirror or even your own local mirror. What you are looking for is the path that contains an images directory inside of which is a state2.img file.

If your remote machine does not use a static IP address but uses DHCP instead, the recipe is a little different. In the case of DHCP you can leave off the netmask, gateway, and dns parameters and just replace "ip=n.n.n.n" with "ip=dhcp".

Look it over carefully and makes sure you got everything perfect. If you have a mistake it will most likely make your install fail without an easy way to recover.

Make sure to set the default= to the proper value that matches the new stanza you added so it will boot it automatically. Look everything over one more time to make sure you got it just perfect and once you are satisfied, reboot the machine with a shutdown -r now.

Running vncviewer

Your remote system will then reboot, boot the new kernel setup, get on the network, download the second stage installer from the CentOS mirror site, and then attempt to connect to vncviewer on your local machine. For your local machine to answer you have to run "vncviewer --listen". In order for that to work, you must have port 5500 open on your local machine so it can receive the VNC display from the remote machine. Of course you want to have all of this setup and ready to go on your local machine before you reboot your remote machine because you only have a minute or two after rebooting before the server tries to do the VNC connection.

It's All Downhill Now

Assuming you got your grub configuration just right, vncviewer running just in time, and your iptables firewall didn't block the connection, you should receive a VNC window with the initial CentOS installer screen. Now you can drive the installation with your mouse just like you would a local install.

As you are probably already aware, the Internet is not perfect and there is a possibility you could have a network glitch in the middle of your install and loose your connection. That is not a good situation expecially if it has gotten far enough where it has wiped the drive and is in the middle of installing... so make sure to cross your fingers... and in case of a disconnect, have the ability for a remote human assist if possible. I've actually done a few remote installs with one being completely across the country and I haven't yet gotten disconnected.

Before You Try It

I strongly recommend you do a few trial runs with some machines on your own local area network before you attempt a remote machine install. Chances are you will make a mistake or two before you have this install method well understood. Trying it out with some local machines so you can see the displays will help you understand exactly what the remote machine does and the order it does it... and the exact formats for all of the keywords and values. For more info see the Advanced Options section of the RHEL 5 Install Guide or this article from Red Hat Magazine.

Good luck with your install journeys!