Bootstrapping CentOS rootfs for use with chroots/containers

Posted on November 16, 2017

We will see how to generate a rootfs tarball for redhat based system. Since we are targetting redhat based system, I am going to use debian based system (Ubuntu 17.10 64-bit - latest at the time of writing this post) as my host. We will generate rootfs tarball for CentOS 7 64-bit.å

Lets get started

As usual the first step, install the required dependecy packages which in our case is yum.

Second, will prepare the required directory structure. In our example ~/work will be our working directory and we will install the CentOS 7 roofs in inside of work in a directory named centos7.

Now we need to generate the repo metadata file for CentOS 7 installation. Below gist does the same.

Once we have our directory structure and the repo file prepared as mentioned above, we can bootstrap the CentOS 7 root by executing the below mentioned command. This creates a base rootfs with networking utilities and sudo command.

After the yum installation is complete we need to prepare our rootfs for customization. We will start by mounting the required mount points to use chroot.

Now we can start using the rootfs using chroot command. We will do the following customizations

Setup releasever and basearch yum variables. Unfortunately this is required because of the caveat mentioned in Appendix I.

References

Appendix I

While running yum command inside of the CentOS 7 chroot I ran into below error message. Strangely this happens on Ubuntu host but not on CentOS host. As a fix I have created yum variables releasever and basearch inside the CentOS rootfs. Please check Reference section for the manual describing how to customize yum variables.