Basic System Recovery

When things go wrong, there are ways to fix problems. However, these methods require that you understand the system well. This chapter contains information on common problems you might face and it also describes installation program rescue mode, which can be used to fix these problems.

Common Problems

You might need to boot into installation program rescue mode for any of the following reasons:

  • You are unable to boot into CentOS normally.

  • You are having hardware or software problems, and you want to recover data from your system’s hard drive.

  • You forgot the root password.

Unable to Boot into CentOS

This problem is often caused by the installation of another operating system after you have installed CentOS. Some other operating systems assume that you have no other operating system(s) on your computer. They overwrite the Master Boot Record (MBR) that originally contained the GRUB2 boot loader. If the boot loader is overwritten in this manner, you cannot boot CentOS unless you can boot into installation program rescue mode and reconfigure the boot loader.

Another common problem occurs when using a partitioning tool to resize a partition or create a new partition from free space after installation, and it changes the order of your partitions. If the partition number of your / partition changes, the boot loader might not be able to find it to mount the partition. To fix this problem, you will need to reinstall the boot loader. See Reinstalling the Boot Loader for instructions on how to do this.

Hardware and Software Problems

This category includes a wide variety of different situations. Two examples include failing hard drives and specifying an invalid root device or kernel in the boot loader configuration file. If either of these occur, you might not be able to reboot into CentOS. However, if you boot into installation program rescue mode, you might be able to resolve the problem or at least get copies of your most important files.

Resetting the Root Password

See the corresponding section in the Red Hat Enterprise Linux 7 System Administrator’s Guide.

Anaconda Rescue Mode

The Anaconda installation program’s rescue mode is a minimal Linux environment that can be booted from the CentOS 7.6.1810 DVD or other boot media. It contains command-line utilities for repairing a wide variety of issues. This rescue mode can be accessed from the Troubleshooting submenu of the boot menu. In this mode, you can mount file systems as read-only or even to not mount them at all, blacklist or add a driver provided on a driver disc, install or upgrade system packages, or manage partitions.

Anaconda rescue mode is different from rescue mode (an equivalent to single-user mode) and emergency mode, which are provided as parts of the systemd system and service manager. For more information about these modes, see Red Hat Enterprise Linux 7 System Administrator’s Guide.

To boot into Anaconda rescue mode, you must be able to boot the system using one CentOS boot media, such as a minimal boot disc or USB drive, or a full installation DVD.

For detailed information about booting the system using media provided by CentOS, see the appropriate chapters:

Advanced storage, such as iSCSI or zFCP devices, must be configured using dracut boot options such as rd.zfcp= or root=iscsi:options. It is not possible to configure these storage devices interactively after booting into rescue mode.

For information about dracut boot options, see the dracut.cmdline(7) man page.

Booting into Anaconda Rescue Mode
  1. Boot the system from either minimal boot media, or a full installation DVD or USB drive, and wait for the boot menu to appear.

  2. From the boot menu, either select the Rescue a CentOS system option from the Troubleshooting submenu, or append the inst.rescue option to the boot command line. To enter the boot command line, press the Tab key on BIOS-based systems or the e key on the UEFI-based systems.

  3. If your system requires a third-party driver provided on a driver disc to boot, append the inst.dd=driver_name to the boot command line:

    inst.rescue inst.dd=driver_name

    For more information on using a driver disc at boot time, see Manual Driver Update (x86) for AMD64 and Intel 64 systems or Manual Driver Update (ppc) for IBM Power Systems servers.

  4. If a driver that is part of the CentOS 7.6.1810 distribution prevents the system from booting, append the modprobe.blacklist= option to the boot command line:

    inst.rescue modprobe.blacklist=driver_name

    For more information about blacklisting drivers, see Blacklisting a Driver (x86).

  5. When ready, press Enter (BIOS-based systems) or Ctrl+X (UEFI-based systems) to boot the modified option. Then wait until the following message is displayed:

    The rescue environment will now attempt to find your Linux installation and mount it under the /mnt/sysimage/ directory. 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 line.

    If you select Continue, it attempts to mount your file system under the directory /mnt/sysimage/. If it fails to mount a partition, you will be notified. 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.

  6. 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-4.2#

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

sh-4.2# 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 Anaconda rescue mode by creating a directory, such as /directory/, and typing the following command:

sh-4.2# mount -t xfs /dev/mapper/VolGroup00-LogVol02 /directory

In the above command, /directory/ 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 a different type than XFS, replace the xfs string with the correct type (such as ext4).

If you do not know the names of all physical partitions, use the following command to list them:

sh-4.2# fdisk -l

If you do not know the names of all LVM2 physical volumes, volume groups, or logical volumes, use the pvdisplay, vgdisplay or lvdisplay commands, respectively.

From the prompt, you can run many useful commands, such as:

Reinstalling the Boot Loader

In some cases, the GRUB2 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:

Reinstalling the GRUB2 Boot Loader
  1. Follow instructions in Booting into Anaconda Rescue Mode to boot into Anaconda rescue mode. Ensure that you mount the installed system’s / (root) partition in read-write mode.

  2. Change the root partition:

    sh-4.2# chroot /mnt/sysimage/
  3. Use the following command to reinstall the GRUB2 boot loader, where install_device is the boot device (typically, /dev/sda):

    sh-4.2# /sbin/grub2-install install_device
  4. Reboot the system.

Using RPM to Add, Remove, or Replace a Driver

Missing or malfunctioning drivers can cause problems when booting the system. Anaconda rescue mode provides an environment in which you can add, remove, or replace a driver even when the system fails to boot. Wherever possible, we recommend that you use the RPM package manager to remove malfunctioning drivers or to add updated or missing drivers.

When you install a driver from a driver disc, the driver disc updates all initramfs images on the system to use this driver. If a problem with a driver prevents a system from booting, you cannot rely on booting the system from another initramfs image.

Using RPM to Remove a Driver
  1. Boot the system into Anaconda rescue mode. Follow the instructions in Booting into Anaconda Rescue Mode. Ensure that you mount the installed system in read-write mode.

  2. Change the root directory to /mnt/sysimage/:

    sh-4.2# chroot /mnt/sysimage/
  3. Use the rpm -e command to remove the driver package. For example, to remove the xorg-x11-drv-wacom driver package, run:

    sh-4.2# rpm -e xorg-x11-drv-wacom
  4. Exit the chroot environment:

    sh-4.2# exit

If you cannot remove a malfunctioning driver for some reason, you can instead blacklist the driver so that it does not load at boot time. See Blacklisting a Driver (x86) and Boot Options for more information about blacklisting drivers.

Installing a driver is a similar process but the RPM package must be available on the system:

Installing a Driver from an RPM package
  1. Boot the system into Anaconda rescue mode. Follow the instructions in Booting into Anaconda Rescue Mode. Do not choose to mount the installed system as read only.

  2. Make the RPM package that contains the driver available. For example, mount a CD or USB flash drive and copy the RPM package to a location of your choice under /mnt/sysimage/, for example: /mnt/sysimage/root/drivers/

  3. Change the root directory to /mnt/sysimage/:

    sh-4.2# chroot /mnt/sysimage/
  4. Use the rpm -ivh command to install the driver package. For example, to install the xorg-x11-drv-wacom driver package from /root/drivers/, run:

    sh-4.2# rpm -­ivh /root/drivers/xorg-x11-drv-wacom-0.23.0-6.el7.x86_64.rpm

    The /root/drivers/ directory in this chroot environment is the /mnt/sysimage/root/drivers/ directory in the original rescue environment.

  5. Exit the chroot environment:

    sh-4.2# exit

When you have finished removing and installing drivers, reboot the system.