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:
boot from livecd or usb
in terminal window:
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 #! system
Do whatever you want to do there, e.g. re-install grub
grub-install /dev/sda update-grub
To exit from chroot:
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
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.
Edit3: Use sudo su in stead of sudo
Edit4: cp /etc/resolv.conf into the chroot to make apt-get possible
Last edited by xaos52 (2013-02-28 12:42:45)
i hope it doesn't, but when it does, i bet it this will prove useful one day. thanks!
Nice! This should go up on the wiki ASAP.
This just saved my A## - thanks - should be a sticky ?
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!
edit: whew, that was easy! thanks for the great explanation xaos, really useful, made my day!
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.
Do not keep us in suspense any longer, rhowaldt.
How did it go?
Oops - missed that.
First message on forum just to say: thank you! You saved my life!
By the way, I am loving #!
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 ... ?
Last edited by CBizgreat! (2012-05-06 23:23:23)
^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.
Last edited by CBizgreat! (2012-05-07 00:23:19)
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 !
Last edited by CBizgreat! (2012-05-07 12:35:06)
Me again ... Xaos ya saved my arse again ... You're da man ... again !
This time dorking around with display managers. Things went a tad wrong, Xaos handy chroot how to and a "dpkg-reconfigure gdm" and was back in bizness ! Anyway ... yet again, thanks for taking the time to write/post this.
^ x12 for good add ...
This info has already saved me a ton of time, headache and/or buttache. Thanks to one of the nix wizards here in Crunch-academy. Professor Xaos.
Last edited by CBizgreat! (2012-05-30 07:41:35)
Last edited by pidsley (2012-07-02 16:47:49)
sudo cp /etc/resolv.conf $TARGET/etc/resolv.conf
mount: unknown filesystem type 'LVM2_member'
Perhaps it should be:
Last edited by mariannemarlow (2012-09-09 22:01:09)
Between two evils, I always pick the one I never tried before ~ Mae West