I love using chroot, even if docker is more comfortable, I find that it gives you a better way to learn more about the system than doing things the easy way.
For this example I am installing RHEL7.5 into /opt/redhat/chroot/ on a debian sid server.
Normally I do not spend my free time on Redhat but it seems that it is a good idea to learn it because many companies will test your redhat specific experience and call that linux skills.
So I registered on redhat and got a download link, using wget I downloaded it, my command contains an auth link I cannot share, so get your own.
Verify the sha256 sum of the download before using it against official site
We can prepare a chroot with an empty directory and mount special dirs into it
mount the special filesystems to your chroot, these are from the debian system and provided by the kernel running in debian.
mount -o bind /run /opt/redhat/chroot/run/
mount -o bind /proc /opt/redhat/chroot/proc/
mount -o bind /sys /opt/redhat/chroot/sys/
mount -o bind /dev /opt/redhat/chroot/dev/
Now we mount the dvd iso loopback
mount /opt/redhat/rhel-server-7.5-x86_64-dvd.iso /cdrom -t iso9660 -o/opt/redhat/chroot/mount/cdrom
mount output we see
/opt/redhat/rhel-server-7.5-x86_64-dvd.iso on /opt/redhat/chroot/mount/cdrom type iso9660 (ro,relatime)
First Pass Install
Now do a provisional install of all the packages in the dvd.
This will give us the basic binaries we need to get install the redhat system and then we will reinstall them the proper way. There must be a better way to do this and I am sure the experts will give me some feedback, but this way works for sure and can be used in a pinch.
So from inside the chroot
cd /opt/redhat/chroot for x in mount/cdrom/Packages/*.rpm; do echo $x; sudo rpm2cpio $x | cpio -idmv; done
Outside the chroot, copy in your resolv.conf
cp /proc/mounts/opt/redhat/chroot/etc/mtab cp /etc/resolv.conf /opt/redhat/chroot/etc/resolv.conf
Go into the chroot
Launch the chroot like this
chroot . /usr/bin/bash
For this case I have the 30 day subscription, so lets use it :
subscription-manager register --username ZZZ --password XXXX --auto-attach
Add DVD to system as source
Then you can add the dvd mounted as a repo and reinstall everything
vi /etc/yum.repos.d/iso.repo with the Content (https://www.cyberciti.biz/tips/redhat-centos-fedora-linux-setup-repo.html)
[mountedcd] baseurl=file:///mount/cdrom enabled=1
Install packages from dvd inside the chroot
Now I can install the packages officially :
yum install bash rpm yum emacs httpd rpm-build gcc glibc-headers
See also :
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -i epel-release-latest-7.noarch.rpm
I noticed that the bin,lib,lib64 and sbin directory were being created by the rpms, and that you need to move them out of the way and link them to /usr/*. So I needed to leave the chroot, move the old dirs out of the way, and then link them.
mv bin binold ln -s usr/bin bin mv lib libold ln -s usr/lib lib mv lib64 lib64old ln -s usr/lib64 lib64 cp -rv lib64old/* lib64/ mv sbin sbinold ln -s usr/sbin/ sbin
Finally I had to then reinstall the filesystem package, so maybe installing that from the beginning would be good.
rpm -i /mount/cdrom/Packages/filesystem-3.2-25.el7.x86_64.rpm
To reinstall all the packages
yum list installed | cut "-d " -f 1| xargs yum reinstall -y
And finally to then install everything else from the cdrom
yumdb search from_repo mountedcd | grep \. | grep -v = | xargs yum install -y