Friday 27 June 2014

GRUB Troubleshooting – 5

GRUB Troubleshooting – 5

--> How do I change a forgotten root password?
We can change root password from either single user mode or rescue mode. The method for booting into single user mode depends on your bootloader:
GRUB – No password protection
Booting into single user mode using GRUB is accomplished by editing the kernel line of the boot configuration. This assumes that either the GRUB boot menu is not password protected or that you have access to the password if it is.
When the system boots up, you will see the GRUB countdown, which is set to 5 seconds by default . Press “Esc” to intercept this countdown and go enter a GRUB menu. Then follow these steps:
Press ‘e’ to start editing.
Scroll down to the “kernel…” line. This line tells GRUB which kernel to boot.
Press ‘e’ again to edit this line.
Move to the end of the line. Add the number “1″ to the end.
Once you have finished that change, press Enter to accept the edit.
Press ‘b’ to boot using that kernel and boot into runlevel 1 (single user mode).
Change the root password when the “#” prompt appears by using the “passwd” command.
Note: The switch to runlevel 1 is not persistent. At next boot, the system will start in default runlevel as specified in the /etc/inittab file.
GRUB – Password protection
If the GRUB boot menu is password protected and you do not have access to the password, you will need to use a rescue disk to boot the system.
Follow the instructions given by the rescue disk boot process:
Boot the system from boot disc 1. Once the system has successfully booted from the ISO image and the Red Hat Enterprise Linux boot screen appears, type “linux rescue” without the quotes at the boot prompt and press the enter key.
[F1-Main] [F2-Options] [F3-General] [F4-Kernel] [F5-Rescue]
boot: linux rescue
When prompted for language and keyboard, provide the pertinent information for the system. When prompted to enable the network devices on the system, select “No”.
Select “Continue” when prompted to allow the rescue environment to mount the Red Hat Enterprise Linux installation under the /mnt/sysimage directory.
Run the command “chroot /mnt/sysimage” to change root to your system image.
Use the command “passwd” to change the root password of the system.
--> How do I reinstall a corrupted boot partition in Red Hat Enterprise Linux?
In a system where the “/boot” partition is a separate partition, when /boot is corrupted or be formatted mistakenly, you can not boot the system but do not want to reinstall the whole system.
Reinstall /boot partition manually with the following steps:
1. Boot the system into rescue mode:
Insert the Red Hat Enterprise Linux CD #1 and boot your system. At boot prompt, type “linux rescue”. This will start the rescue mode program.
You will be prompted for your keyboard and language requirements. Enter these values as you would during the installation of Red Hat Enterprise Linux.
Next, a screen will appear telling you that the program will now attempt to find a Red Hat Enterprise Linux installation to rescue. Select “Continue” on this screen.
At the “sh-3.1″ prompt, chroot to /mnt/sysimage:
# chroot /mnt/sysimage
2. Make sure the boot partition is labeled as described in /etc/fstab. (Assuming the boot partition is /dev/sda1):
# e2label /dev/sda1 /boot
3. Make sure the boot partition is mounted:
# mount /dev/sda1 /boot
4. Mount the CD to install the following rpms:
# mkdir /mnt/iso
# mount -o loop,ro /dev/hdc /mnt/iso
# cd /mnt/iso/Server
# rpm -Uvh –replacefiles –replacepkgs grub-0.97-13.i386.rpm
# rpm -Uvh –replacefiles –replacepkgs redhat-logos-4.9.16-1.noarch.rpm
# rpm -ivh –replacefiles –replacepkgs kernel-2.6.18-8.el5.i686.rpm
5. Install the GRUB:
# grub-install /dev/sda
6. If /boot/grub/grub.conf is lost, you need to create it manually. The following is a sample of grub.conf, please make sure the the file “vmlinuz-2.6.18-8.el5″ and “initrd-2.6.18-8.el5.img” exist under the directory of /boot (which should be installed after step 4).
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.18-8.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/
initrd /initrd-2.6.18-8.el5.img
7. Make a soft link to grub.conf:
# cd /boot/grub
# ln -s grub.conf menu.lst
Then you can reboot your system.
--> How to disable hyperthreading if GRUB is the boot loader?
During the boot sequence you can add an option to the kernel line.
In the GRUB menu, select the kernel to boot into.
Type ‘e’ to modify the kernel arguments before booting.
Add a space then type ‘noht’ at the end of the line.
Hit return to boot with this options.
Type ‘b’ to boot to this kernel.
Permanently
Edit the /etc/grub.conf file.
Find the kernel line that you want to modify.
Add noht to the kernel line. For example:
title Red Hat Enterprise Linux Server (2.6.18-8.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/vg0/lv0 noht
initrd /initrd-2.6.18-8.el5.img
--> How do I turn SELinux off during GRUB booting?


During the boot sequence you can add an option to the kernel line.
In the GRUB menu, select the kernel to boot into.
Type ‘e’ to modify the kernel arguments before booting.
Add a space then type ‘noht’ at the end of the line.
Hit return to boot with this options.
Type ‘b’ to boot to this kernel.
Permanently
Edit the /etc/grub.conf file.
Find the kernel line that you want to modify.
Add noht to the kernel line. For example:
title Red Hat Enterprise Linux Server (2.6.18-8.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/vg0/lv0 rhgb quiet selinux=0
initrd /initrd-2.6.18-8.el5.img
--> How to display the booting log on the display always?
If the kernel entry has “rhgb” and “quiet” at the end of the line, you wont see the boot log. To enable boot log, just modify the entries as below
Before:
title Red Hat Enterprise Linux AS (2.6.9-89.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-89.ELsmp ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.9-89.ELsmp.img
After:
title Red Hat Enterprise Linux AS (2.6.9-89.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-89.ELsmp ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.9-89.ELsmp.img

Wednesday 18 June 2014

GRUB Troubleshooting – 4

GRUB Troubleshooting – 4

--> Grub Boot Fails with Following Error : Error 15: File not found  & Error 17: Cannot mount selected partition
1) At the grub screen, press ‘c’ to enter command line mode
2) Tell grub to search for the grub boot files.
grub> find /grub/stage1
if no disks are returned in step 2, it indicates that grub is unable to mount and find the files. rescue mode will be required to repair the file-system and grub boot files.
Grub will attempt to access the disk listed in the ‘root’ parameter for the bootloader files (/boot/grub).
If the ‘root’ device is incorrect, or the device is inaccessible, an error will be displayed.
3) Note the disk that is returned. Usually, this will be (hd0,0)
4) Press ‘esc’ to return to the menu
5) Press ‘e’ to enter the configuration menu
6) Press ‘e’ on the root parameter, and adjust the line to match the disk that was returned earlier. Press return to save the changes.
root (hd0,0)
7) Press ‘b’ to boot with the new configuration
8) Once the machine is booted, modify the /boot/grub/grub.conf file to make the change permanent
root(hd0,0)
--> How do we activate power management or Advanced Power Management (APM) , from GRUB?
APM packages are available only for 32 bit machine. The apmd package is very old and it has replaced by “acpi”(Advanced Configuration and Power Interface) package. The acpid daemon works to control the power of the devices.
Activating APM:  Advanced Power Management features (APM) can be activated on your system by starting the APM daemon (apmd). To start this immediately, use the service command:
# service apmd start
To ensure that this daemon is enabled across reboots, use the chkconfig command:
# chkconfig apmd on
Note: In order to execute these commands, user has to be the root user.
Confirm that APM was activated :
#dmidecode | grep -i apm
#service apmd status
#/etc/init.d/apmd status
#ps aux | grep apmd
#pstree -paul| grep apmd
 
Disabling  APM:
On 32bit machine you can pass the apm parameter and its value to the kernel to disable it during booting. Just the add the “apm=off” at the end of the line contains “kernel” in the grub.conf file.
Sample grub.conf entries it will look like
default=1
timeout=7
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux AS (2.4.21-20.EL)
root (hd0,0)
kernel /vmlinuz-2.4.21-20.EL ro root=LABEL=/
apm=off
initrd /initrd-2.4.21-20.EL.img
title Red Hat Enterprise Linux AS (2.4.21-20.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.4.21-20.ELsmp ro root=LABEL=/
apm=off
initrd /initrd-2.4.21-20.ELsmp.img
And on that same machine you also need to disable the apmd daemon at the chkconfig service like :
#chkconfig apmd off
#service apmd stop
--> System kernel panics on boot with “mount: could not find filesystem ‘/dev/root’”.
System kernel panics on boot with the following information after loading GRUB and starting the boot process:
Unable to access resume device (/dev/rootvg/swap)
mount: could not find filesystem ‘/dev/root’
setuproot: moving /dev failed: no such file or directory
setuproot: error mounting /proc: no such file or directory
setuproot: error mounting /sys: no such file or directory
switchroot: mount failed: no such file or directory
kernel panic – no syncing: attempted to kill init!
This issue can occur when a yum install of a new kernel is interrupted, the initrd won’t be properly rebuilt for the new kernel resulting in many problems at boot.
 Rollback to the previously installed kernel by booting into the older kernel via the GRUB bootloader. Press any key when “Starting Red Hat Enterprise Linux in 5 seconds…” appears. Then once inside of GRUB use the arrow keys to navigate down to the second line and press the ‘b’ key to boot into the selected kernel.
To make the second kernel the default edit /boot/grub/grub.conf and modify the line default= to read:
default=1
If the above works try re-installing the kernel with yum by first removing the new kernel and then installing it. For example to reinstall the 2.6.18-308.8.1 kernel:
# yum -y remove kernel-2.6.18-308.8.1.el5.x86_64
# yum -y install kernel-2.6.18-308.8.1.el5.x86_64


Friday 13 June 2014

GRUB Troubleshooting – 3

GRUB Troubleshooting – 3

--> How do I change the default kernel in GRUB that is loaded at startup?
Use the command grubby –bootloader-probe to find out which bootloader you have installed. Then, assuming it is GRUB, edit the file /etc/grub.conf as described below. First, an example GRUB configuration file:
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Enterprise Linux ES (kernel number zero)
root (hd0,0)
kernel /vmlinuz-zero ro root=/dev/hard_drive
initrd /initrd-zero.img
title Red Hat Enterprise Linux ES (kernel number one)
root (hd0,0)
kernel /vmlinuz-one ro root=/dev/hard_drive
initrd /initrd-one.img
title Red Hat Enterprise Linux ES (kernel number two)
root (hd0,0)
kernel /vmlinuz-two ro root=/dev/hard_drive
initrd /initrd-two.img
In this example file, notice the line at the top that reads default=0. The number 0 (zero) indicates which stanza to select by default. A stanza is the indented portion after the line starting with title. GRUB will then use this default stanza to boot, after a number of seconds has passed (specified in the line timeout=10). The 0 (zero) in this case is referring to the first stanza that starts with “title Red Hat Enterprise Linux ES (kernel number zero)”. It includes all of the indented lines up to but not including the next “title” line.
For example, if you instead wanted the second stanza, “title Red Hat Enterprise Linux ES (kernel number one)”, to be the default, then you would change the default line to:
default=1
Once you have made this change, save the grub.conf file. You do not need to reload GRUB for the changes to take effect. The next time you boot, your changes will take effect, but once the file is saved, the changes are effective.
--> How to install GRUB on a disk image file?
Image files are representations of block devices. Each image can be used as a hard disk for virtualized guests under Xen or KVM. During booting, if GRUB bootloader cannot recognize a boot partition installed a virtual machine for any reason, need to re-install GRUB on that image file. It will be especially useful when trying to migrate a physical machine to a virtual machine using a disk image file from scratch.
Assumptions: There is a disk image file, so-called virtual-disk.img, for virtual machines. The image has beed made well including a proper kernel version and other system packages. To build a disk image file, refer the How can I create sparse files under Red Hat Enterprise Linux?
Before installing GRUB, get partition information from the image.
# losetup /dev/loop1 /var/lib/libvirt/images/virtual-disk.img
# fdisk -ul /dev/loop1
Disk /dev/loop1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x722fd0f4
Device Boot Start End Blocks Id System
/dev/loop1p1 63 1060289 530113+ 82 Linux swap
/dev/loop1p2 1060290 16771859 7855785 83 Linux
# losetup -d /dev/loop1
In this example, virtual-disk.img is consists of two partitions and is 8GiB in total size. Now install GRUB to the image file:
# grub –device-map=/dev/null
This will open up a GRUB prompt. Enter the following:
grub> device (hd0) /var/lib/libvirt/images/virtual-disk.img
grub> root (hd0,1)
grub> setup (hd0)
grub> quit
Note: do not use the loopback device to install GRUB bootloader because GRUB has a bug when given a loopback device.
--> How do I configure GRUB to see all of my physical memory?
You can specify the amount of memory on your system if your computer is not recognizing all of it. For example if your system says you only have 128 MB of RAM and you know for sure you have 256 MB, then you can specify that in your grub.conf file, located at /boot/grub/grub.conf.
This is what a normal grub.conf file looks like:
# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda2
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Enterprise Linux AS (2.4.21-15.EL)
root (hd0,0)
kernel /vmlinuz-2.4.21-15.EL ro root=LABEL=/
initrd /initrd-2.4.21-15.EL.img
title Red Hat Enterprise Linux AS (2.4.21-9.EL)
root (hd0,0)
kernel /vmlinuz-2.4.21-9.EL ro root=LABEL=/
initrd /initrd-2.4.21-9.EL.img
What you want to do is add the following syntax mem=<###>M to the kernel line of your grub.conf file. So for instance if you were specifying your system had 256 MB in the grub.conf file, it would look something like this:
# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda2
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Enterprise Linux AS (2.4.21-15.EL)
root (hd0,0)
kernel /vmlinuz-2.4.21-15.EL ro root=LABEL=/
mem=256M
initrd /initrd-2.4.21-15.EL.img
title Red Hat Enterprise Linux AS (2.4.21-9.EL)
root (hd0,0)
kernel /vmlinuz-2.4.21-9.EL ro root=LABEL=/
mem=256M
initrd /initrd-2.4.21-9.EL.img


Thursday 12 June 2014

Bash Exercises – 11

Bash Exercises – 11

Script 49: High CPU Usage Script |
At times, we need to monitor the high CPU usage in the system. We can use the below script to monitor the high CPU usage.
 #!/bin/bash   
  while [ true ] ;do   
  used=`free -m |awk 'NR==3 {print $4}'`   
  if [ $used -lt 1000 ] && [ $used -gt 800 ]; then   
  echo "Free memory is below 1000MB. Possible memory leak!!!" | /bin/mail -s "HIGH MEMORY ALERT!!!" user@mydomain.com   
  fi   
  sleep 5   
  done   

Script 50: Add new user |
This script allows the root user or admin to add new users to the system in an easier way by just typing the user name and password (The password is entered in an encrypted manner).
 #!/bin/bash  
 # Script to add a user to Linux system  
 if [ $(id -u) -eq 0 ]; then  
   read -p "Enter username : " username  
   read -s -p "Enter password : " password  
   egrep "^$username" /etc/passwd >/dev/null  
   if [ $? -eq 0 ]; then  
     echo "$username exists!"  
     exit 1  
   else  
     pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)  
     useradd -m -p $pass $username  
     [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"  
   fi  
 else  
   echo "Only root may add a user to the system"  
   exit 2  
 fi  
Script 51: Database Backup |
This script is a pretty basic script useful in backing up the database.
 #!/bin/sh  
 now="$(date +'%d_%m_%Y_%H_%M_%S')"  
 filename="db_backup_$now".gz  
 backupfolder="/var/www/vhosts/example.com/httpdocs/backups"  
 fullpathbackupfile="$backupfolder/$filename"  
 logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt  
 echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"  
 mysqldump --user=mydbuser--password=mypass --default-character-set=utf8 mydatabase | gzip > "$fullpathbackupfile"  
 echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"  
 chown myuser "$fullpathbackupfile"  
 chown myuser "$logfile"  
 echo "file permission changed" >> "$logfile"  
 find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} \;  
 echo "old files deleted" >> "$logfile"  
 echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"  
 echo "*****************" >> "$logfile"  
 exit 0  

Wednesday 11 June 2014

Bash Exercises - 10

Bash Exercises - 10

Script 46: Bulk user creation |

This script is used to create number of users at a time.
 #!/bin/bash  
 HOSTS="/tmp/test/serverlist"  
 DDID="IDENTIFY"  
 HOMEPATH="/home/$UNAME"  
 for i in `cat $HOSTS` ;  
 do  
 UNIQUE=`awk -F " " '{print $1 }' $DDID`  
 RUID=`ssh $i 'grep "$UNIQUE" /etc/passwd'`  
 if [[ -ne "$RUID" ]]  
     then  
         echo "User ID is currently available on $i, ready to add new user"  
         UNAME=`awk -F " " '{print $2 }' $DDID`  
         PASSWORD=`awk -F " " '{print $3 }' $DDID`  
         ROLE=`awk -F " " '{print $4 }' $DDID`  
         `ssh $i useradd -u "$UNIQUE" -d "$HOMEPATH" -s /bin/bash -c "$ROLE" -m -k /etc/skel/ "$UNAME"`  
         `ssh $i echo "$PASSWORD" | passwd --stdin "$UNAME"`  
 else  
         echo "User ID exist on $i, check new ID"  
 fi  
 done  

Script 47: Disk usage |
This script will be useful to analyze the disk usage and if the reported disk space is more than 90 % an email will be sent to the administrator.

 #!/bin/sh  
 # set -x  
 # Shell script to monitor or watch the disk space  
 # It will send an email to $ADMIN, if the (free available) percentage of space is # >= 90%.  
 # -------------------------------------------------------------------------  
 # Set admin email so that you can get email.  
 ADMIN="root"  
 # set alert level 90% is default  
 ALERT=90  
 # Exclude list of unwanted monitoring, if several partions then use "|" to  
 # separate the partitions.  
 # An example: EXCLUDE_LIST="/dev/hdd1|/dev/hdc5"  
 EXCLUDE_LIST="/auto/ripper"  
 #  
 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  
 #  
 function main_prog() {  
 while read output;  
 do  
 #echo $output  
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)  
  partition=$(echo $output | awk '{print $2}')  
  if [ $usep -ge $ALERT ] ; then  
    echo "Running out of space \"$partition ($usep%)\" on server $(hostname), $(date)" | \  
    mail -s "Alert: Almost out of disk space $usep%" $ADMIN  
  fi  
 done  
 }  
 if [ "$EXCLUDE_LIST" != "" ] ; then  
  df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | main_prog  
 fi  
Script 48: Incremental Backup Scripts |
This script will do the incremental backup into an external mounted hard-drive. It is to take a backup of the /home directory. However, it can be modified to suit the requirements.

 #!/bin/bash  
 # ----------------------------------------------------------------------  
 # mikes handy rotating-filesystem-snapshot utility  
 # ----------------------------------------------------------------------  
 # this needs to be a lot more general, but the basic idea is it makes  
 # rotating backup-snapshots of /home whenever called  
 # ----------------------------------------------------------------------  
 unset PATH # suggestion from H. Milz: avoid accidental use of $PATH  
 # ------------- system commands used by this script --------------------  
 ID=/usr/bin/id;  
 ECHO=/bin/echo;  
 MOUNT=/bin/mount;  
 RM=/bin/rm;  
 MV=/bin/mv;  
 CP=/bin/cp;  
 TOUCH=/bin/touch;  
 RSYNC=/usr/bin/rsync;  
 # ------------- file locations -----------------------------------------  
 MOUNT_DEVICE=/dev/hdb1;  
 SNAPSHOT_RW=/root/snapshot;  
 EXCLUDES=/usr/local/etc/backup_exclude;  
 # ------------- the script itself --------------------------------------  
 # make sure we're running as root  
 if (( `$ID -u` != 0 )); then { $ECHO "Sorry, must be root. Exiting..."; exit; } fi  
 # attempt to remount the RW mount point as RW; else abort  
 $MOUNT -o remount,rw $MOUNT_DEVICE $SNAPSHOT_RW ;  
 if (( $? )); then  
 {  
   $ECHO "snapshot: could not remount $SNAPSHOT_RW readwrite";  
   exit;  
 }  
 fi;  
 # rotating snapshots of /home (fixme: this should be more general)  
 # step 1: delete the oldest snapshot, if it exists:  
 if [ -d $SNAPSHOT_RW/home/hourly.3 ] ; then     \  
 $RM -rf $SNAPSHOT_RW/home/hourly.3 ;        \  
 fi ;  
 # step 2: shift the middle snapshots(s) back by one, if they exist  
 if [ -d $SNAPSHOT_RW/home/hourly.2 ] ; then     \  
 $MV $SNAPSHOT_RW/home/hourly.2 $SNAPSHOT_RW/home/hourly.3 ; \  
 fi;  
 if [ -d $SNAPSHOT_RW/home/hourly.1 ] ; then     \  
 $MV $SNAPSHOT_RW/home/hourly.1 $SNAPSHOT_RW/home/hourly.2 ; \  
 fi;  
 # step 3: make a hard-link-only (except for dirs) copy of the latest  
 # snapshot, if that exists  
 if [ -d $SNAPSHOT_RW/home/hourly.0 ] ; then     \  
 $CP -al $SNAPSHOT_RW/home/hourly.0 $SNAPSHOT_RW/home/hourly.1 ; \  
 fi;  
 # step 4: rsync from the system into the latest snapshot (notice that  
 # rsync behaves like cp --remove-destination by default, so the   
 # destination is unlinked first. If it were not so, this would copy over   
 # the other snapshot(s) too!  
 $RSYNC               \  
   -va --delete --delete-excluded       \  
   --exclude-from="$EXCLUDES"       \  
   /home/ $SNAPSHOT_RW/home/hourly.0 ;  
 # step 5: update the mtime of hourly.0 to reflect the snapshot time  
 $TOUCH $SNAPSHOT_RW/home/hourly.0 ;  
 # and thats it for home.  
 # now remount the RW snapshot mountpoint as readonly  
 $MOUNT -o remount,ro $MOUNT_DEVICE $SNAPSHOT_RW ;  
 if (( $? )); then  
 {  
   $ECHO "snapshot: could not remount $SNAPSHOT_RW readonly";  
   exit;  
 } fi;  

Monday 9 June 2014

GRUB Troubleshooting 2


GRUB Troubleshooting 2
How to  Disable  fsck  of file systems from the grub menu?
At the grub prompt edit the boot parameters.
This is usually done by pressing e at the menu.
At the end of the ‘kernel’ line add ‘fastbootwithout the quotation marks. This is what skips the filesystem check.
Exit the grub mode and  boot the system.




How to Configure one time use of Specific Kernel Entry to boot,  in Grub Menu ?  
Using grub Command:
# grub
grub> savedefault –stage2=/boot/grub/stage2 –default=2 –once
Or invoking grup from a shell script:
# echo “savedefault –stage2=/boot/grub/stage2 –default=1 –once” | grub
Please notice that savedefault does not change the grub.conf, it just change the binary code within stage2 file /boot/grub/stage2.




Grub not starting the count down of Timeout value during booting, and we have to hit enter manually to boot from default kernel.
Either Hardware Clock of the Server not working, or had not working. Fixing the Hardware clock should resolve the issue.




How to find nextboot order when using grub “savedefault” option?
Use the below command to know the next boot order set with save default option
# xxd /boot/grub/stage2 |awk ‘ /0000200/ {print $8}’




How to boot into single user mode using the GRUB bootloader?
Single user mode can be accessed by appending an “S”, “s”, or “single” to the kernel command line in GRUB. To do this, restart the system and when the GRUB splash screen presents itself:
Select/highlight the desired kernel using the up/down arrow keys.
Press the letter a to modify the kernel line.
On the new screen, press the spacebar to add a space, then type the letter s and press Enter.
This will boot the system into single user mode, i.e. the boot process will stop immediately after execution of rc.sysinit and present a root BASH shell.
Note:
Adding “S”, “s”, or “single” to the kernel command-line tells the kernel to to have init drop to a root shell after rc.sysinit finishes. This allows one to get into the system without a password and bypass any problems with services.
Adding “1″ to the kernel command-line seems to do basically the same as above, but in reality init also kicks off rc for runlevel 1 before dropping to a root shell. This means that in runlevel 1, there could possibly be some services running (if they were configured in /etc/rc1.d).




How Troubleshoot the if the server hangs at GRUB prompt during boot?
Sometime, when SAN disks connected to the system were detected before the local hard disk. And the the local hard disk will be recognized as /dev/sdg instead of /dev/sda so the GRUB pointed to wrong device to boot from.To Diagnosis and troubles we can use the below guidelines
1. Boot  into Rescue mode, using CD#1 or Network Boot
boot: linux rescue
If your installation images reside on an FTP, HTTP or NFS server on your network, you need to enable it.Then, the rescue environment will ask if you wish to mount filesystems.
Select “Continue” to mount the filesystems in /mnt/sysimage with read-write mode. Now, you can access a minimal shell.
2. chroot the / filesystem
Before we troubleshoot GRUB, we change system environment so that  the grub-install command thinks your root filesystem is the /mnt/sysimage directory. Below command explains the procedure
# mount -t proc none /mnt/sysimage/proc
# mount -o bind /dev /mnt/sysimage/dev
# mount -o bind /sys /mnt/sysimage/sys
# chroot /mnt/sysimage
Verify that /boot is available:
# ls -l /mnt/sysimage/boot
To make sure where the GRUB bootloader was previously installed, check the ‘#boot=’ line in the configuration file:
# head /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,1)
# kernel /boot/vmlinuz-version ro root=/dev/hda2
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
3. Execute grub-install command for the / filesystem.
In this case it is in the MBR of the sda device, To restore the bootloader, execute:
# grub-install /dev/sda
4. Reboot the system
5. When you see GRUB splash screen, hit space key
6. Highlight the server title line, for example “Red Hat Enterprise Linux Server-base (2.6.18-53.el5)” , then type c key to drop into the command line.
7. At the grub prompt, use find command to find out which device has a kernel image (vmlinuz) and driver image (initrd).
If your system has a separate /boot partition, type
grub> find /initrd-2.6.18-53.el5.img
(hd0,0)
If your system does NOT have a separate /boot partition, type
grub> find /boot/initrd-2.6.18-53.el5.img
(hd0,0)
8. Using the device name found in the step 7, set up root as “hd0,0″.
grub> root (hd0,0)
9. Set up kernel image AND the location of / filesystem. This should look like the kernel line in /boot/grub/grub.conf.
If your system has a separate /boot partition, type
grub> kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/1 rhgb quiet
If your system does NOT have a separate /boot partition, type
grub> kernel /boot/vmlinuz-2.6.18-53.el5 ro root=LABEL=/1 rhgb quiet
10. Set up driver image (initrd).
If your system has a separate /boot partition, type
grub> initrd /initrd-2.6.18-53.el5.img
If your system does NOT have a separate /boot partition, type
grub> initrd /boot/initrd-2.6.18-53.el5.img
11. Type boot command to boot with the setting made above steps.
grub> boot