Let's do this backwards. Get the machine to image off an HTTP server and then change the ks.cfg:
#url --url http://1.2.3.4/rhel6Notice that I'm telling the machine that its image is on sdb, not sda. Providing two drives is safer that trying to image off the boot/root drive, but it could be a partition on the same drive. Besides, I've got dozens of little drives laying around doing nothing. Further down in the file, I also indicated:
harddrive --partition=/dev/sdb1 --dir=/
#clearpart --all
clearpart --drives=sda
Next, we mount the second drive and copy the ISO into the root of the drive. To clarify:
mount /dev/sdb1 /mntWhen kickstarting from a local drive, we use the ISO file itself... not an extracted or loop mounted filesystem. Looking back at the first change we made to the ks.cfg, we indicated --dir=/, so we are telling the installer that the ISO is on the top level of the drive.
cp rhel-6-x86_64-dvd.iso /mnt/
As a matter of convenience, mount the ISO, because we need a few files from it:
mkdir /mnt/rhel6Copy three files:
mount rhel-6-x86_64-dvd.iso /mnt/rhel6 -o loop
mkdir /mnt/imagesIf you were going to allow the machine to rebuild different versions (or distros) you would want to add a version number to each file.
cp /mnt/rhel6/images/install.img /mnt/images
cp /mnt/rhel6/isolinux/vmlinuz /mnt/images
cp /mnt/rhel6/isolinux/initrd.img /mnt/images
To initiate the rebuild, we will use the tried and true Grub rebuild hack:
cd /bootMany docs indicate that the second drive has to be made bootable. In this case, we are still booting off the primary drive, but only long enough to read the ks.cfg from sdb and switch to install.img. Once install.img has control, it will read the clearpart command, wipe sda, and reinstall from sdb.
cp /mnt/images/vmlinuz /boot
cp /mnt/images/initrd.img /boot
cat >> /boot/grub/grub.conf << EOF
title Rebuild
root (hd0,0)
kernel /vmlinuz ramdisk_size=8192 ks=hd:sdb1/ks/ks.cfg
initrd /initrd.img
EOF
There is a "gotcha" I've not quite worked out yet. As we all know, Linux is notorious for renaming drive letters at boot time. It is possible that the machine might confuse sda and sdb. This could be disastrous if the machine crashed, and while trying to rebuild, it wiped the image drive! The good news is that the installer reports that it can't find the image and kickstart file, and fails. Just reboot until it finds the correct drive.
* It would seem that either a UUID or LABEL could be used in both Grub and the kickstart file. I'll add checking those possibilities to my ToDo list. Or you could figure that part out and let me know which works. Its only fair: I've already done the hard part for you.
No comments:
Post a Comment