Booting into Rescue Mode | Rescue Mode on Linux

Rescue Mode

When things go wrong, there are several ways to work on fixing them. However, they require that you understand the system well.

We will present the ways that you can boot into rescue modes where you can use your own knowledge to rescue the system.

Booting into Rescue Mode

Rescue mode provides the ability to boot a small Red Hat Enterprise Linux environment entirely from CD-ROM, or some other boot method, instead of the system's hard drive.

As the name implies, rescue mode is provided to rescue you from something. During normal operation, your Red Hat Enterprise Linux system uses files located on your system's hard drive to do everything — run programs, store your files, and more.

However, there may be times when you are unable to get Red Hat Enterprise Linux running completely enough to access files on your system's hard drive. Using rescue mode, you can access the files stored on your system's hard drive, even if you cannot actually run Red Hat Enterprise Linux from that hard drive.
To boot into rescue mode, you must be able to boot the system using one of the following methods.
  • By booting the system from an installation boot CD-ROM.
  • By booting the system from other installation boot media, such as USB flash devices.
  • By booting the system from the Red Hat Enterprise Linux CD-ROM #1.
Once you have booted using one of the described methods, add the keyword rescue as a kernel parameter. For example, for an x86 system, type the following command at the installation boot prompt:
        
          linux rescue
        
      
You are prompted to answer a few basic questions, including which language to use. It also prompts you to select where a valid rescue image is located. Select from Local CD-ROM, Hard Drive, NFS image, FTP, or HTTP. The location selected must contain a valid installation tree, and the installation tree must be for the same version of Red Hat Enterprise Linux as the Red Hat Enterprise Linux disk from which you booted.

If you used a boot CD-ROM or other media to start rescue mode, the installation tree must be from the same tree from which the media was created. For more information about how to setup an installation tree on a hard drive, NFS server, FTP server, or HTTP server, refer to the earlier section of this guide.

If you select a rescue image that does not require a network connection, you are asked whether or not you want to establish a network connection. A network connection is useful if you need to backup files to a different computer or install some RPM packages from a shared network location, for example.

The following message is displayed:
        The rescue environment will now attempt to find your Linux installation and mount it under the directory /mnt/sysimage. You can then make any changes required to your system. If you want to proceed with this step choose 'Continue'. You can also choose to mount your file systems read-only instead of read-write by choosing 'Read-only'. If for some reason this process fails you can choose 'Skip' and this step will be skipped and you will go directly to a command shell.
      
If you select Continue, it attempts to mount your file system under the directory /mnt/sysimage/. If it fails to mount a partition, it notifies you. If you select Read-Only, it attempts to mount your file system under the directory /mnt/sysimage/, but in read-only mode. If you select Skip, your file system is not mounted. Choose Skip if you think your file system is corrupted.

Once you have your system in rescue mode, a prompt appears on VC (virtual console) 1 and VC 2 (use the Ctrl-Alt-F1 key combination to access VC 1 and Ctrl-Alt-F2 to access VC 2):
        sh-3.00b#
      
If you selected Continue to mount your partitions automatically and they were mounted successfully, you are in single-user mode.

Even if your file system is mounted, the default root partition while in rescue mode is a temporary root partition, not the root partition of the file system used during normal user mode (runlevel 3 or 5). If you selected to mount your file system and it mounted successfully, you can change the root partition of the rescue mode environment to the root partition of your file system by executing the following command:

        chroot /mnt/sysimage
      
This is useful if you need to run commands such as rpm that require your root partition to be mounted as /. To exit the chroot environment, type exit to return to the prompt.

If you selected Skip, you can still try to mount a partition or LVM2 logical volume manually inside rescue mode by creating a directory such as /foo, and typing the following command:

        mount -t ext3 /dev/mapper/VolGroup00-LogVol02/foo
      
In the above command, /foo is a directory that you have created and /dev/mapper/VolGroup00-LogVol02 is the LVM2 logical volume you want to mount. If the partition is of type ext2, replace ext3 with ext2.

If you do not know the names of all physical partitions, use the following command to list them:
        fdisk -l
      
If you do not know the names of all LVM2 physical volumes, volume groups, or logical volumes, use the following commands to list them:
        pvdisplay
      
        vgdisplay
      
        lvdisplay
      
From the prompt, you can run many useful commands, such as:
  • ssh, scp, and ping if the network is started
  • dump and restore for users with tape drives
  • parted and fdisk for managing partitions
  • rpm for installing or upgrading software
  • joe for editing configuration files

    Note

    If you try to start other popular editors such as emacs, pico, or vi, the joe editor is started.

Reinstalling the Boot Loader

In many cases, the GRUB boot loader can mistakenly be deleted, corrupted, or replaced by other operating systems.

The following steps detail the process on how GRUB is reinstalled on the master boot record:
  • Boot the system from an installation boot medium.
  • Type linux rescue at the installation boot prompt to enter the rescue environment.
  • Type chroot /mnt/sysimage to mount the root partition.
  • Type /sbin/grub-install /dev/hda to reinstall the GRUB boot loader, where /dev/hda is the boot partition.
  • Review the /boot/grub/grub.conf file, as additional entries may be needed for GRUB to control additional operating systems.
  • Reboot the system.

Unable to Boot Linux

Many times this is caused by the installation of another operating system after you've installed Red Hat Linux. Some other operating systems assume that you have no other operating systems on your computer, and overwrite the Master Boot Record (or MBR) that originally contained the LILO bootloader. If LILO is overwritten in this manner, you're out of luck — unless you can get into rescue mode.

Hardware/Software Problems

There can be as many different situations under this category as there are systems running Linux. Things like failing hard drives and forgetting to run LILO after building a new kernel are just two instances that can keep you from booting Red Hat Linux. If you can get into rescue mode, you might be able to resolve the problem — or at least get copies of your most important files.

To boot your system in rescue mode, enter the following parameter at the installation boot prompt:
boot: linux rescue
   
You can get to the installation boot prompt in one of these ways:
  • By booting your system from the diskette or CD-ROM that came with your Red Hat Linux boxed set.
  • By booting from a network or PCMCIA boot diskette. These methods assume your network connection is working and require you to identify the network host and transfer type. For an explanation of how to specify this information, see "Installing over the Network".
Once you have your system in rescue mode, a prompt appears on VC (virtual console) 2 (use the Ctrl-Alt-F2 key combination to access VC 2 :
bash#
   
From this prompt, you can run the commands listed below:
anaconda          gzip        mkfs.ext2   ps
badblocks         head        mknod       python
bash              hwclock     mkraid      python1.5
cat               ifconfig    mkswap      raidstart
chatter           init        mlabel      raidstop
chmod             insmod      mmd         rcp
chroot            less        mmount      rlogin
clock             ln          mmove       rm
collage           loader      modprobe    rmmod
cp                ls          mount       route
cpio              lsattr      mpartition  rpm
dd                lsmod       mrd         rsh
ddcprobe          mattrib     mread       sed
depmode           mbadblocks  mren        sh
df                mcd         mshowfat    sync 
e2fsck            mcopy       mt          tac
fdisk             mdel        mtools      tail
fsck              mdeltree    mtype       tar
fsck.ext2         mdir        mv          touch
ftp               mdu         mzip        traceroute
genhdlist         mformat     open        umount
gnome-pty-helper  minfo       pico        uncpio
grep              mkdir       ping        uniq
gunzip            mke2fs      probe       zcat
   
However, if your root filesystem is undamaged, you can mount it and then run any standard Linux utility. For example, suppose your root filesystem is in /dev/hda5. Here's how to mount this partition:

mount -t ext2 /dev/hda5 /foo
     
Where /foo is a directory that you have created.

Now you can run chroot, fsck, man, and other utilities. At this point, you are running Linux in single-user mode.

If you don't know the names of your Linux partitions, you can guess what they are; mounting non-existent partitions will do no harm.

Booting Single-User Mode Directly

You may be able to boot single-user mode directly. If your system boots, but does not allow you to log in when it has completed booting, try rebooting and specifying one of these options at the LILO boot prompt:

LILO boot: linux single
LILO boot: linux emergency
   
In single-user mode, you computer boots to runlevel 1. Your local filesystems will be mounted but your network will not be activated. You get a usable system maintenance shell.

In emergency mode, you are booted into the most minimal environment possible. The root filesystem will be mounted read-only and almost nothing will be set up. The main advantage of this over linux single is that your init files are not loaded. If init is corrupted or not working, you can still mount filesystems to recover data that could be lost during a re-installation.

A Handy Trick

Have you ever rebuilt a kernel and, eager to try out your new handiwork, rebooted before running LILO? And you didn't have an entry for an older kernel in lilo.conf? Read on…

In many cases, it's possible to boot your Red Hat Linux/Intel system from the Red Hat Linux boot disk with your root filesystem mounted and ready to go. Here's how:

Enter the following command at the boot disk's boot: prompt:
linux single root=/dev/hdXX initrd=
   
(Replace the XX in /dev/hdXX with the appropriate letter and number for your root partition.)
What does this do? First, it starts the boot in single-user mode, with the root partition set to your root partition. The empty initrd specification bypasses the installation-related image on the boot disk, which will cause you to enter single-user mode immediately.

Is there a downside? Unfortunately, yes. Because the kernel on the Red Hat Linux boot disk only has support for IDE built-in, those of you with SCSI-based systems won't be able to use this trick. In that case, you'll have to use the boot/rescue disk combination mentioned above.

0 comments:

Post a Comment