Hi, this script modify a grub configuration to launch in the next reboot a CentOS 6 netinstall in graphical mode.
I hope it will be useful for your business.
Regards!
I hope it will be useful for your business.
Regards!
Code:
#!/bin/bash
clear
echo
echo "Network Boot Install Script for CentOS"
echo "(c) alexsmith.im 2009-2010"
echo
echo "This script gives you the ability to install and use the VNC based network installer built into the"
echo "CentOS and Fedora Core network images."
echo
echo "It will walk you through your settings and reboot the server when required, please only run this script"
echo "if you are happy to lose the contents of this machines hard drive(s)"
echo
echo "This script comes without guarantee that it will work if it breaks your server I cannot be held responsible"
echo "I have tested it on my servers and it works without issue, if you do find a bug please report it"
echo "to me via my site at http://alexsmith.im - Thanks"
echo
echo " Please choose one of the following options"
echo
echo "A) Install CentOS 6.x 32 Bit"
echo "B) Install CentOS 6.x 64 Bit"
echo "X) Quit this installer"
echo
echo -n "Select an option and hit [ENTER]: "
read option
rm -rf /setup
mkdir /setup
cd /setup
case "$option" in
"a" | "A" )
echo
echo "Installing CentOS 6 32 Bit"
wget -4 -q http://mirror.ovh.net/ftp.centos.org/6/os/i386/images/pxeboot/initrd.img -O /setup/initrd.img
wget -4 -q http://mirror.ovh.net/ftp.centos.org/6/os/i386/images/pxeboot/vmlinuz -O /setup/vmlinuz
mirror="http://mirror.ovh.net/ftp.centos.org/6/os/i386/"
;;
"b" | "B" )
echo
echo "Installing CentOS 6 64 Bit"
wget -4 -q http://mirror.ovh.net/ftp.centos.org/6/os/x86_64/images/pxeboot/initrd.img -O /setup/initrd.img
wget -4 -q http://mirror.ovh.net/ftp.centos.org/6/os/x86_64/images/pxeboot/vmlinuz -O /setup/vmlinuz
mirror="http://mirror.ovh.net/ftp.centos.org/6/os/x86_64/"
;;
"x" | "X" )
echo "Quitting"
exit
;;
esac
echo
echo "Detecting required system settings..."
gateway=`netstat -nr | grep UG | awk '{print $2}'`
echo "Gateway detected as $gateway"
ip=`ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -d : -f 2`
echo "IP detected as $ip"
echo
echo
echo "This password is purely for VNC access and it doesn't like long ones"
echo -n "So please enter a SHORT (6 chars or less) password for VNC and hit [ENTER]: "
read password
cp /setup/initrd.img /boot/pxe.initrd.img
cp /setup/vmlinuz /boot/pxe.vmlinuz
echo
echo "Forcing install of Grub..."
yum install grub -y > /dev/null
echo "Creating boot menu..."
if [ -s /boot/grub/menu.lst ]
then
rm /boot/grub/menu.lst
fi
# Make menu.lst with correct settings
cat > /boot/grub/menu.lst << DELIM
default 0
timeout 5
title PXE Install Boot
root (hd0,0)
kernel /boot/pxe.vmlinuz vnc vncpassword=$password headless ip=$ip netmask=255.255.255.0 gateway=$gateway dns=8.8.8.8 ksdevice=eth0 method=$mirror lang=en_US keymap=us
initrd /boot/pxe.initrd.img
DELIM
if [ -s /boot/grub/grub.conf ]
then
rm /boot/grub/grub.conf
cp /boot/grub/menu.lst /boot/grub/grub.conf
fi
echo "Installing Grub to the first disk..."
grub-install /dev/sda > /dev/null
echo "Checking Grub Install..."
grub-install --recheck /dev/sda > /dev/null
echo
echo "PRE-SETUP COMPLETE"
echo
echo "Once the server is rebooted VNC will start up and you will be able to carry on the install as normal"
echo "This includes doing your partitioning and installing your packages"
echo
echo "You will be able to connect to the VNC Server using $ip:1 as the host"
echo
echo "The reboot can take a few minutes, depending on the speed of your server and if the mirror is busy"
echo "If you would like to reboot the server now to start the installation of your server please hit [ENTER] now, otherwise press ctrl+c"
read -s
echo "Rebooting!"
reboot