Bienvenido! - Willkommen! - Welcome!

Bitácora Técnica de Tux&Cía., Santa Cruz de la Sierra, BO
Bitácora Central: Tux&Cía.
Bitácora de Información Avanzada: Tux&Cía.-Información
May the source be with you!

Sunday, November 6, 2011

How to chroot Ubuntu using Live CD

to fix GRUB rescue prompt
Black God june 2010
(adapted with my example)

Recently I messed up GRUB boot loader in my laptop installed with Ubuntu which resulted in grub rescue prompt. So I had to boot Ubuntu Live CD to get it fixed. Thought of blogging it, may be useful for some one.
This fix involves two steps. First one is to chroot into Ubuntu installation partition. Second one is to install the grub MBR (Master Boot Record). I am using Ubuntu Lucid 10.04 and Live CD also of same.
Step-1: Boot your machine with Ubuntu Live CD and select  
Trying Ubuntu without installation option when it is prompted (Live CD mode)
Step-2: Be patient till you get complete desktop ready.
Step-3: Ubuntu main menu - Places - Home Folder
Look for other partitions listed on left hand side pane.
Mount one by one and identify your Ubuntu root partition. When you are in your root partition, press Ctrl+L to view the complete mount path. Press Ctrl+C to copy this path. This path is normally /media/xx..xx kind of long path, where xx..xx denotes your hard disk partition unique id.
If you know your Ubuntu root partition you can replace the above GUI step-3 with simple mount command like this (Applications - Accessories - Terminal) [or Ctrl + Alt + T]:
$ sudo mount /dev/sda7 /mnt/myroot 
sudo mount /dev/sda2 /mnt/myroot/boot
sudo mount /dev/sda8 /mnt/myroot/home
[where sda7 is your root partition (and if separated)
sda2 your boot partition and sda8 your home partition]
Forget the special case above (Not mounted partitions at myroot) and let’s say you have mounted root partition at /media/xx..xx.
Step-4: Run the terminal through Applications - Accessories - Terminal.
Step-5: Run the following commands to export the pseudo file system of Live CD to your would be root file system soon.
$ sudo mount ‐‐bind /dev /media/xx..xx/dev
$ sudo mount ‐‐bind /proc /media/xx..xx/proc
$ sudo mount ‐‐bind /sys /media/xx..xx/sys
Step-6: Changing the root file system of live system to your hard disk installed root file system.
$ sudo chroot /media/xx..xx
Step-7: Installing GRUB Boot record in Master Boot record of your hard disk. My hard disk is sda. Replace your hard disk device node in the following command.
$ sudo grub-install /dev/sda
Step-8: Reboot the Live Ubuntu. Eject the CD.
Now you should get boot menu for your Ubuntu installation back. Enjoy the Ubuntu!
Note: How to get it done without Live CD which includes GRUB2 rescue prompt
Related content:
How to fix GRUB rescue prompt without Live CD? (For GRUB2)
How to safely remove ubuntu in dual boot installation
Ubuntu 6.06 installation on Legacy PC (low RAM)
HOWTO: /dev file system in chroot-ed environment
Boot CDROM through GRUB
==========================11.04 - How to chroot Ubuntu
What is the recommended way to use chroot from Ubuntu 11.04 with Ubuntu 11.10?
Linked (but probably separate) is "Is there anything special that I need to do in order to get Xorg working?"
Reason I ask is because I'd like to test a few GTK3 programs without losing my current (stable) Ubuntu, or having to get my data synced.

Could you please tell us why exactly you are doing this? 
You can chroot, but all that will do is change your root to 11.10. init/kernel/kernel modules will still have run from 11.04, so you won't really be running 11.10. This could be useful if you're trying to install grub or something from 11.10, but otherwise it's just silly.
In order to chroot to do things like.. configure/install grub, do the following-
#first, mount new install to /mnt/oneiric
mount -t proc proc /mnt/oneiric/proc
mount -t sysfs sys /mnt/oneiric/sys
mount -o bind /dev /mnt/oneiric/dev
chroot /mnt/oneiric /bin/bash
I wouldn't try to start full gnome this way.
The only reason you should really be doing this is if you can't boot into the linux installation for some reason, but still need to run a few things from it. You can't just chroot over and change the distro you're running. 

No comments: