Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a rootfs environment for chroot building.
# Create a rootfs environment for chroot building.
# Requires
# - OS installing CDROM at the current directory,
# - the root authority.
# mount install cd
mkdir /mnt/cdrom
mount CentOS-7-x86_64-Minimal-1503-01.iso /mnt/cdrom -t iso9660 -o loop
# mount squashfs
mkdir /mnt/squashfs
mount /mnt/cdrom/LiveOS/squashfs.img /mnt/squashfs -t squashfs
# mount rootfs
mkdir /mnt/rootfs
mount /mnt/squashfs/LiveOS/rootfs.img /mnt/rootfs -t ext4
# copy rootfs
cp -r /mnt/rootfs rootfs
umount /mnt/rootfs
umount /mnt/squashfs
umount /mnt/cdrom
rm -r /mnt/rootfs /mnt/squashfs /mnt/cdrom
# mount dvd image under rootfs
mkdir rootfs/mnt/cdrom
mount CentOS-7-x86_64-Minimal-1503-01.iso rootfs/mnt/cdrom -t iso9660 -o loop
# chroot
mount -o bind /dev rootfs/dev/
mount -t proc none rootfs/proc/
mount -o bind /sys rootfs/sys/
chroot rootfs /bin/bash -xe << _END_CHROOT_
cd /mnt/cdrom/Packages
rpm -ivh --nodeps rpm-4.11.1-25.el7.x86_64.rpm
rpm -ivh --nodeps yum-3.4.3-125.el7.centos.noarch.rpm
# add the cdrom image to yum repository
cat << _END_ > /etc/yum.repos.d/cdrom.repo
name=Install CD-ROM
yum --disablerepo=\* --enablerepo=cdrom -y reinstall yum
yum --disablerepo=\* --enablerepo=cdrom -y groupinstall "Minimal Install"
# yum --disablerepo=\* --enablerepo=cdrom -y install <required packages>
rm /etc/yum.repos.d/cdrom.repo
# Clean up
umount rootfs/mnt/cdrom
umount rootfs/dev
umount rootfs/proc
umount rootfs/sys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.