By: Adrian (a.delete@this.acm.org), September 21, 2022 4:42 am
Room: Moderated Discussions
Andrey (andrey.semashev.delete@this.gmail.com) on September 21, 2022 3:45 am wrote:
> Adrian (a.delete@this.acm.org) on September 20, 2022 8:44 pm wrote:
> > Andrey (andrey.semashev.delete@this.gmail.com) on September 20, 2022 9:35 am wrote:
> > > Adrian (a.delete@this.acm.org) on September 20, 2022 7:23 am wrote:
> > > >
> > > > I have never used Debian, but in many Linux distributions you can make a directory, mount there /proc, /sys
> > > > and /dev, chroot into it and install there the same Linux
> > > > distribution or another one, and also install there
> > > > whatever packages you want and test them or use them without modifying in any way your base system.
> > >
> > > It's not as simple as that. You need /etc, /bin, /usr and /var (at least major parts of them) to
> > > be able to run shell, basic shell tools like grep/sed/python/etc. and apt, which also requires network
> > > to work. Since you're going to install packages and you don't want to affect the host system, those
> > > directories must not be mounts but rather different copies or something like overlayfs.
> > >
> > > There is a pbuilder tool (or cowbuilder flavor of it) that prepares an environment image automatically,
> > > but it is better suited for building packages, not for interactive development.
> > >
> >
> >
> > In my experience, it is actually as simple as that.
> >
> > Maybe there are Linux distributions with weirder requirements, but on all that I
> > have used (I never use systemd), it is enough to do this sequence of commands:
> >
> >
> > mkdir /home/user/test_dir
> > cd /home/user/test_dir
> > mkdir dev etc root proc sys
> >
> > mount -t proc none proc
> > mount --rbind /sys sys
> > mount --rbind /dev dev
> > cp /etc/resolv.conf etc
> >
> > env -i HOME=/root TERM=$TERM /bin/chroot . bash -l
> >
> >
> > Copying resolv.conf from the host Linux system is enough to make networking work.
>
> Nope, doesn't work for me:
>
> /usr/sbin/chroot: failed to run command 'bash': No such file or directory
>
> As I said, bash needs to be runnable within the new root. Same with
> any other program you want to run in the chroot environment.
>
Sorry, maybe I was not clear enough.
Obviously, you cannot run anything from an empty directory.
I have said that you first need to install a Linux distribution in that directory.
With the Linux distributions that I normally use (e.g. Gentoo), an installation is done by extracting an archive with a bootstrap stage into the empty directory, which populates the directory with bash and the other executables required for performing an installation.
Then, from the chrooted environment the installation of the complete distribution from the Internet is done according to the procedure specific for that distibution, using the bootstrapping programs.
The point was that this distribution installed in that directory is completely independent of the host distribution, with which it shares no files. So you can install completely different compilers, libraries or any other applications, without any interference. You can install e.g. a Fedora Linux or an Arch Linux under a Gentoo host, or vice-versa.
> Adrian (a.delete@this.acm.org) on September 20, 2022 8:44 pm wrote:
> > Andrey (andrey.semashev.delete@this.gmail.com) on September 20, 2022 9:35 am wrote:
> > > Adrian (a.delete@this.acm.org) on September 20, 2022 7:23 am wrote:
> > > >
> > > > I have never used Debian, but in many Linux distributions you can make a directory, mount there /proc, /sys
> > > > and /dev, chroot into it and install there the same Linux
> > > > distribution or another one, and also install there
> > > > whatever packages you want and test them or use them without modifying in any way your base system.
> > >
> > > It's not as simple as that. You need /etc, /bin, /usr and /var (at least major parts of them) to
> > > be able to run shell, basic shell tools like grep/sed/python/etc. and apt, which also requires network
> > > to work. Since you're going to install packages and you don't want to affect the host system, those
> > > directories must not be mounts but rather different copies or something like overlayfs.
> > >
> > > There is a pbuilder tool (or cowbuilder flavor of it) that prepares an environment image automatically,
> > > but it is better suited for building packages, not for interactive development.
> > >
> >
> >
> > In my experience, it is actually as simple as that.
> >
> > Maybe there are Linux distributions with weirder requirements, but on all that I
> > have used (I never use systemd), it is enough to do this sequence of commands:
> >
> >
> > mkdir /home/user/test_dir
> > cd /home/user/test_dir
> > mkdir dev etc root proc sys
> >
> > mount -t proc none proc
> > mount --rbind /sys sys
> > mount --rbind /dev dev
> > cp /etc/resolv.conf etc
> >
> > env -i HOME=/root TERM=$TERM /bin/chroot . bash -l
> >
> >
> > Copying resolv.conf from the host Linux system is enough to make networking work.
>
> Nope, doesn't work for me:
>
> /usr/sbin/chroot: failed to run command 'bash': No such file or directory
>
> As I said, bash needs to be runnable within the new root. Same with
> any other program you want to run in the chroot environment.
>
Sorry, maybe I was not clear enough.
Obviously, you cannot run anything from an empty directory.
I have said that you first need to install a Linux distribution in that directory.
With the Linux distributions that I normally use (e.g. Gentoo), an installation is done by extracting an archive with a bootstrap stage into the empty directory, which populates the directory with bash and the other executables required for performing an installation.
Then, from the chrooted environment the installation of the complete distribution from the Internet is done according to the procedure specific for that distibution, using the bootstrapping programs.
The point was that this distribution installed in that directory is completely independent of the host distribution, with which it shares no files. So you can install completely different compilers, libraries or any other applications, without any interference. You can install e.g. a Fedora Linux or an Arch Linux under a Gentoo host, or vice-versa.