Messing with a distro's files -- from within another distro.
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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
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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.