Fixing Linux Problems with Chroot

If you want to reset password or fix some booting issue, you may need to boot the server in rescue, then mount old live disks and chroot it. Once it is done, you will be able to run commands like passwd to change password or install any missing software with apt/dnf/yum etc.

To chroot a file system, run

mkdir /mnt
mount /dev/sdc1 /mnt
mount /dev/sdc2 /mnt/boot
cd /mnt
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
mount --bind /dev/pts /mnt/dev/pts/
chroot /mnt

In the above example /dev/sdc1 was / partition. /dev/sdc2 was /boot.

Once you chroot, you can change the root password on the server with the command

passed

If you use LVM for root partition, do

vgscan && vgchange -ay vgubuntu
mount /dev/VG_NAME/root /mnt
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *