Topic: How to chroot into #! on disk when you can not boot via grub

How to chroot from live session to #! on disk

Assumption: #! is installed on /dev/sda1 but is not accessible via grub
Goal: reinstall grub in mbr of /dev/sda:
Here goes:
boot from livecd or usb
in terminal window:

TARGET=/media/sda1
sudo mkdir -p $TARGET
sudo mount /dev/sda1 $TARGET
sudo mount --bind /dev     $TARGET/dev
sudo mount --bind /dev/pts $TARGET/dev/pts
sudo mount --bind /proc    $TARGET/proc
sudo mount --bind /sys     $TARGET/sys
sudo chroot $TARGET /bin/bash

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

grub-install /dev/sda
update-grub

To exit from chroot:

control-D

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

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

Thats it...
Reboot into the #! system on disk.

Edit1: Replaced '/usr/bin/bash' by '/bin/bash'
Edit2: Start with defining TARGET, and reference it in all subsequent lines.

Last edited by xaos52 (2012-03-26 16:30:46)

If you poke the bear it is going to come after you.

Re: How to chroot into #! on disk when you can not boot via grub

i hope it doesn't, but when it does, i bet it this will prove useful one day. thanks!

Re: How to chroot into #! on disk when you can not boot via grub

Nice! This should go up on the wiki ASAP.

Re: How to chroot into #! on disk when you can not boot via grub

This just saved my A## - thanks - should be a sticky ?

Re: How to chroot into #! on disk when you can not boot via grub

^ It is in Quick References and will be added to the Wiki

Re: How to chroot into #! on disk when you can not boot via grub

today is the day i'll be making use of this. just installed Win7 on another partition because i need to test some audio-issues i'm having (try and determine whether it is a Linux problem or not..). of course it has messed up my MBR, so i'll be using chroot for the first time ever! this calls for celebration! smile

edit: whew, that was easy! thanks for the great explanation xaos, really useful, made my day!

Re: How to chroot into #! on disk when you can not boot via grub

Some days ago I made a typo in /etc/default/grub
Had to chroot into #! and used something similar...
As I have an encrypted root partition I first had to open and mount that one as well. When this is done the steps are the same as described above.

Re: How to chroot into #! on disk when you can not boot via grub

Do not keep us in suspense any longer, rhowaldt.
How did it go? smile

If you poke the bear it is going to come after you.

Re: How to chroot into #! on disk when you can not boot via grub

^ i already made an edit to my post! check it:

edit: whew, that was easy! thanks for the great explanation xaos, really useful, made my day!

in other words: everything went smooth as a baby's butthole.

Re: How to chroot into #! on disk when you can not boot via grub

Oops - missed that.

If you poke the bear it is going to come after you.

Re: How to chroot into #! on disk when you can not boot via grub

First message on forum just to say: thank you! You saved my life! big_smile
By the way, I am loving #!

Re: How to chroot into #! on disk when you can not boot via grub

redman wrote:

First message on forum just to say: thank you! You saved my life! big_smile

In general, if you do get into trouble, dr xaos will be the one to bail you out. He's the problem solver here.

Re: How to chroot into #! on disk when you can not boot via grub

Another thank you Xaos ...

Nothing borked here. But was really wanting to know how to do something like this and hadn't been able to trackdown any good how to's for it. So definitely bookmarked and appreciated. Know where to come, if needing this done. This would work w most Debian OS's and deriviatives too ... ?


(CB) smile

Last edited by CBizgreat! (2012-05-06 23:23:23)

Some common cbiz abbreviations. This will save me time and yet @ same time tell folks what the babble is supposed to mean.

Vll ! = ( Viva la gnu/Linux !)    Vl#!! = ( Viva la #! !)    Last but not least, UD ... OD ! = ( Use Debian ... or die !) tongue

Re: How to chroot into #! on disk when you can not boot via grub

CBizgreat! wrote:

This would work w most Debian OS's and deriviatives too ... ?

This will work with any distro using Grub2, so everything based on Debian and Ubuntu. If a distro uses Grub1 (grub legacy), only the last bit needs to be changed, though Grub1 rarely breaks, if ever.

Re: How to chroot into #! on disk when you can not boot via grub

^Thanks El_ it's always appreciated when more experienced nixers clarify. More interested in possibly having to change files on harddisk from live session, so a better idea of how to do this could really help out sometime.


Vll ! smile

Last edited by CBizgreat! (2012-05-07 00:23:19)

Some common cbiz abbreviations. This will save me time and yet @ same time tell folks what the babble is supposed to mean.

Vll ! = ( Viva la gnu/Linux !)    Vl#!! = ( Viva la #! !)    Last but not least, UD ... OD ! = ( Use Debian ... or die !) tongue

Re: How to chroot into #! on disk when you can not boot via grub

el_koraco wrote:
redman wrote:

First message on forum just to say: thank you! You saved my life! big_smile

In general, if you do get into trouble, dr xaos will be the one to bail you out. He's the problem solver here.

Along with an incredible amount of information and fellow doctor's on the Quick Reference page.. cool

Re: How to chroot into #! on disk when you can not boot via grub

VastOne wrote:
el_koraco wrote:
redman wrote:

First message on forum just to say: thank you! You saved my life! big_smile

In general, if you do get into trouble, dr xaos will be the one to bail you out. He's the problem solver here.

Along with an incredible amount of information and fellow doctor's on the Quick Reference page.. cool

Yes, indeed. This forum and all the info posted by the community it's of great help in everything. It's one of the best characteristics of #!

Re: How to chroot into #! on disk when you can not boot via grub

Ok it's official ... add me to the list of folks whose arse Xaos saved w this how to ...

At the risk of getting added to El_'s and BlackIvans PLONK list. Funny story ... a dork ( who shall remain nameless) decides why da heel not. Time to give it a try ... installs Arch. Spends HOURS 1/2 learning way around, get's brilliant idea. Ha ! It'll save me some time if I just copy over some fluxbox config files to this new install ... Yeah !

And everything was going great, dork was very pleased w himself. Until he borked up the .fluxbox keys file and the wm went to shat ! Arghhhh ... being still nix newbish, didn't know how to fixy, though sure there are plenty of ways and gdm was set up for autologin. To a fluxbox that wasn't there ! Arghhhh again ! In a nix newb frenzy x dork tried to just reinstall fluxbox, then in an ever desperate dorkish frenzy ... uninstalled fluxbox altogether, the only wm installed at the time and gdm didn't like it at all. Reboot ... gdm login screen ... nothing to log into ... And so was up chit creek.

So ... what ends up happening. Dork follows Xaos handy how to for chroot ( w a friggin LM10 livecd of all things), makes it into Arch root terminal and whamo ... reinstalls fluxbox w it. To @ least enable dork to get back in and in grand newb style fix the borkage w/o having to spend FRIGGIN HRS reinstalling and config'in.

So THANK YOU Xaos ... You're da man ! wink


(CB)

Last edited by CBizgreat! (2012-05-07 12:35:06)

Some common cbiz abbreviations. This will save me time and yet @ same time tell folks what the babble is supposed to mean.

Vll ! = ( Viva la gnu/Linux !)    Vl#!! = ( Viva la #! !)    Last but not least, UD ... OD ! = ( Use Debian ... or die !) tongue