Saturday, November 14, 2009

A Headless CENTOS Install Using a Netboot Image and VNC

I recently bought an Acer EasyStore H340 server for use as a home file store and media server.  It's a nifty little box, but it's limited by the Windows Home Server installed on it by default.  I decided to load CENTOS on it instead, and this turned out to be a real chore.  There's no video output, save for a non-descript header on the motherboard, and the box will not boot from anything other than the hard disk without tweaking the BIOS, which is kind of hard with no video display.  Undaunted, I found some piecemeal info on the Internet for how to load CENTOS on a headless box like the H340.  Here's what I learned...

  1. Anaconda supports VNC during the CENTOS install, so you can drive the install Q&A from a remote box.
  2. CENTOS 5.3 is a good place to start.  I've seen lots of docs that talk about using 4.6, 5.1, 5.2, 5.3, and 5.4, but I couldn't get 5.4 to work right.  It wouldn't build a bootable image.  CENTOS 5.3 worked quite nicely.
  3. Creating a bootable USB stick or USB HDD is pretty simple -- assuming you're not running CENTOS 5.4.  Really, try 5.3 instead.
  4. You probably still want a video card for diagnostics later on, but you can get it up and running if you need to without the video!

Here's the process I followed...

  1. Download the CENTOS 5.3 Live CD and the full ISO image.  If you can mount and/or burn the DVD flavor, I recommend it.  Otherwise the install media is 6 CD's; the DVD is so much easier.
  2. Fire up the Live CD and open up a terminal window once Gnome is loaded.  Save lots of headaches by becoming root.  Type "sudo su -" at the command prompt.
  3. Make sure the syslinux package is installed (it should be) by typing "yum list | grep syslinux".  If you need it, connect to your network and run "yum install syslinux".
  4. Pop in your USB stick or whatever media you intend to use for the install.  If it doesn't automount, run dmesg and look at the last few lines of output to see what the device is called (e.g., /dev/sdb).  If it does automount, make note of the device name, then unmount any and all partitions that automounted.  For the rest of this discussion, we'll assume the device was /dev/sdb.
  5. Run fdisk on the device (e.g., fdisk /dev/sdb) and wipe out any old filesystems on the device.  Then create a single primary partition of roughly 20MB.  Label the partition as "Win95 VFAT" (label "b") and toggle the boot flag active.  Write the changes and quit.
  6. Create the filesystem and write the syslinux data to the new partition and the master boot record:
    mkfs.vfat -n BOOT /dev/sdb1
    syslinux -s /dev/sdb1
    dd if=/usr/lib/syslinux/mbr.bin of=/dev/sdb

  7. Now, time to copy some files.  If your new partition didn't automount, mount it manually and cd to the directory where you mounted it.  Then copy the isolinux/ folder from the Live CD to the new partition you created in the syslinux/ folder.  Something like this:
    mount /dev/sdb1 /mnt/usb
    cd /mnt/usb
    cp -rv /mnt/livecd/isolinux/ ./syslinux/
  8. Now cd to the syslinux folder you just created and remove the isolinux.bin file.
  9. Rename isolinux.cfg to syslinux.cfg.  Now it's time to do some editing...
The syslinux.cfg file looks something like this:

default vesamenu.c32
timeout 100


menu background splash.jpg
menu title Welcome to CentOS-5.3-i386-LiveCD!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 5
label linux0
  menu label Boot CentOS-5.3-i386-LiveCD
  kernel vmlinuz0
  append initrd=initrd0.img root=CDLABEL=CentOS-5.3-i386-LiveCD rootfstype=iso9660 ro quiet liveimg
menu default
label linuxtext0
  menu label Boot CentOS-5.3-i386-LiveCD (text mode)
  kernel vmlinuz0
  append initrd=initrd0.img root=CDLABEL=CentOS-5.3-i386-LiveCD rootfstype=iso9660 ro quiet liveimg 3
label installer
  menu label Network Installation
  kernel vminst
  append initrd=install.img text
label memtest
  menu label Memory Test
  kernel memtest
label local
  menu label Boot from local drive
  localboot 0xffff

Most of it is unnecessary for our purposes.  All of the "label" sections can go except for the "label installer" section.  All of the "menu" statements can go.  Change the default from vesamenu.c32 to installer, change the timeout to 0, and set a new value "prompt" to 0 as well.  Now it should look like this:

default installer
timeout 0
prompt 0


label installer
  menu label Network Installation
  kernel vminst
  append initrd=install.img text

Now we need to add some detail to the append line.  The settings below will assign an IP address of 192.168.100.100/24 to the install host and will open a VNC connection to 192.168.100.5.  The install host will also pull the CENTOS image from an HTTP server also at 192.168.100.5:

default installer
timeout 0
prompt 0


label installer
  menu label Network Installation
  kernel vminst
  append initrd=install.img text ramdisk_size=8192 vnc vncconnect 192.168.100.5 headless ip=192.168.100.100 netmask=255.255.255.0 gateway=192.168.100.1 ksdevice=eth0 method=http://192.168.100.5/centos lang=en_US keymap=us

Save the file, sync the filesystem, and unmout the device.

Now open up your favorite VNC client in listening mode.  Pop the USB stick on the machine you want to build. Power on the machine and force it to boot from the USB stick.  After a few minutes, you should see the CENTOS loader pop up on your VNC client.  And there you have it!