Installing CentOS in a chroot under Debian
This guide assumes you have a working Debian 10 (Buster) system and describes the steps needed to install a minimal CentOS 7 version into a chroot in it. Such installation can be useful if you need to build software for CentOS and/or Red Hat Enterprise Linux users.
Initial booststap using rinse
Debian packages rinse
script in the package with the same, which
can be used to create minimal installations of many RPM-based systems. Start
by installing and then just run it, as root:
# apt install rinse
# rinse --arch amd64 --distribution centos-7 \
--directory /srv/chroot/centos-7
It can be useful to additionally specify the --mirror
option to
select a particular mirror to use. This option also allows to explicitly
select an exact CentOS version instead of installing the latest one by
default, e.g. appending
--mirror http://centos.mirrors.proxad.net/7.6.1810/os/x86_64/Packages
to the command line above would download CentOS 7.6 packages from a particular
mirror in France (mirrors close to your location can be found at
this page).
Creating minimal /dev
entries
CentOS 7 doesn't seem to provide the MAKEDEV
script any longer,
so the minimal set of required devices needs to be created by hand, i.e.
executing the following commands inside the chroot:
# mknod /dev/null c 1 3
# chmod 666 /dev/null
# mknod /dev/ptmx c 5 2
# chmod 666 /dev/ptmx
# mkdir /dev/pts
Sharing users between the host system and chroot
Generally speaking, it's convenient to be able to reuse the same user in both the main, Debian, system and in chroot. For a single user it's enough to just create the same user entry in the chroot directory:
# chroot /srv/chroot/centos-7.6 adduser --no-create-home \
--uid $USER_ID $USER_NAME
The --no-create-home
option is used because we plan on reusing
the home directories from the main system in the chroot, see the next section.
Mounting chroot filesystems
While not, strictly speaking, required, it is recommended to at least mount
the /proc
pseudo filesystem. Many tools also require the ability
to create the pseudo-terminal devices, for which devpts
must be
mounted as well. And if you also decide to share the home directories between
the main system and chroot, you need to use a bind-mount for it.
Taken together, this means that the following commands need to be executed:
# mount -t proc proc /srv/chroot/centos-7.6/proc
# mount -t devpts devpts /srv/chroot/centos-7.6/dev/pts
# mount -o bind /home /srv/chroot/centos-7.6/home
It also recommended to add the lines
proc /srv/chroot/centos-7.6/proc proc defaults 0 0
devpts /srv/chroot/centos-7.6/devpts devpts gid=5,mode=620 0 0
/home /srv/chroot/centos-7.6/home none bind 0 0
to /etc/fstab
of the main system in order to make these
mounts persistent.
Useful packages not included in the minimal installation
Installing ncurses-term
is required in order to have non-dumb
terminal functionality: this package provides the necessary terminfo entries.
The development tools included in CentOS 7 are quite ancient by now and it's recommended to install the latest version of RedHat development toolset to get the newer versions. For this the following commands need to be used:
# yum -y install centos-release-scl
# yum-config-manager --enable rhel-server-rhscl-7-rpms
# yum install devtoolset-8 rh-git218
Of course, remember to use
$ scl enable devtoolset-8 rh-git218 $SHELL
to actually enable using the programs included in these packages.