We all make mistakes and this is especially true for novice Linux system administrators. Linux can have a steep learning curve and sooner or later there will be a point in your career where your CentOS installation does not start up due to broad number of reasons, including hardware problems or human mistakes such as configuration errors. If this has happened to you then you can use the CentOS rescue mode in order to boot an otherwise unbootable system and try to undo your mistakes or find out the root of the problems. In this recipe, we will show you three common use cases when to use this option:
To complete this recipe, you will require a standard installation media (CD/DVD or USB device) of the CentOS 7 operating system. For recovering the data from the system, you will need to connect some sort of external storage device to the system, such as an external hard disk or a working network connection to another computer to copy all your precious data to a different location.
To begin this recipe, you should boot your server from the CentOS installation CD/DVD or the USB device and wait until the first welcome splash screen appears with the cursor waiting at the Test this media & install CentOS 7 menu option.
bash-4.2#_
chroot /mnt/sysimage
reboot
If you are now in the rescue mode and need to backup important files from the filesystem, you need a destination location for the data transfer. For transferring the data we want to recover from the server to another computer please physically connect an external USB device to it. You can also use network storages for the recovery. For example, you could import an NFS server share and copy data to it. Refer to the Working with NFS recipe in Chapter 7, Building a Network.
fdisk -l
fdisk -l
command twice, first with the plugged-in USB device and then again with the USB device unplugged, and compare the output of both the commands. It should be different by one device name which you are searching for!mkdir /mnt/hdd-recovery
sdd1
(please change if different on your system):mount /dev/sdd1 /mnt/hdd-recovery
/mnt/sysimage
), if you need to access it for example to change configuration files which caused startup problems or make a full or partial backup. For example, if you need to backup your Apache webserver configuration files, use:cp -r /mnt/sysimage/etc/http /mnt/hdd-recovery
fdisk -l
to identify the partition of interest. Then create a directory and mount the partition to it and change to that directory to access your data similar you did when mounting the USB device.reboot
passwd
reboot
fdisk
command to find the name of all the current partitions. To do this, type the following instruction and then press the Return key to complete your request:fdisk –l
dmesg | grep -Fq "EFI v"
*
symbol in the fdisk
listing in the boot column to find the correct start partition, and assuming that your boot disk is on /dev/sda1
(change this as required), type the following:grub2-install /dev/sda
yum reinstall grub2-efi shim
# this device map was generated by anaconda (hd0) /dev/sda
reboot
There are a broad variety of problems which can be resolved by the tools provided through the rescue mode environment. Often these problems refer to booting problems but can also be from different types, such as forgetting the root password. Rescue mode can be a life-saver and an understanding of it is a very important skill to learn. It was felt that such a recipe should thus remain close at hand.