How to chroot into a Linux drive

Chrooting can be super useful for changing things like the root password, repairing grub bootloader etc., things that require the system to be mounted.  Typically if your chrooting into an OS drive you can boot up on a Live Linux distro, or use the Rescue feature on some Linux installers.

Mount main drive

Change sdb2 to the root partition of your drive.

mount /dev/sdb2 /mnt

Mount other stuff

mount -t proc none /mnt/proc
mount -o bind /dev /mnt/dev
mount -o bind /sys /mnt/sys
mount -o bind /run /mnt/run

If you want to, you can mount the boot partition.  Change sdb1 if your boot partition is something else.  For efi, you may need to mount the boot partition then mount the efi partition inside /boot/efi.

mount /dev/sdb1 /mnt/boot

Chroot

 chroot /mnt

You should now be inside the chroot environment.  To exit the chroot, hit control+d or type exit.

If your having issues resolving DNS refer to this post.

Leave a Reply

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