Quick and easy Fedora Minimal chroot

This is a quick guide on how to quickly make a Fedora Minimal chroot environment without any special tools. The only prerequisite is that you have root access on the machine you are using, and chroot binary (or busybox even). I am also using wget and tar but you probably have that. :)

We are going to use a Container image as it contains a very well packaged Fedora Minimal rootfs.

Container images are available for x86_64 and ARM architectures here:

https://download.fedoraproject.org/pub/fedora/linux/releases/34/Container/

Lets get ready:

# make sure you are root
sudo su -

# create a directory for Fedora
mkdir -p /fedora 
cd /fedora

# get the Container image
wget https://download.fedoraproject.org/linux/releases/34/Container/x86_64/images/Fedora-Container-Base-34-1.2.x86_64.tar.xz

To unpack the image:

# unpack Container image
tar xvf Fedora-Container-Base-34-1.2.x86_64.tar.xz --strip-components=1

# unpack the main tar
tar xvpf layer.tar

# cleanup
rm layer.tar
rm Fedora-Container-Base-34-1.2.x86_64.tar.xz
rm json
rm VERSION

So you now have a base Fedora Minimal root filesystem in /fedora

It’s a good idea to create a script to enter it quickly. With your favorite text editor create /usr/bin/enter-fedora-chroot file:

#!/bin/sh

echo "Entering Fedora chroot"

mount -t proc proc /fedora/proc/
mount -t sysfs sys /fedora/sys/
mount -o bind /dev /fedora/dev/
mount -o bind /dev /fedora/dev/pts

chroot /fedora /bin/env -i \
    HOME=/root TERM="$TERM" PS1='[\u@f34chroot \W]\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/bin \
    /bin/bash --login

echo "Exiting Fedora chroot"
umount /fedora/dev/pts
umount /fedora/dev/
umount /fedora/sys/
umount /fedora/proc/

echo "Cleaned up"

and mark it as executable: chmod +x /usr/bin/enter-fedora-chroot

Now you can enter Fedora from literally anywhere! Just run the script with enter-fedora-chroot!

When inside the chroot, you will probably have to setup DNS to have working internet connection with a quick echo nameserver 8.8.8.8 > /etc/resolv.conf.

That’s it, it is really very easy.

Have fun!

Copy and rewrite from:
https://nmilosev.svbtle.com/quick-and-easy-fedora-minimal-chroot