Monday, March 16, 2009

Restoring the MBR on RHEL/CentOS servers

It happens that the MBR is getting bad (after os updates/power failures, etc)
We can restore it in a few minutes if we have a RHEL/CentOS install CD at hand, or if we have a PXE server nearby.

Boot the system from the install cd,
at the boot prompt choose:
text rescue

After booting the rescue system, perform the following commands (actually only the chroot and grub-install may be needed, but sometimes the rescue system does not see all devices under the mounted system tree):
chroot /mnt/sysimage
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /dev
mkdir dev/pts
mount -t devpts devpts /dev/pts
/sbin/udevstart
/sbin/grub-install hd0
quit
quit

The system will reboot, and hopefully all will work right away.
If it doesn't - you will need to dig further :)
P.S - Don't sue me if these commands do some nasty things to your server ;)

Wednesday, March 4, 2009

Quick shell script to convert ifcfg-ethX-rangeY to ifcfg-ethX:Y format

Quick shell script to convert ifcfg-ethX-rangeY to ifcfg-ethX:Y format:
for i in `ls ifcfg-eth1-range*`; 
do
. ./$i
D1=`echo $IPADDR_START|cut -d. -f4`;
D2=`echo $IPADDR_END|cut -d. -f4`;
D=`expr $D2 - $D1`;
echo $D;
S=`echo $IPADDR_START|cut -d. -f1,2,3`;
for j in `seq 0 $D`;
do
echo "DEVICE=eth1:`expr $j + $CLONENUM_START`
BOOTPROTO=static
ONBOOT=yes
IPADDR=$S.`expr $D1 + $j`
NETMASK=$NETMASK" > ifcfg-eth1:`expr $j + $CLONENUM_START`;
done
done