A chroot installation environment
Posted: 2022-09-10 Filed under: system | Tags: chroot, vm 5 CommentsI have been having annoying problems with VirtualBox, summed up already at LQ, so I won’t go through them again. I need a clean installation of Slackware (x86_64 and x86), therefor, I decided to learn how to set it up in a chroot environment.
I used as a guide Slackware’s and CRUX’s wiki pages. Below is what I did for a 32bit Slackware on a 64bit “host”.
Create the folder, let’s name it slack32
, where the chroot environment will be. I have a data storage HDD, mounted on /media/data0
, so that’s where I decided to create it:
mkdir /media/data0/slack32/
Mount the installation ISO (as root, of course):
mount -o loop slackware-15.0-install-dvd.iso /media/cdrom0/
Navigate there, to the subfolder containing the packages:
cd /media/cdrom0/slackware/
Now, install all packages to the folder where we’ll chroot later:
installpkg --root /media/data0/slack32/ */*.t?z
Let’s already define the path to the folder as:
CHROOT=/media/data0/slack32/
Let’s navigate there:
cd $CHROOT
Copy resolv.conf from the host, so we have net:
cp /etc/resolv.conf $CHROOT/etc
There’s no fstab
file, so let’s create one:
touch $CHROOT/etc/fstab
Paste these as it’s contents:
# <file system> <mount point> <type> <options> <dump> <pass> tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts noexec,nosuid,gid=tty,mode=0620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
Now mount:
mount -t proc proc $CHROOT/proc
mount --bind /dev $CHROOT/dev
mount --bind /sys $CHROOT/sys
Finally, chroot there:
chroot $CHROOT /bin/bash
Specify that it’s a 32bit system:
linux32
From this point we are working in the chroot environment and all file locations are in the chroot environment. To set up slackpkg
, a 32bit mirror should be selected. Since I installed from a 64bit host, the mirrors will be for x86_64 architecture. What I did was, first to modify a mirror close to me by removing the “64” suffix from “slackware:”
# FINLAND (FI) ftp://elektroni.phys.tut.fi/slackware-15.0/
I had GPG signature problems, which seemed to disappear after I updated ca-certificates
. For this, I had to stop the GPG check first:
# If CHECKGPG is "on", the system will verify the GPG signature of each package # before install/upgrade/reinstall is performed. CHECKGPG=off
Then, do
slackpkg update
slackpkg upgrade ca-certificates
After that, I put it back to on and then:
slackpkg update gpg
One thing that can also be done is to reinstall slackpkg
itself, now when the system knows it’s 32bit, in this way all mirrors should be correct:
slackpkg reinstall slackpkg
Upgrade the whole system, as usual:
slackpkg upgrade-all
That’s it. I went to /tmp
and tested a few SlackBuilds (Bpp1.9-*) that just made it back to 15.0. When done with working in slack32, I did:
exit
umount $CHROOT/proc
umount $CHROOT/dev
umount $CHROOT/sys
exit
Next time I need it, just start like this
CHROOT=/media/data0/slack32/
cd $CHROOT
mount -t proc proc $CHROOT/proc
mount --bind /dev $CHROOT/dev
mount --bind /sys $CHROOT/sys
chroot $CHROOT /bin/bash
linux32
Compile times are better than in a VM, that’s for sure. I also have very easy navigation and file sharing there. Phew!
There is a problem with “installpkg –root”. Theoretically, doinst.sh scripts should work when “–root” is used, but in reality a lot of them doesn’t work. This is a reason for your ca-certificates problem.
I’d suggest first install a and l series using installpkg –root, them chroot and install all series, including a and l, with installpkg without –root. This way, all doinst.sh scripts will run and you get a proper installation.
Also, you should have /var/lib/dbus/machine-id ( = /etc/machine-id ) and root/.Xauthority inside chroot.
And set the environment variable HOME, TERM, and PATH to be what you want (for root).
hey, thanks very much! I will give it a try and update the post.
A nice thing is that it is possible to run a program installed in chroot such that a part of environment will be from chroot, but the rest is from you usual environmet outside chroot. Say, /usr/bin from chroot, /home from outside. In this way you can run from chroot programs that use X. I use something like this:
/usr/bin/bwrap \
–ro-bind /chroot / \
–dev-bind /dev /dev \
–ro-bind /sys /sys \
–proc /proc \
–ro-bind-try /etc/resolv.conf /etc/resolv.conf \
–ro-bind-try /etc/hosts /etc/hosts \
–ro-bind-try /etc/nsswitch.conf /etc/nsswitch.conf \
–ro-bind-try /etc/passwd /etc/passwd \
–ro-bind-try /etc/group /etc/group \
–bind-try /home /home \
–bind-try /media /media \
–bind-try /mnt /mnt \
–bind-try /opt /opt \
–bind-try /run /run \
–bind-try /srv /srv \
–bind-try /tmp /tmp \
–bind-try /usr/local /usr/local \
–bind-try /var /var \
“$@”
The –bind-try directories are from outside chroot.
An example, if you have 32-bit chroot, you can run wine from it without installi
ng multilib.
bwrap is from bubblewrap package at SBo.
hey, that’s a great tip! I’ll definitely give it a try and if you don’t mind, even write a post about it
You are welcome