How to Create a Fedora 26 Chroot
Below is the long list of commands that I will be using to create the Fedora chroot. To start you have to make sure that you have wget installed on the host system, or you will get errors with the below commands.
export CHROOTDIR=/opt/chroots/fedora-chroot
mkdir -p $CHROOTDIR/var/lib/rpm
cd $CHROOTDIR/../
rpm --rebuilddb --root=$CHROOTDIR
wget ftp://ftp.acc.umu.se/mirror/fedora/linux/releases/26/Server/x86_64/os/Packages/f/fedora-release-server-26-1.noarch.rpm
wget ftp://ftp.acc.umu.se/mirror/fedora/linux/releases/26/Server/x86_64/os/Packages/f/fedora-repos-26-1.noarch.rpm
rpm -i --root=$CHROOTDIR --nodeps fedora-release-server-26-1.noarch.rpm
rpm -i --root=$CHROOTDIR --nodeps fedora-repos-26-1.noarch.rpm
yum --installroot=$CHROOTDIR --releasever=26 install -y rpm-build yum
cp $CHROOTDIR/etc/skel/.??* $CHROOTDIR/root
cp /etc/resolv.conf $CHROOTDIR/etc/resolv.conf
yum --installroot=$CHROOTDIR install -y iputils net-tools telnet
The below commands will create some scripts that can be used to start up and stop the chroot. The chroot-services file that is referenced, is run inside the chroot to run any commands and services that are to be run in the chroot. These scripts help for if you want to start the chroot with a startup script fro the host.
cat > chroot-mount.sh <<"EOF"
#!/bin/bash
CHR=$1
mount -vt proc proc $CHR/proc
mount -vt sysfs none $CHR/sys
mount -v --bind /dev $CHR/dev
mount -vt tmpfs tmpfs $CHR/dev/shm
mount -vt devpts /dev/pts $CHR/dev/pts
chroot $CHR /root/chroot-services.sh start
EOF
chmod +x chroot-mount.sh
cat > chroot-umount.sh <<"EOF"
#!/bin/bash
chroot $1 /root/chroot-services.sh stop
CHR=$1
umount -v $CHR/proc
umount -v $CHR/sys
umount -v $CHR/dev/shm
umount -v $CHR/dev/pts
umount -v $CHR/dev
EOF
chmod +x chroot-umount.sh
echo '#!/bin/bash' > $CHROOTDIR/root/chroot-services.sh
chmod +x $CHROOTDIR/root/chroot-services.sh
./chroot-mount.sh $CHROOTDIR
chroot $CHROOTDIR /bin/bash -l
yum install screen mc nano wget ntsysv initscripts
exit
./chroot-umount.sh $CHROOTDIR