[CentOS] Filesystems, GRUB, weirdness, oh my! [long]

Drew Weaver drew.weaver at thenap.com
Fri Mar 3 22:29:43 UTC 2006

	I am using SystemImager to auto-install about 500 different
machines, some of them are CentOS; as you can Imagine I want to automate
the installation of the bootloader; so I wrote a 2 scripts to accomplish
this task. Why two? Because some of the machines are IDE, and some of
them are SATA, and I need to be able to use the same disk image on both
of the drive types. Here is the first bash script:

if grep -q sda /proc/diskstats
   MOUNT1="/dev/sda1 /a/boot"
   MOUNT2="/dev/sda3 /a"
   MOUNT1="/dev/hda1 /a/boot"
   MOUNT2="/dev/hda3 /a"
   mount $MOUNT2
   mount $MOUNT1
   MOUNT3="proc /a/proc -t proc -o defaults"
   mount $MOUNT3
   MKSYS="-p /a/sys"
   MOUNT4="sysfs /a/sys -t sysfs -o defaults"
   mkdir $MKSYS
   mount $MOUNT4
   MOUNT5="/dev /a/dev -o bind"
   mount $MOUNT5
   echo "mount $MOUNT2"
   echo "mount $MOUNT1"
   cp /sbin/grubinstall /a/sbin/grubinstall
   chmod 755 /a/sbin/grubinstall
   chmod +x /a/sbin/grubinstall
   chroot /a /sbin/grubinstall
exit 0

What this does is determines whether the drive is SATA or IDE by looking
at diskstats, if it is SATA, it mounts /dev/sda1 & /dev/sda3, if it is
IDE, it mounts /dev/hda1 & /dev/hda3, it also creates and mounts all of
the auxillary filesystems (proc, sys, dev) The next script which I run
in the CentOS environment via chroot is:

if grep -q sda /proc/diskstats
   grub-install --no-floppy --recheck /dev/$TYPE
   sed -i "$SUBS" /boot/grub/menu.lst       
   echo "sed -i $SUBS /boot/grub/menu.lst"
   sed -i "$SUBS" /etc/fstab
   echo "sed -i $SUBS /etc/fstab"
   sed -i "$SUBS" /boot/grub/grub.conf
   echo "sed -i $SUBS /boot/grub/grub.conf"
   sed -i "$SUBS" /etc/grub.conf
   echo "sed -i $SUBS /etc/grub.conf"
   ls "ls -l /etc/grub.conf /boot/grub/grub.conf /boot/grub/menu.lst"
exit 0

By the way /a is the ROOT of the hard drive (freshly imaged) and /a/boot
is the boot partition of the hard drive (freshly imaged).

This script again enumerates the type of hard disk attached to the
system, installs grub on /dev/hda1 or /dev/sda1, modifies
/boot/grub/menu.lst /boot/grub/grub.conf /etc/fstab /etc/grub.conf
sda>hda hda>sda and so forth.

	Everything actually works fine; grub is installed; the files are
all modified appropriately. 

	The issue comes when the newly imaged system comes up. The first
time the system boots up; grub is still configured to boot with
root=/dev/sda3; even though NONE of the configuration files mention
anything about /dev/sda3. However if I hit 'E' and modify the 'kernel
...' line in the grub editor from the bootloader, and allow it to boot
up; the system boots up normally.

	The STRANGE part; is that after the first time it boots off of
/dev/hda3; grub suddenly starts using that EVERY time the system boots;
but I cant figure out why I have to first manually change it; and then
reboot before it will work.

	Its almost like the CentOS boot process 'fixes' whatever is
wrong with grub; the first time it boots after I run my crazy script on
it; but I cant figure out what process during the boot is doing it; or
what else I need to do to ensure trouble free auto-installation of
CentOS, the reason I am asking you all is because that same script
appears to work with a few other distributions.

Any advice anyone can give me would be wonderful.


More information about the CentOS mailing list