🐧 Linux Recovery: Using CHROOT to recover a broken Linux installation

🐧 Linux Recovery: Using CHROOT to recover a broken Linux installation

Summary:

We can enable chroot in the recovery console, so customers can start essential services and use it to generate MySQL database backup.

In cases of server crash in Linux, we need to recover data from the machine using the recovery/rescue mode. We can enable chroot in the recovery console, so users can start essential services and use it to generate MySQL database backup.

Initially, when you chroot in recovery console, you will get the following error:

[root@recovery ~]# chroot /mnt

chroot: failed to run command `/bin/bash': No such file or directory

This error means that there is no /bin/bash directory inside chroot. Make sure you point it to where bash (or other shell’s) executable is in chroot directory.

If you have /mnt/somedir/usr/bin/bash then execute chroot /mnt/somedir /usr/bin/bash.

Apart from the above, you also need to add libc directory dependencies, as mentioned in the answer here.

Now, if the machine crashed, follow the steps below to resolve:

mount /dev/vda1 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /bin /mnt/bin


Once it is done, you will be able to chroot to the mounted directory.

chroot /mnt
whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.