I have a chroot environment in a directory. I want to install some RPM packages using the repositories in that chroot environment instead of the host OS ones.

yum --installroot= will look for packages repositories only in myroot/etc/yum.repos.d or it will only/also look in /etc/yum/repos.d? RHEL 6 is having the latter behavior. If that is expected behavior, what is the best method to achieve what I need?

Thanks in advance.

MensaWater

04-03-2013 09:35 AM

In the man page for yum it says repository configuration is honored for all operations. I take that to mean it is always going to look at your overall configuration.

The way yum works is to install what you ask for AND any dependencies required to make it work. It is recursive which is to say if it determines package J is needed to install package A it will then check to see what dependencies package J has so may find it also needs to install package Z. It then checks package Z and may find it needs package F. It then checks package F etc...

So if you think about it if you were to try to use yum to install packages in a chroot directory and exclude the main repositories and rpmdb it would determine utltimately that you need a full install of hundreds of packages because you're chroot is apt to have a limited subset that you'd put there. (e.g. you typically don't copy all of /lib, /usr/lib, /bin, /etc to it - just enough to make it work when someone logs into the chroot).

Theoretically the above wouldn't be a problem if you logged in as the chrooted user and ran yum because the chrooted user wouldn't see the root /etc but rather the /etc you'd put in myroot. Unfortunately you'd still have the same problem of yum deciding to install EVERYTHING because it wouldn't see much. In practice it wouldn't work anyway because your chrooted user won't have root access to his own environment.

So the question here is - Are you trying to simply set up a chroot environment with limited functionality or are you trying to setup a fully functional environment with broad functionality. If the latter you should be looking at creating a virtual machine (e.g. with KVM). If the former a better way to do what you want might be to either a) Install the packages as your real root user then copy what you need to the chroot'ed environment from your non-chroot environment or b) Use yum downloadonly to download the RPMs you need then use yum's local install option or rpm itself to install the packages. Were it me I'd go with option a.

alan.vitor

04-03-2013 02:53 PM

I'm trying to set up a fully functional limited environment to build packages for different Linux distributions. Each chroot should contain all packages/binaries/libraries it needs, but it should contain the minimum necessary to build packages. I use schroot to manage all chroots and imho it is simpler/faster than managing one VM for each Linux distribution I need to support.

As I may have a chroot with a Linux distribution different than the host OS, installing packages as host OS root user using host OS repositories does not work. Using yum downloadonly in the host OS will not work for the same reason.

I need to only use repos in the myroot/etc/yum.repos.d.

Idea 1: as yum --installroot=<myroot> repolist gets chroot and host repositories, I thought in using yum install disablerepo=<host OS repositories> but then I'd need to parse files in etc/yum.repos.d/ to get the repositories list?

Idea 2: temporarily backup /etc/yum.repos.d and replace it with myroot/etc/yum.repos.d

I think there should be a simpler way to achieve this. Ideas?

MensaWater

04-03-2013 04:51 PM

I haven't done what you're trying.

Doing a web search using the following search terms resulted in a fair number of hits.
creating multiple build environments with chroot yum

However it shows that you do have to do a full install in each chroot as I indicated would be the case which is why I suggested VMs.

One idea might be to setup your chroot'ed user so that the myroot/etc/passwd gives him UID 0 so that when it logs in it is seen as the root user in the chroot itself. Or better yet setup sudo under the chroot (e.g. myroot/etc/sudoers) to allow the chrooted user to become root after loging. Since it is chroot'ed and logged into the chroot theoretically it should see myroot as / and only use anything it sees under that directory structure. I've not tried that myself though and there may be safeguards specifically to prevent chroot'ed user's from becoming root of which I am not aware.

alan.vitor

04-03-2013 05:58 PM

I'm already following the steps in the url you sent in your last post. The problem is that yum install fails because yum looks in my host os repositories and tries to download the wrong packages (host os != chrooted os). Fow now, I've used hard-coded --disablerepo=<host_repos> parameter in yum install, but that's hardly a definite solution.

I have no problem doing a full install (if it's a minimal one) in each chroot. As I said, chroots are now easily handled by schroot and the build process is already automated using it, so I'd like to avoid the change to VMs.