How to make a minimal Fedora chroot and run programs in it
How to bootstrap a modern Fedora system in a chroot.
This will not give you a bootable system, but it will give you a Fedora system you can chroot
into and run programs. This is especially useful when you must run a Python 2 program that your Fedora 32 (or higher) system cannot run anymore. To create a Fedora system in a folder, use the following command (run all that you see here as root
):
dnf install \
--installroot=/mnt \
--releasever=30 \
--setopt=install_weak_deps=False \
--setopt=keepcache=True \
--assumeyes \
--nodocs \
systemd dnf glibc-langpack-en passwd rtkit policycoreutils \
NetworkManager audit firewalld selinux-policy-targeted kbd zchunk sudo \
vim-minimal systemd-udev rootfiles less iputils deltarpm sqlite lz4
With the above command line you can bootstrap a Fedora 30 system. Change the --releasever=30
parameter to whatever version of Fedora you'd like to have.
After dnf
is done processing and installing software, you may want to do the following things in order to be able to use the chroot
ed Fedora system:
- Enable name resolution inside the system:
touch /mnt/etc/resolv.conf
mount --bind /etc/resolv.conf /mnt/etc/resolv.conf
- Enable access to block devices and other system statistics:
mount --bind /dev/mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
Presto! You are now ready to run programs in that jail. Simply chroot /mnt
and you will be able to run programs there. Note that jails created in this way are not security sandboxes and therefore you should consider programs in it as root
-equivalent.