|
# Make a chroot environment |
|
|
|
chroot_home := $(chroot)/home/$(chroot_user) |
|
|
|
alpine_ver := 3.12 |
|
alpine_ver_full := $(alpine_ver).1 |
|
alpine_arch := aarch64 |
|
miniroot_basename := alpine-minirootfs-$(alpine_ver_full)-$(alpine_arch) |
|
chroot := $(miniroot_basename) |
|
miniroot_tarball := $(chroot).tar.gz |
|
miniroot_tarball_uri := http://dl-cdn.alpinelinux.org/alpine/v$(alpine_ver)/releases/$(alpine_arch)/$(miniroot_tarball) |
|
|
|
chroot_busybox := $(chroot)/bin/busybox |
|
chroot_resolv := $(chroot)/etc/resolv.conf |
|
chroot_mounted := $(chroot).mounted |
|
chroot_env := $(chroot)/.chroot.env |
|
chroot_profile := $(chroot)/etc/profile.d/chroot.sh |
|
chroot_postinstaller := $(chroot)/usr/local/bin/postinstall.sh |
|
chroot_postinstalled := $(chroot)/.postinstalled |
|
|
|
.PHONY: cleanlocal cleanall mount umount default |
|
|
|
default: $(chroot_postinstalled) |
|
|
|
$(chroot_postinstalled): $(chroot_env) $(chroot_resolv) $(chroot_postinstaller) $(chroot_profile) |
|
chroot $(chroot) /usr/local/bin/postinstall.sh |
|
|
|
$(chroot_profile): $(chroot_busybox) |
|
cp profile.d.chroot.sh $(chroot_profile) |
|
|
|
$(chroot_postinstaller): postinstall.sh $(chroot_busybox) $(chroot_mounted) |
|
install postinstall.sh $(chroot_postinstaller) |
|
|
|
$(chroot_env): $(chroot_busybox) chroot.env |
|
cp chroot.env $(chroot_env) |
|
|
|
$(chroot_resolv): $(chroot_busybox) resolv.conf |
|
install resolv.conf $(chroot_resolv) |
|
|
|
$(chroot_busybox): $(miniroot_tarball) |
|
mount | grep '$(chroot)' && exit 1 || true |
|
mkdir -p $(chroot) |
|
cd $(chroot); tar -zxf ../$(miniroot_tarball) |
|
# Touch it because it'll extract it with an old timestamp |
|
touch $(chroot) |
|
|
|
$(miniroot_tarball): |
|
wget $(miniroot_tarball_uri) |
|
|
|
cleanlocal: |
|
mount | grep '$(chroot)' && exit 1 || true |
|
rm -rf $(chroot) |
|
|
|
cleanall: |
|
mount | grep '$(chroot)' && exit 1 || true |
|
rm -rf $(chroot) $(miniroot_tarball) |
|
|
|
# Mounts section. Note that these all must be done as root |
|
mount: $(chroot_mounted) |
|
$(chroot_mounted): $(chroot_busybox) |
|
mount --bind /dev $(chroot)/dev |
|
mount -t devpts devpts $(chroot)/dev/pts -o nosuid,noexec |
|
mount -t tmpfs shm $(chroot)/dev/shm -o mode=1777,nosuid,nodev |
|
mount -t sysfs sys $(chroot)/sys -o nosuid,nodev,noexec,ro |
|
mount -t proc proc $(chroot)/proc -o nosuid,nodev,noexec |
|
mount -t tmpfs tmp $(chroot)/tmp -o mode=1777,nosuid,nodev,strictatime |
|
mount -t tmpfs run $(chroot)/run -o mode=0755,nosuid,nodev |
|
mkdir -p $(chroot)/home/builder |
|
mount --bind ./chroot-homedir $(chroot)/home/builder |
|
touch $(chroot_mounted) |
|
|
|
# Unmount section. All must be done as root |
|
umount: |
|
umount -l $(chroot)/dev/pts || true |
|
umount -l $(chroot)/dev/shm || true |
|
umount -l $(chroot)/home/builder || true |
|
sleep 1 |
|
umount -l $(chroot)/* || true |
|
rm -f $(chroot_mounted) |
|
@echo "======== Any remaining mounts listed below ========" |
|
mount | grep '$(chroot)' || true |
|
@echo "======== Mounts list complete ========" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# OLD MOUNTS SECTION - DELETEME |
|
# chroot_dev := $(chroot)/dev |
|
# chroot_devpts := $(chroot)/dev/pts |
|
# chroot_devpts_mounted :$(chroot).devpts.mounted |
|
# chroot_sysfs := $(chroot)/sys |
|
# chroot_procfs := $(chroot)/proc |
|
# chroot_tmpfs := $(chroot)/tmp |
|
# chroot_runfs := $(chroot)/run |
|
# chroot_devshm := $(chroot)/dev/shm |
|
# chroot_devshm_mounted :$(chroot).devshm.mounted |
|
# mount: $(chroot_dev).mounted $(chroot_devpts_mounted) $(chroot_sysfs).mounted $(chroot_procfs).mounted $(chroot_tmpfs).mounted $(chroot_runfs).mounted $(chroot_devshm_mounted) |
|
# echo "Mounted chroot filesystems" |
|
# $(chroot_devpts_mounted): $(chroot_dev).mounted |
|
# umount $(chroot_devpts) || true |
|
# mount -t devpts devpts $(chroot_devpts) |
|
# touch $(chroot_devpts_mounted) |
|
# $(chroot_devshm_mounted): $(chroot_dev).mounted |
|
# umount $(chroot_devshm) || true |
|
# mount -t tmpfs shm $(chroot_devshm) -o mode=1777,nosuid,nodev |
|
# touch $(chroot_devshm_mounted) |
|
# $(chroot_dev).mounted: $(chroot_busybox) |
|
# umount $(chroot_dev) || true |
|
# mount --bind /dev $(chroot_dev) |
|
# touch $(chroot_dev).mounted |
|
# $(chroot_sysfs).mounted: $(chroot_busybox) |
|
# umount $(chroot_sysfs) || true |
|
# mount -t sysfs sys $(chroot_sysfs) -o nosuid,nodev,noexec,ro |
|
# touch $(chroot_sysfs).mounted |
|
# $(chroot_procfs).mounted: $(chroot_busybox) |
|
# umount $(chroot_procfs) || true |
|
# mount -t proc proc $(chroot_procfs) -o nosuid,nodev,noexec |
|
# touch $(chroot_procfs).mounted |
|
# $(chroot_tmpfs).mounted: $(chroot_busybox) |
|
# umount $(chroot_tmpfs) || true |
|
# mount -t tmpfs tmp $(chroot_tmpfs) -o mode=1777,nosuid,nodev,strictatime |
|
# touch $(chroot_tmpfs).mounted |