diff -Naur '--exclude=.svn' '--exclude=.git' genkernel-3.4.18/defaults/initrd.defaults pentoo/genkernel/trunk/defaults/initrd.defaults --- genkernel-3.4.18/defaults/initrd.defaults 2012-03-24 23:23:39.476742487 -0400 +++ pentoo/genkernel/trunk/defaults/initrd.defaults 2011-10-16 21:32:06.000000000 -0400 @@ -72,6 +72,7 @@ CDROOT_TYPE='auto' NEW_ROOT='/newroot' CONSOLE='/dev/console' +MODULESD="mnt/cdrom" #XXX sub CDROOT_PATH instead LOOPS='/livecd.loop /zisofs /livecd.squashfs /image.squashfs /livecd.gcloop' diff -Naur '--exclude=.svn' '--exclude=.git' genkernel-3.4.18/defaults/initrd.scripts pentoo/genkernel/trunk/defaults/initrd.scripts --- genkernel-3.4.18/defaults/initrd.scripts 2012-03-24 23:23:39.476742487 -0400 +++ pentoo/genkernel/trunk/defaults/initrd.scripts 2012-02-03 00:03:57.395026177 -0500 @@ -215,6 +217,193 @@ [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!" } +# Insert a directory tree $2 to an union specified by $1 +# Top-level read-write branch is specified by it's index 0 +# $1 = union absolute path (starting with /) +# $2 = path to data directory +# +union_insert_dir() { + # Always mount it over the precedent (add:1:) + mount -n -o remount,add:1:$2=rr aufs $1 + if [ $? = '0' ] + then + good_msg "Addition of $2 to $1 successful" + fi +} + +# Insert all modules found in $1, usually mnt/cdrom +# added to allow users to add their own apps. +union_insert_modules() { + for module in `ls ${NEW_ROOT}/$1/modules/*.mo 2>/dev/null| sort` + do + mkdir -p ${MEMORY}/modules/`basename ${module} .mo` + mount -o loop,ro ${module} ${MEMORY}/modules/`basename ${module} .mo` + union_insert_dir $UNION ${MEMORY}/modules/`basename ${module} .mo` + done + for module in `ls ${NEW_ROOT}/$1/modules/*.lzm 2>/dev/null| sort` + do + mkdir -p ${MEMORY}/modules/`basename ${module} .lzm` + mount -o loop,ro ${module} ${MEMORY}/modules/`basename ${module} .lzm` + union_insert_dir $UNION ${MEMORY}/modules/`basename ${module} .lzm` + done +} + +# Function to create an ext2 fs on $CHANGESDEV, $CHANGESMNT mountpoint +create_changefs() { + local size + while [ 1 ] + do + read -p '<< Size of file (Enter for default 256 Mb): ' size + if [ -z "$size" ]; then + let size=256 + fi + let size="$size" + if [ $size -lt 16 ] + then + bad_msg "Please give a size of at least 16 Mb" + else + dd if=/dev/zero of=$CHANGESMNT/livecd.aufs bs=1M count=$size + if [ $? = '0' ] + then + good_msg "Creation of livecd.aufs, $size Mb on $CHANGESDEV successful, formatting it ext2" + mke2fs -F $CHANGESMNT/livecd.aufs + break + else + rm -f $CHANGESMNT/livecd.aufs + bad_msg "Unable to create livecd.aufs on $CHANGESDEV of $size Mb" + bad_msg "Please give a size of at least 16 Mb" + bad_msg "Also check if your disk is full or read-only ?" + read -p '<< Type "a" to abort, anything else to continue : ' doabort + if [ "$doabort" = "a" ]; then + return 1 + fi + fi + fi + done + return 0 +} + +setup_aufs() { + if [ "${USE_AUFS_NORMAL}" -eq '1' ] + then + # Directory used for rw changes in union mount filesystem + UNION=/union + MEMORY=/memory + # Mountpoint for the changesdev + CHANGESMNT=$NEW_ROOT/mnt/changesdev + if [ -z "$UID" ] + then + CHANGES=$MEMORY/aufs_changes/default + else + CHANGES=$MEMORY/aufs_changes/$UID + fi + + mkdir -p ${MEMORY} + mkdir -p ${UNION} + mkdir -p ${CHANGESMNT} + for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys + do + mkdir -p "${NEW_ROOT}/${i}" + chmod 755 "${NEW_ROOT}/${i}" + done + [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 + [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1 + + bootstrapCD + if [ -n "${AUFS}" ] + then + if [ "${AUFS}" = "detect" ] + then + CHANGESMNT="${NEW_ROOT}/mnt/cdrom" + CHANGESDEV=${REAL_ROOT} + else + CHANGESDEV=${AUFS} + good_msg "mounting $CHANGESDEV to $MEMORY for aufs support" + # mount -t auto $CHANGESDEV $MEMORY + mount -t auto $CHANGESDEV $CHANGESMNT + ret=$? + if [ "${ret}" -ne 0 ] + then + bad_msg "mount of $CHANGESDEV failed falling back to ramdisk based aufs" + unset AUFS + fi + fi + # Check and attempt to create the changesfile + if [ ! -e $CHANGESMNT/livecd.aufs ] && [ -n "${AUFS}" ] + then + create_changefs + mount -t auto $CHANGESMNT/livecd.aufs $MEMORY + elif [ -n "${AUFS}" ] + then + local nbpass=0 + while [ 1 ] + do + mount -t auto $CHANGESMNT/livecd.aufs $MEMORY + ret=$? + if [ "${ret}" -ne 0 ] + then + if [ $nbpass -eq 0 ] + then + bad_msg "mounting of changes file failed, Running e2fsck" + e2fsck $CHANGESMNT/livecd.aufs + nbpass=$(($nbpass + 1)) + else + bad_msg "mount of $CHANGESDEV failed falling back to ramdisk based aufs" + bad_msg "your livecd.aufs might be messed up, and I couldn't fix it" + bad_msg "moving livecd.aufs to livecd.aufs.bad" + mv $CHANGESMNT/livecd.aufs $CHANGESMNT/livecd.aufs.bad + bad_msg "try to fix it yourself with e2fsck later on, sorry for disturbing" + break + fi + else + if [ $nbpass -eq 1 ] + then + good_msg "e2fsck seemed successful. Please check your files after bootup" + fi + break + fi + done + if [ -f ${MEMORY}/.doclean.sh ] + then + good_msg "finishing the permanent changes cleanup" + . ${MEMORY}/.doclean.sh + rm ${MEMORY}/.doclean.sh + fi + fi + # mount tmpfs only in the case when changes= boot parameter was + # empty or we were not able to mount the storage device + if [ "${CDROOT}" -eq '1' -a ! -f ${CHANGESMNT}/livecd.aufs ] + then + umount $MEMORY + bad_msg "failed to find livecd.aufs file on $CHANGESDEV" + bad_msg "create an ext2 livecd.aufs file on this device if you wish to use it for aufs" + bad_msg "falling back to ramdisk based aufs for safety" + mount -t tmpfs tmpfs $MEMORY + XINO=$MEMORY + else + XINO=$MEMORY/xino + mkdir -p $XINO + mount -t tmpfs tmpfs $XINO + fi + else + good_msg "Mounting ramdisk to $MEMORY for aufs support..." + mount -t tmpfs tmpfs $MEMORY + XINO=$MEMORY + fi + + mkdir -p $CHANGES + mount -t aufs -n -o nowarn_perm,udba=none,xino=$XINO/.aufs.xino,br:$CHANGES=rw aufs ${UNION} + ret=$? + if [ "${ret}" -ne 0 ] + then + bad_msg "Can't setup union ${UNION} in directory!" + USE_AUFS_NORMAL=0 + fi + else + USE_AUFS_NORMAL=0 + fi +} + findnfsmount() { if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q then @@ -510,7 +701,11 @@ } setup_keymap() { XXX: needed? - if [ "${DO_keymap}" ] + if [ -e $MEMORY/keyboard ] + then + . $MEMORY/keyboard + loadkmap < /lib/keymaps/${XKEYBOARD}.map + elif [ "${DO_keymap}" ] XXX: ask grimmlin then if [ ! -e /dev/vc/0 -a ! -e /dev/tty0 ] then @@ -523,7 +718,10 @@ [ "${DEVBIND}" = '1' ] && umount /dev XXX: needed? - if [ -e /etc/sysconfig/keyboard -a "${CDROOT}" = '1' ] + if [ -e /etc/sysconfig/keyboard -a "${USE_AUFS_NORMAL}" = '1' ] + then + cp /etc/sysconfig/keyboard $MEMORY + elif [ -e /etc/sysconfig/keyboard -a "${CDROOT}" = '1' ] XXX: ask grimmlin then mkdir -p ${NEW_ROOT}/etc/sysconfig/ cp /etc/sysconfig/keyboard ${NEW_ROOT}/etc/sysconfig/keyboard @@ -595,13 +794,15 @@ then echo good_msg "Keeping default keymap" splash set_msg "Keeping default keymap" XXX: needed? + mkdir -p /etc/sysconfig + echo "XKEYBOARD=us" > /etc/sysconfig/keyboard XXX: ask grimmlin else bad_msg "Sorry, but keymap ''${keymap}'' is invalid!" unset keymap diff -Naur '--exclude=.svn' '--exclude=.git' genkernel-3.4.18/defaults/linuxrc pentoo/genkernel/trunk/defaults/linuxrc --- genkernel-3.4.18/defaults/linuxrc 2012-03-24 23:23:39.476742487 -0400 +++ pentoo/genkernel/trunk/defaults/linuxrc 2011-10-16 21:32:06.000000000 -0400 @@ -78,6 +78,41 @@ isoboot\=*) ISOBOOT=`parse_opt "${x}"` ;; + aufs) + USE_AUFS_NORMAL=1 + ;; + aufs\=*) + USE_AUFS_NORMAL=1 + CMD_AUFS=`parse_opt "${x}"` + echo ${CMD_AUFS}|grep , >/dev/null 2>&1 + if [ "$?" -eq '0' ] + then + UID=`echo ${CMD_AUFS#*,}` + AUFS=`echo ${CMD_AUFS%,*}` + else + AUFS=${CMD_AUFS} + fi + ;; + changes\=*) + USE_AUFS_NORMAL=1 + CMD_AUFS=`parse_opt "${x}"` + echo ${CMD_AUFS}|grep , >/dev/null 2>&1 + if [ "$?" -eq '0' ] + then + UID=`echo ${CMD_AUFS#*,}` + AUFS=`echo ${CMD_AUFS%,*}` + else + AUFS=${CMD_AUFS} + fi + ;; + persistent) + USE_AUFS_NORMAL=1 + AUFS="detect" + ;; + # Allow user to specify the modules location + modules\=*) + MODULESD=`parse_opt "${x}"` + ;; # Start Volume manager options dolvm) USE_LVM_NORMAL=1 @@ -350,23 +384,32 @@ fi mkdir -p "${NEW_ROOT}" XXX: but why? -CHROOT="${NEW_ROOT}" - -# Run debug shell if requested -rundebugshell +CHROOT=${NEW_ROOT} XXX: no reason at all if [ "${CDROOT}" = '1' ] then - good_msg "Making tmpfs for ${NEW_ROOT}" - mount -n -t tmpfs tmpfs "${NEW_ROOT}" - - for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys - do - mkdir -p "${NEW_ROOT}/${i}" - chmod 755 "${NEW_ROOT}/${i}" - done - [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 - [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1 + setup_aufs + setup_keymap + + # Run debug shell if requested + rundebugshell + + if [ "${USE_AUFS_NORMAL}" -eq '1' ] + then + CHROOT=${UNION} + else + CHROOT=${NEW_ROOT} + good_msg "Making tmpfs for ${NEW_ROOT}" + mount -t tmpfs tmpfs ${NEW_ROOT} + + for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys + do + mkdir -p "${NEW_ROOT}/${i}" + chmod 755 "${NEW_ROOT}/${i}" + done + [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 + [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1 + fi # For SGI LiveCDs ... if [ "${LOOPTYPE}" = "sgimips" ] @@ -382,7 +425,7 @@ [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1 fi - if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] + if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] && [ "${USE_AUFS_NORMAL}" != '1' ] then bootstrapCD fi @@ -613,7 +656,23 @@ fi fi - + if [ "${USE_AUFS_NORMAL}" -eq '1' ] + then + union_insert_dir ${UNION} ${NEW_ROOT}/${FS_LOCATION} + + # Make sure fstab notes livecd is mounted ro. Makes system skip remount which fails on aufs dirs. + sed -e 's|\(.*\s/\s*tmpfs\s*\)defaults\(.*\)|\1defaults,ro\2|' /${UNION}/etc/fstab > /${UNION}/etc/fstab.new + mv /${UNION}/etc/fstab.new /${UNION}/etc/fstab + warn_msg "Adding all modules in $MODULESD/modules/" + if [ "${MODULESD}" = "mnt/cdrom" ] + then + union_insert_modules mnt/cdrom + else + mkdir ${NEW_ROOT}/mnt/modulesd + mount "${MODULESD}" ${NEW_ROOT}/mnt/modulesd + union_insert_modules ${NEW_ROOT}/mnt/modulesd + fi + fi # Unpacking additional packages from NFS mount # This is useful for adding kernel modules to /lib @@ -637,53 +696,54 @@ setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION} CHROOT=/union else - - good_msg "Copying read-write image contents to tmpfs" - # Copy over stuff that should be writable - (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") - - # Now we do the links. - for x in ${ROOT_LINKS} - do - if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] + if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] then - ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null - else - # List all subdirectories of x - find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory - do - # Strip the prefix of the FS_LOCATION - directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}" + good_msg "Copying read-write image contents to tmpfs" + # Copy over stuff that should be writable + (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") - # Skip this directory if we already linked a parent directory - if [ "${current_parent}" != '' ]; then - var=`echo "${directory}" | grep "^${current_parent}"` - if [ "${var}" != '' ]; then - continue - fi - fi - # Test if the directory exists already - if [ -e "/${NEW_ROOT}/${directory}" ] + # Now we do the links. + for x in ${ROOT_LINKS} + do + if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] then - # It does exist, link all the individual files - for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}` + ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null + else + # List all subdirectories of x + find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory do - if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then - ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null + # Strip the prefix of the FS_LOCATION + directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}" + + # Skip this directory if we already linked a parent directory + if [ "${current_parent}" != '' ]; then + var=`echo "${directory}" | grep "^${current_parent}"` + if [ "${var}" != '' ]; then + continue + fi + fi + # Test if the directory exists already + if [ -e "/${NEW_ROOT}/${directory}" ] + then + # It does exist, link all the individual files + for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}` + do + if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then + ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null + fi + done + else + # It does not exist, make a link to the livecd + ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null + current_parent="${directory}" fi done - else - # It does not exist, make a link to the livecd - ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null - current_parent="${directory}" fi done - fi - done - - mkdir initramfs proc tmp sys 2>/dev/null - chmod 1777 tmp + mkdir initramfs proc tmp sys 2>/dev/null + chmod 1777 tmp + fi fi #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'` @@ -704,6 +764,12 @@ setup_unionfs /union_changes ${NEW_ROOT} mkdir -p ${UNION}/tmp/.initrd fi + + if [ "${USE_AUFS_NORMAL}" -eq '1' ] + then + union_insert_dir ${UNION} ${NEW_ROOT} + mkdir -p ${UNION}/tmp/.initrd + fi fi # Execute script on the cdrom just before boot to update things if necessary @@ -717,6 +783,35 @@ verbose_kmsg +if [ "${USE_AUFS_NORMAL}" -eq '1' ] +then + mkdir -p /${CHROOT}/.unions/memory 2>/dev/null + mount -o move /memory /${CHROOT}/.unions/memory || echo '*: Failed to move aufs /memory into the system root!' + for i in tmp var/tmp mnt/gentoo mnt/livecd + do + mkdir -p ${CHROOT}/$i + chmod 755 ${CHROOT}/$i + done + # This will prevent from putting junk on the CHANGESDEV + mkdir -p ${CHROOT}/usr/portage/distfiles + mount -t tmpfs tmpfs ${CHROOT}/var/tmp + mount -t tmpfs tmpfs ${CHROOT}/tmp + mount -t tmpfs tmpfs ${CHROOT}/usr/portage/distfiles + warn_msg "/tmp /var/tmp /usr/portage/distfiles are mounted in ram" + warn_msg "consider saving important files elsewhere..." + read -t 3 UNUSEDVAL + mount -o bind ${NEW_ROOT}/mnt/cdrom ${CHROOT}/mnt/cdrom + mount -o bind ${NEW_ROOT}/mnt/livecd ${CHROOT}/mnt/livecd + if [ -e $MEMORY/keyboard -a "${CDROOT}" -eq '1' ] + then + cp $MEMORY/keyboard ${CHROOT}/etc/sysconfig/keyboard + elif [ -e /etc/sysconfig/keyboard -a "${CDROOT}" -eq '1' ] + then + mkdir -p ${NEW_ROOT}/etc/sysconfig/ + cp /etc/sysconfig/keyboard ${CHROOT}/etc/sysconfig/keyboard + fi +fi + echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}" cd "${CHROOT}" diff -Naur '--exclude=.svn' '--exclude=.git' genkernel-3.4.18/gen_initramfs.sh pentoo/genkernel/trunk/gen_initramfs.sh --- genkernel-3.4.18/gen_initramfs.sh 2012-03-24 23:23:39.478742478 -0400 +++ pentoo/genkernel/trunk/gen_initramfs.sh 2011-10-16 21:32:05.000000000 -0400 @@ -69,6 +69,24 @@ rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null } +# Used to add e2fs file making inside initramfs for aufs changes saving +append_e2fstools(){ + if [ -d "${TEMP}/initramfs-e2fsprogs-temp" ] + then + rm -r "${TEMP}/initramfs-e2fsprogs-temp/" + fi + print_info 1 'E2FSTOOLS: Adding support (compiling binaries)...' + # Using different name for blkid compatibility + compile_e2fstools + cd ${TEMP} + mkdir -p "${TEMP}/initramfs-e2fsprogs-temp/" + /bin/tar -jxpf "${E2FSPROGS_BINCACHE}" -C "${TEMP}/initramfs-e2fsprogs-temp/" || + gen_die "Could not extract e2fsprogs binary cache!" + cd "${TEMP}/initramfs-e2fsprogs-temp/" + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" + rm -rf "${TEMP}/initramfs-e2fsprogs-temp" > /dev/null +} + append_blkid(){ if [ -d "${TEMP}/initramfs-blkid-temp" ] then @@ -507,6 +525,7 @@ rm -r "${TEMP}/initramfs-aux-temp/" fi mkdir -p "${TEMP}/initramfs-aux-temp/etc" + mkdir -p "${TEMP}/initramfs-aux-temp/bin" mkdir -p "${TEMP}/initramfs-aux-temp/sbin" if [ -f "${CMD_LINUXRC}" ] then @@ -620,6 +639,7 @@ append_data 'base_layout' append_data 'auxilary' "${BUSYBOX}" append_data 'busybox' "${BUSYBOX}" + append_data 'e2fstools' append_data 'lvm' "${LVM}" append_data 'dmraid' "${DMRAID}" append_data 'iscsi' "${ISCSI}" diff -Naur '--exclude=.svn' '--exclude=.git' genkernel-3.4.18/genkernel.conf pentoo/genkernel/trunk/genkernel.conf --- genkernel-3.4.18/genkernel.conf 2012-03-24 23:23:39.479742473 -0400 +++ pentoo/genkernel/trunk/genkernel.conf 2011-10-16 21:32:05.000000000 -0400 @@ -229,6 +229,7 @@ XXX: seperate patch for this E2FSPROGS_VER="VERSION_E2FSPROGS" E2FSPROGS_DIR="e2fsprogs-${E2FSPROGS_VER}" E2FSPROGS_SRCTAR="${DISTDIR}/e2fsprogs-${E2FSPROGS_VER}.tar.gz" +E2FSPROGS_BINCACHE="%%CACHE%%/e2fsprogs-${E2FSPROGS_VER}-%%ARCH%%.bz2" BLKID_BINCACHE="%%CACHE%%/blkid-${E2FSPROGS_VER}-%%ARCH%%.bz2" FUSE_VER="VERSION_FUSE"