From 904d6449909db7e127a17043844f032e8486017b Mon Sep 17 00:00:00 2001 From: r00t Date: Fri, 30 Jan 2015 20:38:42 -0500 Subject: [PATCH] overlayfs implementation --- extra/pre-build.d/etc/customizepkg.d/linux | 92 ------------------- extra/pre-build.d/root/post-build.sh | 21 ----- .../pre-build.d/usr/lib/initcpio/hooks/livecd | 6 +- .../usr/lib/initcpio/install/livecd | 3 +- lib/10-mentos.func.sh | 16 +--- lib/mk.chroot.sh | 16 ++-- 6 files changed, 17 insertions(+), 137 deletions(-) delete mode 100755 extra/pre-build.d/etc/customizepkg.d/linux diff --git a/extra/pre-build.d/etc/customizepkg.d/linux b/extra/pre-build.d/etc/customizepkg.d/linux deleted file mode 100755 index c0e1da7..0000000 --- a/extra/pre-build.d/etc/customizepkg.d/linux +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh -# change some versions around -sed -i -e 's/^\(pkgbase=linux[[:space:]]*\)/#\1/g' ${1} -sed -i -e 's/^#\(pkgbase=linux-\)custom.*$/\1BDisk/g' ${1} -sed -i -e '/^_kernelname/a KERNVER=$(echo ${pkgver} | sed -e "s/\\\([0-9]\\\.[0-9]*\\\).*$/\\\1/")' ${1} -sed -i -e '/^_kernelname/a KERNVER_MIN=$(echo ${pkgver} | sed -e "s/\\\([0-9]\\\.[0-9]*\\\)\\\.\\\(.*\\\)$/\\\2/")' ${1} -sed -i -e "s/^\(makedepends=.*\))$/\1 'rsync' 'git')/g" ${1} -##cp linux.preset linux-BDisk.preset -##sed -i -e 's#^[[:space:]]*install\ -D\ -m644\ "${srcdir}/linux.preset".*$#install -D -m644 "${srcdir}/linux-BDisk.preset" "${pkgdir}/etc/mkinitcpio.d/${pkgbase}.preset"#g' ${1} -##sed -i -e "s/\ 'fallback'//g" \ -##-e '/^fallback/d' \ -##-e '/^$/d' \ -##-e '/^[[:space:]]*$/d' \ -##-e 's#^\(default_image="/boot/initramfs-linux\).*#\1-BDisk"/g' linux-BDisk.preset -##-e 's/^\(ALL_kver="/boot/vmlinuz-linux\)\(.*\)/\1-BDisk\2/g' linux-BDisk.preset - -# add source for aufs3 -## 12.07.2014 - remove the "git checkout " once a bug is fixed. currently fails with: -##\ git checkout c75f6dddc1c58950c76cc1581e4b4c7ac8365bff > \/dev\/null 2>&1\ -## LD fs/aufs/built-in.o -## CC [M] fs/aufs/module.o -##In file included from fs/aufs/module.c:24:0: -##fs/aufs/inode.h:307:12: error: function declaration isn't a prototype -##[-Werror=strict-prototypes] -## AuStubInt0(au_cpup_xattr, h_dst, h_src, ignore_flags) -## ^ -##fs/aufs/aufs.h:28:21: note: in definition of macro 'AuStub' -## static inline type name(__VA_ARGS__) { body; } -## ^ -##fs/aufs/inode.h:307:1: note: in expansion of macro 'AuStubInt0' -## AuStubInt0(au_cpup_xattr, h_dst, h_src, ignore_flags) -## ^ -##cc1: some warnings being treated as errors -##scripts/Makefile.build:257: recipe for target 'fs/aufs/module.o' failed -##make[2]: *** [fs/aufs/module.o] Error 1 -##scripts/Makefile.build:404: recipe for target 'fs/aufs' failed -##make[1]: *** [fs/aufs] Error 2 -##Makefile:929: recipe for target 'fs' failed -##make: *** [fs] Error 2 -sed -i -e '/^prepare()\ {/a\ -\ git clone git:\/\/aufs.git.sourceforge.net\/gitroot\/aufs\/aufs3-standalone.git aufs3 > \/dev\/null 2>&1\ -\ cd aufs3\ -\ AUFS_MIN=$(git branch -a | grep "${KERNVER}" | tail -n1 | cut -f3 -d"/" | sed -e "s/aufs${KERNVER}//g ; s/\\\.\\\([0-9]*\\\).*$/\\\1/g")\ -\ if [ -n "${AUFS_MIN}" ] && [ -n "${KERNVER_MIN}" ] && [[ "${AUFS_MIN}" -le "${KERNVER_MIN}" ]] ; then CO="$(git branch -a | grep "${KERNVER}" | tail -n1 | cut -f3 -d"/")" ; else CO=aufs${KERNVER} ; fi \ -\ git checkout ${CO} > \/dev\/null 2>&1\ -\ cd ..\/' ${1} -#sed -i -e 's/^\(_kernelname=\).*$/\1"-BDisk"/' ${1} -sed -i -e '/^[[:space:]]*patch.*pkgver}"$/i rsync -a ../aufs3/Documentation/. Documentation/. ; rsync -a ../aufs3/fs/. fs/. ; cp -a ../aufs3/include/uapi/linux/aufs_type.h include/uapi/linux/. \ -\ for i in $(ls -1 ../aufs3/*.patch) ; do patch -p1 -i ../aufs3/${i} ; done' ${1} -# and we need to be sure to build aufs3-util -#sed -i -e '/^[[:space:]]*install\ -D\ -m644\ vmlinux.*$/a\ -#\ git clone git:\/\/git.code.sf.net\/p\/aufs\/aufs-util > \/dev\/null 2>&1\ -#\ cd aufs-util\ -#\ UTILVER=$(git branch -a | grep -v master | sort -nr | grep -v rcN | head -n1 | cut -f3 -d"\/")\ -#\ git checkout ${UTILVER} > \/dev\/null 2>&1\ -#\ make' ${1} - -# and configure the kernel. this gets messy. -#-e "s/^#[[:space:]]\\\(CONFIG_AUFS_FS\\\).*$/\\\1=m/g" \\\ -sed -i -e '/^[[:space:]]*make\ prepare.*$/i yes "" | make olddefconfig >/dev/null' ${1} -sed -i -e '/^[[:space:]]*make\ prepare.*$/a sed -i \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_FS\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_BRANCH_MAX_127\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_SBILIST\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_HNOTIFY\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_HFSNOTIFY\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_EXPORT\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_INO_T_64\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_FHSM\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_RDU\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_BDEV_LOOP\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(AUFS_BRANCH_MAX_511\\\).*$/\\\1=n/g" \\\ --e "s/^#[[:space:]]\\\(AUFS_BRANCH_MAX_1023\\\).*$/\\\1=n/g" \\\ --e "s/^#[[:space:]]\\\(AUFS_BRANCH_MAX_32767\\\).*$/\\\1=n/g" ${srcdir}/../config{,.x86_64}' ${1} -# yes, we have to do this twice. with a hammer. -sed -i -e '/^[[:space:]]*make\ prepare.*$/a sed -i \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_FS\\\).*$/\\\1=m/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_BRANCH_MAX_127\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_SBILIST\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_HNOTIFY\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_HFSNOTIFY\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_EXPORT\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_INO_T_64\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_FHSM\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_RDU\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(CONFIG_AUFS_BDEV_LOOP\\\).*$/\\\1=y/g" \\\ --e "s/^#[[:space:]]\\\(AUFS_BRANCH_MAX_511\\\).*$/\\\1=n/g" \\\ --e "s/^#[[:space:]]\\\(AUFS_BRANCH_MAX_1023\\\).*$/\\\1=n/g" \\\ --e "s/^#[[:space:]]\\\(AUFS_BRANCH_MAX_32767\\\).*$/\\\1=n/g" .config' ${1} -sed -i -e 's/^\([[:space:]]*yes\ ""\ |\ \)make\ config/\1make olddefconfig/' ${1} -# and we have to edit the linux.install as well. -sed -i -e 's/^\(KERNEL_NAME=\).*$/\1-BDisk/g' linux.install* diff --git a/extra/pre-build.d/root/post-build.sh b/extra/pre-build.d/root/post-build.sh index 62274d4..7f3422b 100755 --- a/extra/pre-build.d/root/post-build.sh +++ b/extra/pre-build.d/root/post-build.sh @@ -4,26 +4,5 @@ set -e apacman --noconfirm --noedit -S --needed customizepkg-scripting -echo -n "Compiling kernel sources..." -set +e -## Uncomment below and remove manual ABS/makepkg when https://github.com/oshazard/apacman/issues/2 is fulfulled -#apacman --noconfirm --noedit -S --needed linux - -export ABSROOT=/tmp -abs core/linux - -cd /tmp/core/linux -customizepkg --modify - -chown -R nobody:nobody /tmp/core/linux -sudo -u nobody makepkg --skipinteg -set -e - -yes '' | apacman --skipinteg --noconfirm --noedit -U /tmp/core/linux/linux-*.pkg.tar.xz - -#for i in $(ls -1 linux-*.pkg.tar.xz | sort); -#do - #apacman --skipinteg --noconfirm --noedit --noconfirm -U ${i} -#done echo "Done." diff --git a/extra/pre-build.d/usr/lib/initcpio/hooks/livecd b/extra/pre-build.d/usr/lib/initcpio/hooks/livecd index ea08dc0..d583ea0 100644 --- a/extra/pre-build.d/usr/lib/initcpio/hooks/livecd +++ b/extra/pre-build.d/usr/lib/initcpio/hooks/livecd @@ -1,8 +1,8 @@ # vim: set ft=sh: run_cleanuphook () { - msg ":: Mounting aufs on / with tmpfs=rw, ${root}=ro ..." - modprobe aufs + msg ":: Mounting OverlayFS on / with tmpfs=rw, ${root}=ro ..." + modprobe overlay echo "Now attempting aufs mount..." @@ -10,6 +10,6 @@ run_cleanuphook () { mount --move /new_root /new_root.hw mkdir /dev/shm mount -t tmpfs none /dev/shm - mount -t aufs none /new_root -o dirs=/dev/shm=rw:/new_root.hw=ro -o noatime + mount -t overlay overlay -olowerdir=/new_root.hw,upperdir=/new_root,workdir=/dev/shm -o noatime pkill -9 dropbear #kill SSH (in preparation for the live system starting ssh on port 22 } diff --git a/extra/pre-build.d/usr/lib/initcpio/install/livecd b/extra/pre-build.d/usr/lib/initcpio/install/livecd index 248e827..86299e8 100644 --- a/extra/pre-build.d/usr/lib/initcpio/install/livecd +++ b/extra/pre-build.d/usr/lib/initcpio/install/livecd @@ -5,6 +5,7 @@ build() add_module 'squashfs' add_module 'loop' add_module 'aufs' + add_module 'overlay' add_binary "sed" add_binary "pkill" @@ -16,6 +17,6 @@ build() help() { cat <> "${LOGFILE}.${FUNCNAME}" 2>&1 - else - ${CHROOTCMD} ${i}/ bash -c "${RACECAR_CHK}apacman --noconfirm --noedit --skipinteg -Syyu --devel --ignore linux,linux-${PNAME}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 - fi for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%.pacorig} ; done - ${CHROOTCMD} ${i}/ bash -c "${RACECAR_CHK}apacman --noconfirm --noedit --skipinteg -S --needed --ignore linux,linux-${PNAME} ${PKGLIST}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 + ${CHROOTCMD} ${i}/ bash -c "${RACECAR_CHK}apacman --noconfirm --noedit --skipinteg -S --needed --ignore linux ${PKGLIST}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%.pacorig} ; done #${CHROOTCMD} ${i}/ bash -c "apacman --noconfirm --noedit --skipinteg -S --needed ${PKGLIST}" - if [[ -n $(find ${BASEDIR}/extra/pre-build.d/ -type f -newer root.x86_64/boot/vmlinuz-linux-${PNAME}) ]]; - then - set +e - ${CHROOTCMD} ${i}/ bash -c "${RACECAR_CHK}mkinitcpio -p linux-${PNAME}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 - set -e - fi echo "Done." done @@ -71,7 +59,7 @@ function mentos { PKGLIST=$(sed -e '/^[[:space:]]*#/d ; /^[[:space:]]*$/d' ${BASEDIR}/extra/packages.64 | tr '\n' ' ') if [ -n "${PKGLIST}" ]; then - ${CHROOTCMD} ${CHROOTDIR64}/ bash -c "${RACECAR_CHK}apacman --noconfirm --noedit --skipinteg -S --needed ${PKGLIST}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 + ${CHROOTCMD} ${CHROOTDIR64}/ bash -c "yes '' | ${RACECAR_CHK}apacman --noconfirm --noedit --skipinteg -S --needed ${PKGLIST}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 fi for x in $(find ${CHROOTDIR64}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%.pacorig} ; done #${CHROOTCMD} ${CHROOTDIR64}/ bash -c "apacman --noconfirm --noedit --skipinteg -S --needed ${PKGLIST}" diff --git a/lib/mk.chroot.sh b/lib/mk.chroot.sh index 89e7ee4..4f3cbb1 100755 --- a/lib/mk.chroot.sh +++ b/lib/mk.chroot.sh @@ -186,6 +186,8 @@ EOF cp ${BASEDIR}/extra/bootstrap/apacman* ${i}/var/tmp/pkg/apacman.tar.xz #${CHROOTCMD} ${i} "pacman --noconfirm -U /var/tmp/pkg/apacman.tar.xz" >> "${LOGFILE}.${FUNCNAME}" 2>&1 ${CHROOTCMD} ${i} bash -c "pacman --noconfirm -U /var/tmp/pkg/apacman.tar.xz" >> "${LOGFILE}.${FUNCNAME}" 2>&1 + mkdir ${i}/var/tmp/apacman ; chmod 0750 ${i}/var/tmp/apacman ; chown 0:$(egrep '^aurbuild' ${i}/etc/group | cut -f3 -d":") ${i}/var/tmp/apacman + for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%%.pacorig} ; done ${CHROOTCMD} ${i} bash -c "apacman -S --noconfirm --noedit --skipinteg -S apacman-deps expac" >> "${LOGFILE}.${FUNCNAME}" 2>&1 #rm -rf ${i}/var/tmp/pkg #${CHROOTCMD} ${i}/ pacman -S --noconfirm --needed yaourt >> "${LOGFILE}.${FUNCNAME}" 2>&1 @@ -211,13 +213,15 @@ EOF PKGLIST=$(sed -e '/^[[:space:]]*#/d ; /^[[:space:]]*$/d' ${BASEDIR}/extra/packages.both | tr '\n' ' ') for i in ${CHROOTDIR32} ${CHROOTDIR64}; do - echo "Running post-build tasks (building kernel, etc.) in ${i}..." + echo "Running post-build tasks in ${i}..." ${CHROOTCMD} ${i}/ "/root/post-build.sh" >> "${LOGFILE}.${FUNCNAME}" 2>&1 for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%%.pacorig} ; done - #set +e - #${CHROOTCMD} ${i}/ /usr/bin/bash -c "apacman --noconfirm --noedit --skipinteg -S --needed linux" >> "${LOGFILE}.${FUNCNAME}" 2>&1 - #set -e - #for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%%.pacorig} ; done + set +e + ${CHROOTCMD} ${i}/ /usr/bin/bash -c "apacman --noconfirm --noedit --skipinteg -S --needed linux" >> "${LOGFILE}.${FUNCNAME}" 2>&1 + cp -a ${i}/boot/vmlinuz-linux ${i}/boot/vmlinuz/vmlinuz-linux-${PNAME} + cp -a ${i}/boot/initramfs-linux.img ${i}/boot/initramfs-linux-${PNAME}.img + set -e + for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%%.pacorig} ; done # Uncomment if you wish to use the mkpasswd binary from within the chroot... #${CHROOTCMD} ${i}/ bash -c "apacman --noconfirm --noedit --skipinteg -S --needed debian-whois-mkpasswd" >> "${LOGFILE}.${FUNCNAME}" 2>&1 #for x in $(find ${i}/etc/ -type f -iname "*.pacorig");do mv -f ${x} ${x%%.pacorig} ; done @@ -261,7 +265,7 @@ EOF for i in ${CHROOTDIR32} ${CHROOTDIR64}; do set +e - ${CHROOTCMD} ${i}/ /usr/bin/bash -c "mkinitcpio -p linux-${PNAME}" >> "${LOGFILE}.${FUNCNAME}" 2>&1 + ${CHROOTCMD} ${i}/ /usr/bin/bash -c "mkinitcpio -p linux" >> "${LOGFILE}.${FUNCNAME}" 2>&1 set -e done