Script for Centos install with VNC and network images

This script allows you to install Centos 6.5 or Centos 7 with VNC and network images. Read the script carefully and do any change that suit you.

Why do you need this? Because not every hosting company offer you an original kernel distribution. So, you can install any centos distribution offered by your hosting provider and run this script for a good and original centos kernel.

#!/bin/bash
clear

echo
echo " Please select one of the following options"
echo
echo "a) Install CentOS 6.5 64 Bit"
echo "b) Install CentOS 7   64 Bit"
echo "x) Quit this installer"
echo
echo -n "Select an option and hit [ENTER]: "
read option

cd /tmp

case "$option" in

    "a" | "A" )
    
        echo
        echo "Installing CentOS 6.5 64 Bit"
        wget -4 -q http://mirror.ovh.net/ftp.centos.org/6/os/x86_64/images/pxeboot/initrd.img -O /tmp/initrd.img
        wget -4 -q http://mirror.ovh.net/ftp.centos.org/6/os/x86_64/images/pxeboot/vmlinuz -O /tmp/vmlinuz
        mirror="http://mirror.ovh.net/ftp.centos.org/6/os/x86_64/"
        ;;
    
    "b" | "B" )
    
        echo
        echo "Installing CentOS 7 64 Bit"
        wget -4 -q http://mirror.ovh.net/ftp.centos.org/7/os/x86_64/images/pxeboot/initrd.img -O /tmp/initrd.img
        wget -4 -q http://mirror.ovh.net/ftp.centos.org/7/os/x86_64/images/pxeboot/vmlinuz -O /tmp/vmlinuz
        mirror="http://mirror.ovh.net/ftp.centos.org/7/os/x86_64/"
        ;;
        
    "x" | "X" )
    
        echo "Quitting"
        exit
        ;;
        
esac

echo
echo "Detecting required system settings..."
gateway=`/sbin/ip route | awk '/default/ { print $3 }'`
echo "Gateway detected as $gateway"
ip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
echo "IP detected as $ip"
netmask=`ifconfig | grep 'Mask:'| grep -v '127.0.0.1' | cut -d: -f4 | awk '{ print $1}'`
echo "Netmask detected as $netmask"
# If you are in a openvz container try
#netmask=`ifconfig | grep 'Mask:'| grep -v '127.0.0.1' | cut -d: -f5 | awk '{ print $1}'`
dns=`cat /etc/resolv.conf | grep nameserver | head -1 | perl -lpe's/nameserver\s+//'`
echo "DNS detected as $dns"

echo 
echo 
echo "This password is for VNC client access" 
echo -n "Enter a password (max. 6 chars) for VNC and hit [ENTER]: "
read password

cp /tmp/initrd.img /boot/pxe.initrd.img
cp /tmp/vmlinuz /boot/pxe.vmlinuz

echo
echo "Installing Grub..."
yum install grub -y > /dev/null

echo "Creating boot menu.lst..."
if [ -s /boot/grub/menu.lst ]
then 
    rm /boot/grub/menu.lst
fi

# Create menu.lst
#If you dont now what to put instead hd0 go and check here: nano /boot/grub/device.map (could be fd0 if you are in a container openvz) or run:
#grub
#grub>find /grub/stage1
#grub>quit
#If you are in a openvz container instead ksdevice=eth0 put ksdevice=venet0:0
#read more about (hd0,1) here http://wiki.centos.org/HowTos/GrubInstallation
cat > /boot/grub/menu.lst << DELIM
default 0
timeout 5
title PXE Install Centos
root (hd0,1)
kernel /boot/pxe.vmlinuz vnc vncpassword=$password headless ip=$ip netmask=$netmask gateway=$gateway dns=$dns 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

#If you dont now what to put instead /dev/sda go and check here: nano /boot/grub/device.map
#Read http://wiki.centos.org/HowTos/GrubInstallation
echo "Installing Grub to the disk..."
grub-install /dev/sda > /dev/null
echo "Checking Grub Install..."
grub-install --recheck /dev/sda > /dev/null

echo
echo "DONE"
echo
echo "Install on your desktop a VNC viewer (VNC client). You can find one here https://www.realvnc.com/download/viewer/"
echo
echo
echo "After server reboot start your VNC viewer an connect to the VNC server using ip-server:1 as the host and password you put above"
echo
echo
echo "Now you can reboot your server"

Leave a Reply

Your email address will not be published. Required fields are marked *