How to chroot into linux distro on disk when you can't boot via grub

This will restore your grub startup menu

(Apply to debian and derivatives)

Assumption 1: Your distro is installed on /dev/sda1 but is not accessible via grub.
Assumption 2: /dev/sda1 is the root partition, and you do not have a separate boot partition.
Goal: reinstall grub in mbr of /dev/sda:


Boot from livecd or usb, then in the terminal window enter:

$ sudo su
# TARGET=/media/sda1
# mkdir -p $TARGET
# mount /dev/sda1 $TARGET
# mount --bind /dev     $TARGET/dev
# mount --bind /dev/pts $TARGET/dev/pts
# mount --bind /proc    $TARGET/proc
# mount --bind /sys     $TARGET/sys
# cp /etc/resolv.conf    $TARGET/etc/
# chroot $TARGET /bin/bash

This places you in a root terminal on the linux system
Do whatever you want to do there, e.g. re-install grub

# grub-install /dev/sda
# update-grub

To exit from chroot:
Press control-D or enter exit

This brings you back to where you were in the live session and you can unmount

# umount -l $TARGET/dev/pts
# umount -l $TARGET/dev
# umount -l $TARGET/proc
# umount -l $TARGET/sys

Thats it…

Reboot into the your linux distro system on disk.

Edit1: Replaced ‘/usr/bin/bash’ by ‘/bin/bash’.
Edit2: Start with defining TARGET, and reference it in all subsequent lines.
Edit3: Use sudo su in stead of sudo.
Edit4: cp /etc/resolv.conf into the chroot to make apt-get possible.


*English post

0 comentarios:

Publicar un comentario