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
1 2 3 4 5 6 7 8 9 |
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 above example /dev/sdc1 was / partiition. /dev/sdc2 was /boot.
Once you chroot, you can change root password on the server with the command
1 |
passed |
If you use LVM for root partition, do
1 2 |
vgscan && vgchange -ay vgubuntu mount /dev/VG_NAME/root /mnt |