Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown   Email 


( See UPDATE because of change to udev below )

With the “chroot” command you can log in as root in another distro located on a different partition so you can give commands as root, as if you were actually booted in that other distro.
This is handy for repair jobs, but also for example if your MBR is messed up and you only have a Live CD you can boot from.
In this example we want to restore Mandrake´s lilo to the MBR and Mandrake is on hda7. We boot from the Live CD ( or any other distro on the same computer ) and issue the following commands:

First we make sure we are root:

$ su
< password >

Then we mount the Mandrake partition:

# mount /dev/hda7 /mnt/hda7

( this assuming that /mnt/hda7 does exist, if not we have to do “mkdir /mnt/hda7” first )

Also we have to mount /dev/pts and /proc

# mount -t devpts none /mnt/hda7/dev/pts
# mount -t proc none /mnt/hda7/proc

( NOTE: /dev/pts is only Mandrake, other distro's just use /dev without the pts )

Now we can chroot:

# chroot /mnt/hda7

( NOTE: The prompt will change to show you that you are on a different filesystem )

And give the command to write the Mandrake lilo to MBR:

# /sbin/lilo -b /dev/hda

Log out of the chroot environment:
< Ctrl+D >
And we are “normal” root again.

We unmount the previously mounted partitions:

# umount /mnt/hda7/dev/pts
# umount /mnt/hda7/proc
# umount /mnt/hda7

And reboot to see the MBR working again:

# reboot

Hope you will never need this and always have a boot-floppy or boot-CD ready, but in case even those fail . . . . . . .


UPDATE: Because of the recent switch to "udev" in PCLos and Mandrake there are 2 changes in the above:
In Mandrake /devpts is gone, so only proc has to be mounted
In PCLos the /dev line changed to "mount -t none /dev /dev/hda7/dev -o bind"

-- Jan 6 2004 ( Revised Dec 13 2005 ) --

Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown   Email