LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-13-2009, 04:54 AM   #1
GTrax
Member
 
Registered: Oct 2005
Location: UK
Distribution: Mint
Posts: 258

Rep: Reputation: 37
Messing with a distro's files -- from within another distro.


For various reasons, I keep several distros each on their own partition. The first one to be booted from the master boot record is set up to have its GRUB bootloader offer a "chainloader +1" link to point at the others.

The most common need to mount and tweak stuff in other partitions is usually to edit something like a /etc/X11/xorg.conf to get the display to work, or maybe to retrieve files that were downloaded while working in the "other" distro, but what if one wants to do a real repair?

I know, from an earlier exploration of Gentoo, that one can "chroot" into a different environment, and then proceed to install, remove,compile, configure, (and possibly completely wreck!) the other distro content, all from within a "foreign" terminal.

So the question - is there a reasonably generic recipe that would enable one to sneak in to a distro from outside, and then do real serious stuff like "apt-get --uninstall xorg", all from within a desktop maintaining the handy connection to the internet, Google, manuals, FAQ's and suchlike useful stuff?
 
Old 06-14-2009, 06:43 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Quote:
Originally Posted by GTrax View Post
I know, from an earlier exploration of Gentoo, that one can "chroot" into a different environment, and then proceed to install, remove,compile, configure, (and possibly completely wreck!) the other distro content, all from within a "foreign" terminal.

So the question - is there a reasonably generic recipe that would enable one to sneak in to a distro from outside, and then do real serious stuff like "apt-get --uninstall xorg", all from within a desktop maintaining the handy connection to the internet, Google, manuals, FAQ's and suchlike useful stuff?
It seems to me that the first paragraph has already answered the question in the second one. Or is there something I'm missing here?
 
Old 06-14-2009, 07:27 AM   #3
GTrax
Member
 
Registered: Oct 2005
Location: UK
Distribution: Mint
Posts: 258

Original Poster
Rep: Reputation: 37
Thanks for your reply

The key phrase was "reasonably generic recipe". For the adventure with Gentoo, it was never going to matter if I got it wrong, since I could always reformat the partition, copy in the distro, and start configuring again. The list of commands I used included things that might not be universal to other distro's. They went like this..

$ sudo su
<password>
# mkdir /mnt/sda6
# mkdir /mnt/gentoo
# mount /dev/sda6 /mnt/gentoo
# cd /mnt/gentoo

Ensure networking still works even after entering the new environment

# cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
# mount -t proc none /mnt/gentoo/proc
# mount -o bind /dev /mnt/gentoo/dev

# chroot /mnt/gentoo /bin/bash

At this point, the prompt changes colour.. then we had to do

# env-update
>> Regenerating /etc/ld.so.cache...
# source /etc/profile
# export PS1="(gentoo)$PS1"

At this point it was possible to do things like use the Portage package manager, compile, etc. though I have no idea which kernel was actually doing the work at the time.

So .. what might it take to get into say a Sidux or Ubuntu environment from outside? You can understand why I would ask here before I try it. I don't really want to break installations just because of experimenting with chroot. This time, they are not an educational dabble.
 
Old 06-14-2009, 03:53 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I believe chroot uses your host system's currently running kernel with the target system's environment. Running 'uname -a' inside the chroot should tell you what you're running (unless both systems are running exactly the same kernel, that is).

Actually, I really don't know all that much about the ins-and-outs of chroot myself. There may just be too many variables and different needs for there to be any single "global" sequence that will work on all systems. However, I'm sure a lot of it will be similar in most situations. Of course once you know how to properly chroot into any single system, then you can easily set up a script to automate the process.

The only thing I've used chroot for myself is to rescue systems when something has broken them, such as bad mbr or failed update. In these cases I would boot up a live distro, mount the root partition, bind /dev, /sys, and /proc to the respective locations inside of it, and chroot in to do the repairs. That's as far as my experience goes.

(These days I mostly use systemrescuecd instead, which has options such as booting directly into an installed system using the kernel supplied on the disk.)

As for doing damage, I don't think the chroot itself does anything except shift you into the target system's working environment. It's the commands you run while inside the chroot that affect things. Most probably the worst that will happen is that some things fail because you don't have the chrooted environment set up properly (but don't trust me on that).

Anyway, you've already shown that you can safely chroot into a system and run complex commands in it, so what specifically are you worried about doing wrong?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Atheros AR5007EG using Mint vs. messing with GRUB and some other distro bobbygrimlock Linux - Networking 1 04-02-2009 12:55 AM
rebooting directly to another distro from current distro's logout window newbiesforever Linux - Distributions 1 09-28-2008 02:53 PM
reinstalling a distro's bootloader from another distro newbiesforever Linux - General 3 11-12-2007 11:58 AM
messing with udev and rc files props666999 Slackware 14 03-04-2007 07:38 PM
booting multiple distro's with a mini-distro SVN Linux - General 1 04-08-2004 02:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration