From 7149888e45e8ef7471ebb1461f3edb568bdd8b94 Mon Sep 17 00:00:00 2001 From: "Rick Farina (Zero_Chaos)" Date: Wed, 8 May 2013 22:24:51 -0400 Subject: Proper AUFS support This patch is what we have been using for the Pentoo LiveCDs for about 5 years with the changes suggested by lxnay merged in. As much as possible has been addressed (with the exception of the man page documentation). Please review this code as the next version will likely be suggested for inclusion (once I write the documentation for the new features). Signed-off-by: Rick Farina (Zero_Chaos) --- defaults/initrd.defaults | 1 + defaults/initrd.scripts | 180 +++++++++++++++++++++++++++++++++++++++++++ defaults/linuxrc | 194 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 321 insertions(+), 54 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index 69be5160..a0176427 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -65,6 +65,7 @@ CDROOT_PATH='/mnt/cdrom' # This is the file that the cdroot will be checked for as a # marker. It must exist RELATIVE to the cdroot. CDROOT_MARKER='/livecd' +AUFS_CHANGESFILE=livecd.aufs LOOPS='/livecd.loop /zisofs /livecd.squashfs /image.squashfs /livecd.gcloop' diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 153c3790..1bae2761 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -234,6 +234,186 @@ mount_sysfs() { [ ${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 ${CDROOT_PATH} +# 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) + 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}/${AUFS_CHANGESFILE} bs=1M count=${size} + if [ $? = '0' ] + then + good_msg "Creation of ${AUFS_CHANGESFILE}, ${size} Mb on ${CHANGESDEV} successful, formatting it ext2" + mke2fs -F ${CHANGESMNT}/${AUFS_CHANGESFILE} + break + else + rm -f ${CHANGESMNT}/${AUFS_CHANGESFILE} + bad_msg "Unable to create ${AUFS_CHANGESFILE} 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 ${CDROOT_PATH} 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}${CDROOT_PATH}" + CHANGESDEV=${REAL_ROOT} + else + CHANGESDEV=${AUFS} + good_msg "mounting ${CHANGESDEV} to ${MEMORY} for aufs support" + 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}/${AUFS_CHANGESFILE} ] && [ -n "${AUFS}" ] + then + create_changefs + mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} + elif [ -n "${AUFS}" ] + then + local nbpass=0 + while [ 1 ] + do + mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} + ret=$? + if [ "${ret}" -ne 0 ] + then + if [ ${nbpass} -eq 0 ] + then + bad_msg "mounting of changes file failed, Running e2fsck" + e2fsck ${CHANGESMNT}/${AUFS_CHANGESFILE} + nbpass=$((${nbpass} + 1)) + else + bad_msg "mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" + bad_msg "your ${AUFS_CHANGESFILE} might be messed up, and I couldn't fix it" + bad_msg "moving ${AUFS_CHANGESFILE} to ${AUFS_CHANGESFILE}.bad" + mv ${CHANGESMNT}/${AUFS_CHANGESFILE} ${CHANGESMNT}/${AUFS_CHANGESFILE}.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 ran successfully. Please check your files after bootup" + fi + break + fi + done + 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}/${AUFS_CHANGESFILE} ] + then + umount ${MEMORY} + bad_msg "failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" + bad_msg "create an ext2 ${AUFS_CHANGESFILE} 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 diff --git a/defaults/linuxrc b/defaults/linuxrc index 6401614f..e2e1b6f5 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -253,6 +253,38 @@ do 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 + ;; + aufs.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 + ;; + aufs.persistent) + USE_AUFS_NORMAL=1 + AUFS="detect" + ;; + # Allow user to specify the modules location + aufs.modules\=*) + MODULESD=$(parse_opt "${x}") + ;; unionfs) if [ ! -x /sbin/unionfs ] then @@ -425,19 +457,26 @@ rundebugshell "before setting up the root filesystem" if [ "${CDROOT}" = '1' ] then - good_msg "Making tmpfs for ${NEW_ROOT}" - mount -n -t tmpfs tmpfs "${NEW_ROOT}" + setup_aufs + if [ "${USE_AUFS_NORMAL}" -eq '1' ] + then + CHROOT=${UNION} + else + CHROOT=${NEW_ROOT} + good_msg "Making tmpfs for ${NEW_ROOT}" + mount -n -t tmpfs tmpfs ${NEW_ROOT} - for i in dev mnt proc run sys tmp mnt/livecd mnt/key tmp/.initrd mnt/gentoo - do - mkdir -p "${NEW_ROOT}/${i}" - chmod 755 "${NEW_ROOT}/${i}" - done - [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" - [ ! -e "${NEW_ROOT}/dev/null" ] && mknod -m 660 "${NEW_ROOT}"/dev/null c 1 3 - [ ! -e "${NEW_ROOT}/dev/zero" ] && mknod -m 660 "${NEW_ROOT}"/dev/zero c 1 5 - [ ! -e "${NEW_ROOT}/dev/console" ] && mknod -m 660 "${NEW_ROOT}"/dev/console c 5 1 - [ ! -e "${NEW_ROOT}/dev/ttyS0" ] && mknod -m 600 "${NEW_ROOT}"/dev/ttyS0 c 4 64 + for i in dev mnt ${CDROOT_PATH} proc run mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys + do + mkdir -p "${NEW_ROOT}/${i}" + chmod 755 "${NEW_ROOT}/${i}" + done + [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" + [ ! -e "${NEW_ROOT}/dev/null" ] && mknod -m 666 "${NEW_ROOT}"/dev/null c 1 3 + [ ! -e "${NEW_ROOT}/dev/zero" ] && mknod -m 666 "${NEW_ROOT}"/dev/zero c 1 5 + [ ! -e "${NEW_ROOT}/dev/console" ] && mknod -m 600 "${NEW_ROOT}"/dev/console c 5 1 + [ ! -e "${NEW_ROOT}/dev/ttyS0" ] && mknod -m 660 "${NEW_ROOT}"/dev/ttyS0 c 4 64 + fi # For SGI LiveCDs ... if [ "${LOOPTYPE}" = "sgimips" ] @@ -452,7 +491,7 @@ then [ ! -e "${NEW_ROOT}/dev/$minor" ] && mknod -m 600 "${NEW_ROOT}/dev/tty$minor" c 4 $minor done - if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] + if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] && [ "${USE_AUFS_NORMAL}" != '1' ] then bootstrapCD fi @@ -764,7 +803,23 @@ then 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 [ -z "${MODULESD}" ] + then + union_insert_modules ${CDROOT_PATH} + 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 @@ -787,56 +842,60 @@ then then setup_unionfs ${NEW_ROOT} /${FS_LOCATION} CHROOT=/union - elif [ "${USE_AUFS_NORMAL}" != '1' ]; then - - 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}") || { - bad_msg "Copying failed, dropping into a shell." - do_rundebugshell - } - - # Now we do the links. - for x in ${ROOT_LINKS} - do - if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] + else + #XXX Note to potential reviewers. diff formats this section very very oddly. Be sure to review this hunk after applied, do NOT simply read the diff + 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 + 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}") || { + bad_msg "Copying failed, dropping into a shell." + do_rundebugshell + } + + # Now we do the links. + for x in ${ROOT_LINKS} do - # 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}" ] + 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 run 2>/dev/null - chmod 1777 tmp + fi + #XXX: end extremely confusing hunk # have handy /mnt/cdrom (CDROOT_PATH) as well _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" @@ -863,6 +922,12 @@ else 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 # Mount the additional things as required by udev & systemd @@ -907,6 +972,27 @@ fi 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 --bind ${NEW_ROOT}${CDROOT_PATH} ${CHROOT}${CDROOT_PATH} + mount --bind ${NEW_ROOT}/mnt/livecd ${CHROOT}/mnt/livecd +fi + good_msg "Booting (initramfs)" cd "${CHROOT}" -- cgit v1.2.3-65-gdbad From afa17c13d7292e1ba22e33334151898b4979893e Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 17 Mar 2014 12:20:40 -0700 Subject: cleanup: these directories were dropped in the aufs patch. Signed-off-by: Robin H. Johnson --- defaults/linuxrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index e2e1b6f5..8b474aa3 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -891,7 +891,7 @@ then done fi done - mkdir initramfs proc tmp sys 2>/dev/null + mkdir -p initramfs proc tmp run sys 2>/dev/null chmod 1777 tmp fi -- cgit v1.2.3-65-gdbad From d87b93eb93223aca061b919aee7b781fdd2899b4 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 17 Mar 2014 12:32:04 -0700 Subject: Refactor tmpfs creation to aufs env. Signed-off-by: Robin H. Johnson --- defaults/linuxrc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index 8b474aa3..b4ce21d0 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -976,17 +976,21 @@ 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 + for i in 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" + str="" + for i in tmp var/tmp usr/portage/distfiles + do + mkdir -p ${CHROOT}/$i + chmod 755 ${CHROOT}/$i + mount -t tmpfs tmpfs ${CHROOT}/$i + str="${str} ${i}" + done + warn_msg "${str}are mounted in ram" warn_msg "consider saving important files elsewhere..." read -t 3 UNUSEDVAL mount --bind ${NEW_ROOT}${CDROOT_PATH} ${CHROOT}${CDROOT_PATH} -- cgit v1.2.3-65-gdbad From efe010d4a2a5f9239cdf19fcd8589f03215bcfdc Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 17 Mar 2014 12:38:09 -0700 Subject: Document the very large if structure for AUFS. Signed-off-by: Robin H. Johnson --- defaults/linuxrc | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index b4ce21d0..aaf27ada 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -733,7 +733,7 @@ then test_success 'Mount filesystem' FS_LOCATION='mnt/livecd' # Setup the loopback mounts, if unencrypted - else + else # if [ -n "${CRYPT_ROOT}" ] if [ "${LOOPTYPE}" = 'normal' ] then good_msg 'Mounting loop filesystem' @@ -801,13 +801,14 @@ then test_success 'mount /dev/loop0 /' FS_LOCATION='mnt/livecd' fi - fi + fi # if [ -n "${CRYPT_ROOT}" ] 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. + # TODO: remounting all tmpfs as RO seems weird, can we be more specific? 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/" @@ -843,7 +844,7 @@ then setup_unionfs ${NEW_ROOT} /${FS_LOCATION} CHROOT=/union else - #XXX Note to potential reviewers. diff formats this section very very oddly. Be sure to review this hunk after applied, do NOT simply read the diff + #XXX Note to potential reviewers. diff formats this section very very oddly. Be sure to review this hunk after applied, do NOT simply read the diff if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] then good_msg "Copying read-write image contents to tmpfs" @@ -887,22 +888,22 @@ then # 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 + fi # if [ -e "/${NEW_ROOT}/${directory}" ] ... else + done # while read directory + fi # if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] ... else + done # for x in ${ROOT_LINKS} mkdir -p initramfs proc tmp run sys 2>/dev/null chmod 1777 tmp - fi - #XXX: end extremely confusing hunk + fi # if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] + #XXX: end extremely confusing hunk - # have handy /mnt/cdrom (CDROOT_PATH) as well - _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" - mount --bind "${CDROOT_PATH}" "${_new_cdroot}" + # have handy /mnt/cdrom (CDROOT_PATH) as well + _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" + [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" + mount --bind "${CDROOT_PATH}" "${_new_cdroot}" - fi + fi # if [ "${USE_UNIONFS_NORMAL}" = '1' ] ... else #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||') #if [ "${UML}" = 'UML' ] @@ -914,7 +915,7 @@ then # Let Init scripts know that we booted from CD export CDBOOT CDBOOT=1 -else +else # if [ "${CDROOT}" = '1' ] if [ "${USE_UNIONFS_NORMAL}" = '1' ] then mkdir /union_changes @@ -928,7 +929,7 @@ else mkdir -p ${UNION}/tmp/.initrd fi -fi +fi # if [ "${CDROOT}" = '1' ] # Mount the additional things as required by udev & systemd if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then @@ -959,7 +960,7 @@ for fs in $fslist; do if ! $cmd; then bad_msg "Unable to mount $dev for $fs" fi -done +done # for fs in $fslist; do # Execute script on the cdrom just before boot to update things if necessary cdupdate -- cgit v1.2.3-65-gdbad From 9e90b4923c0b017ebbdf8864371e6fa108cee058 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 22 May 2014 16:52:30 -0400 Subject: Fix kernel line argument handling. Fix kernel line argument handling since it's using old deprecated function. --- defaults/linuxrc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index aaf27ada..8620352b 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -255,35 +255,35 @@ do ;; aufs\=*) USE_AUFS_NORMAL=1 - CMD_AUFS=$(parse_opt "${x}") - echo ${CMD_AUFS}|grep , >/dev/null 2>&1 + echo ${x#*=} | grep , &>/dev/null + if [ "$?" -eq '0' ] then - UID=$(echo ${CMD_AUFS#*,}) - AUFS=$(echo ${CMD_AUFS%,*}) + UID=${x#*,} + AUFS=${x%,*} else - AUFS=${CMD_AUFS} + AUFS=${x#*=} fi ;; aufs.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 - ;; + USE_AUFS_NORMAL=1 + echo ${x#*=} | grep , &>/dev/null + + if [ "$?" -eq '0' ] + then + UID=${x#*,} + AUFS=${x%,*} + else + AUFS=${x#*=} + fi + ;; aufs.persistent) USE_AUFS_NORMAL=1 AUFS="detect" ;; # Allow user to specify the modules location aufs.modules\=*) - MODULESD=$(parse_opt "${x}") + MODULESD=${x#*=} ;; unionfs) if [ ! -x /sbin/unionfs ] -- cgit v1.2.3-65-gdbad From fc508c9decf6155fae67c84164454e8d8f0c9c4d Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 22 May 2014 17:10:12 -0400 Subject: Removing use of 'let' and cleaner output of dd command, plus minor cosmetic --- defaults/initrd.scripts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 1bae2761..34af3d70 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -267,14 +267,16 @@ union_insert_modules() { # 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 + read -p '<< Size of file (Press Enter for default 256 Mb): ' size if [ -z "${size}" ]; then - let size=256 + size=256 fi - let size="${size}" - if [ ${size} -lt 16 ] + size="${size}" + + if [ ${size} -lt 16 ] then bad_msg "Please give a size of at least 16 Mb" else @@ -282,13 +284,13 @@ create_changefs() { if [ $? = '0' ] then good_msg "Creation of ${AUFS_CHANGESFILE}, ${size} Mb on ${CHANGESDEV} successful, formatting it ext2" - mke2fs -F ${CHANGESMNT}/${AUFS_CHANGESFILE} + mke2fs -F ${CHANGESMNT}/${AUFS_CHANGESFILE} &>/dev/null break else rm -f ${CHANGESMNT}/${AUFS_CHANGESFILE} bad_msg "Unable to create ${AUFS_CHANGESFILE} 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 ?" + bad_msg "Ensure your disk is not full or read-only" read -p '<< Type "a" to abort, anything else to continue : ' doabort if [ "${doabort}" = "a" ]; then return 1 -- cgit v1.2.3-65-gdbad From 8223248cb727650efe1c0f718df2345965e233ea Mon Sep 17 00:00:00 2001 From: "Rick Farina (Zero_Chaos)" Date: Thu, 22 May 2014 17:11:10 -0400 Subject: remove pointless changes size warning a check has been added rendering this warning obsolete --- defaults/initrd.scripts | 1 - 1 file changed, 1 deletion(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 34af3d70..263ed189 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -289,7 +289,6 @@ create_changefs() { else rm -f ${CHANGESMNT}/${AUFS_CHANGESFILE} bad_msg "Unable to create ${AUFS_CHANGESFILE} on ${CHANGESDEV} of ${size} Mb" - bad_msg "Please give a size of at least 16 Mb" bad_msg "Ensure your disk is not full or read-only" read -p '<< Type "a" to abort, anything else to continue : ' doabort if [ "${doabort}" = "a" ]; then -- cgit v1.2.3-65-gdbad From 1748c95286f7554cca5facb39ec744b635d46401 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 29 May 2014 03:55:05 +0200 Subject: Cleaner shutdown process preventing aufs related mounts from being umounted along with mnt/{livecd,cdrom} and others. Addition of a variable for aufs changes so that required directory can be create upon successful creation of the livecd image file. --- defaults/initrd.defaults | 3 +++ defaults/initrd.scripts | 1 + defaults/linuxrc | 20 +++++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index a0176427..aa9f85cb 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -65,6 +65,9 @@ CDROOT_PATH='/mnt/cdrom' # This is the file that the cdroot will be checked for as a # marker. It must exist RELATIVE to the cdroot. CDROOT_MARKER='/livecd' + +# AUFS variables +AUFS_CHANGES=false AUFS_CHANGESFILE=livecd.aufs LOOPS='/livecd.loop /zisofs /livecd.squashfs /image.squashfs /livecd.gcloop' diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 263ed189..68c0ef7a 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -285,6 +285,7 @@ create_changefs() { then good_msg "Creation of ${AUFS_CHANGESFILE}, ${size} Mb on ${CHANGESDEV} successful, formatting it ext2" mke2fs -F ${CHANGESMNT}/${AUFS_CHANGESFILE} &>/dev/null + AUFS_CHANGES=true break else rm -f ${CHANGESMNT}/${AUFS_CHANGESFILE} diff --git a/defaults/linuxrc b/defaults/linuxrc index 8620352b..6d942a13 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -811,6 +811,15 @@ then # TODO: remounting all tmpfs as RO seems weird, can we be more specific? 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 + + # RC_NO_UMOUNTS variable for a clean shutdown/reboot + test ! $(grep 'RC_NO_UMOUNTS="/newroot|/newroot/mnt/aufs|\ +/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|/.unions/\ +memory|/.unions/memory/xino"' "${UNION}"/etc/rc.conf) && + echo "RC_NO_UMOUNTS=\"/newroot|/newroot/mnt/aufs|"\ +"/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|"\ +"/.unions/memory|/.unions/memory/xino\"">> "${UNION}"/etc/rc.conf + warn_msg "Adding all modules in $MODULESD/modules/" if [ -z "${MODULESD}" ] then @@ -820,6 +829,10 @@ then mount "${MODULESD}" ${NEW_ROOT}/mnt/modulesd union_insert_modules ${NEW_ROOT}/mnt/modulesd fi + + mkdir -p "${UNION}"/newroot/mnt/aufs + test ${AUFS_CHANGES} && test ! -d "${UNION}"/newroot/mnt/changesdev && + mkdir "${UNION}"/newroot/mnt/changesdev fi # Unpacking additional packages from NFS mount @@ -975,9 +988,10 @@ 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 mnt/gentoo mnt/livecd + mkdir -p /${CHROOT}/.unions/memory + mount -o move /memory /${CHROOT}/.unions/memory + test_success "Failed to move aufs /memory into the system root" + for i in mnt/gentoo mnt/livecd ${CDROOT_PATH} do mkdir -p ${CHROOT}/$i chmod 755 ${CHROOT}/$i -- cgit v1.2.3-65-gdbad From 48f1906ab8d4e8e3172511a95571018ad62e01a8 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 29 May 2014 04:40:18 +0200 Subject: This fixes /etc/fstab from not working while in setup_aufs function and instead includes it in the union path. --- defaults/initrd.scripts | 1 - defaults/linuxrc | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 68c0ef7a..c76abb50 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -1380,7 +1380,6 @@ setup_squashfs_aufs() { [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}" [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}" - echo "aufs / aufs defaults 0 0" > "${NEW_ROOT}"/etc/fstab for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done # have handy /mnt/cdrom (CDROOT_PATH) as well diff --git a/defaults/linuxrc b/defaults/linuxrc index 6d942a13..d5b424c3 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -820,6 +820,10 @@ memory|/.unions/memory/xino"' "${UNION}"/etc/rc.conf) && "/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|"\ "/.unions/memory|/.unions/memory/xino\"">> "${UNION}"/etc/rc.conf + # Fstab change for aufs + test ! $(grep aufs "${UNION}"/etc/fstab) && + echo "aufs / aufs defaults 0 0" > "${UNION}"/etc/fstab + warn_msg "Adding all modules in $MODULESD/modules/" if [ -z "${MODULESD}" ] then -- cgit v1.2.3-65-gdbad From f29d304e5d71f65778ea7bff7e9628851bb17ed5 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 29 May 2014 10:15:13 +0200 Subject: Removing --bind on some directories to prevent ${NEW_ROOT} path from existing in favor of --move. Got rid of the no longer required subshell call for aufs ${NEW_ROOT} overlay. --- defaults/initrd.scripts | 11 ++--------- defaults/linuxrc | 7 ++++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index c76abb50..2fe540ba 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -1363,10 +1363,9 @@ getdvhoff() { } setup_squashfs_aufs() { - ( # Setup aufs directories and vars - local overlay=/mnt/overlay - local static=/mnt/livecd + overlay=/mnt/overlay + static=/mnt/livecd for i in "${overlay}" "${static}"; do [ ! -d "${i}" ] && mkdir -p "${i}" @@ -1381,12 +1380,6 @@ setup_squashfs_aufs() { [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}" [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}" for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done - - # have handy /mnt/cdrom (CDROOT_PATH) as well - local new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}" - mount --bind "${CDROOT_PATH}" "${new_cdroot}" - ) } setup_unionfs() { diff --git a/defaults/linuxrc b/defaults/linuxrc index d5b424c3..0a91c58d 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -995,7 +995,7 @@ then mkdir -p /${CHROOT}/.unions/memory mount -o move /memory /${CHROOT}/.unions/memory test_success "Failed to move aufs /memory into the system root" - for i in mnt/gentoo mnt/livecd ${CDROOT_PATH} + for i in mnt/gentoo mnt/livecd /mnt/overlay ${CDROOT_PATH} do mkdir -p ${CHROOT}/$i chmod 755 ${CHROOT}/$i @@ -1012,8 +1012,9 @@ then warn_msg "${str}are mounted in ram" warn_msg "consider saving important files elsewhere..." read -t 3 UNUSEDVAL - mount --bind ${NEW_ROOT}${CDROOT_PATH} ${CHROOT}${CDROOT_PATH} - mount --bind ${NEW_ROOT}/mnt/livecd ${CHROOT}/mnt/livecd + for i in ${CDROOT_PATH} ${overlay} ${static}; do + mount --move ${NEW_ROOT}${i} ${CHROOT}${i} + done fi good_msg "Booting (initramfs)" -- cgit v1.2.3-65-gdbad From 5a62af115cf85e15fbac4f35d98af2a5bf34d004 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 02:51:08 +0200 Subject: Enhanced the shutdown process and changed from using ${UNION} to ${CHROOT} to better understand the logic behind things as CHROOT is set to ${UNION} anyways. RC_NO_UMOUNTS is more dynamic now and should scale up. --- defaults/initrd.defaults | 1 + defaults/linuxrc | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index aa9f85cb..9937e008 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -58,6 +58,7 @@ KSUFF='.ko' REAL_ROOT='' CONSOLE='/dev/console' NEW_ROOT='/newroot' +RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/overlay|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino" CDROOT='0' CDROOT_DEV='' CDROOT_TYPE='auto' diff --git a/defaults/linuxrc b/defaults/linuxrc index 0a91c58d..5d4d2a17 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -805,24 +805,38 @@ then if [ "${USE_AUFS_NORMAL}" -eq '1' ] then - union_insert_dir ${UNION} ${NEW_ROOT}/${FS_LOCATION} + union_insert_dir ${CHROOT} ${NEW_ROOT}/${FS_LOCATION} # Make sure fstab notes livecd is mounted ro. Makes system skip remount which fails on aufs dirs. # TODO: remounting all tmpfs as RO seems weird, can we be more specific? - 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 + #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 # RC_NO_UMOUNTS variable for a clean shutdown/reboot - test ! $(grep 'RC_NO_UMOUNTS="/newroot|/newroot/mnt/aufs|\ -/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|/.unions/\ -memory|/.unions/memory/xino"' "${UNION}"/etc/rc.conf) && - echo "RC_NO_UMOUNTS=\"/newroot|/newroot/mnt/aufs|"\ -"/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|"\ -"/.unions/memory|/.unions/memory/xino\"">> "${UNION}"/etc/rc.conf + RC_MOUNTS=$(grep 'RC_NO_UMOUNTS' "${CHROOT}"/etc/rc.conf) + RESULTS=false + + # Iterate through ${RC_MOUNTS} to find our duplicate(s) and or remove obsolete lines when ever + # our RC_NO_UMOUNTS variable changes. + printf '%s\n' ${RC_MOUNTS} | while read -r mount; do + if [[ "${mount}" = "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"" ]]; then + RESULTS=true + else + # Escape characters in ${mounts} for use in sed + mount_re=$(echo ${mount} | sed -e 's/\//\\\//g' -e 's/\&/\\\&/g') + + # Remove non matching pattern + sed -i "/${mount_re}/d" "${CHROOT}"/etc/rc.conf + fi + done + + if ! ${RESULTS}; then + echo 'RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/overlay|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino"'>> "${CHROOT}"/etc/rc.conf + fi # Fstab change for aufs - test ! $(grep aufs "${UNION}"/etc/fstab) && - echo "aufs / aufs defaults 0 0" > "${UNION}"/etc/fstab + test ! $(grep -o ^aufs "${CHROOT}"/etc/fstab) && + echo "aufs / aufs defaults 0 0" > "${CHROOT}"/etc/fstab warn_msg "Adding all modules in $MODULESD/modules/" if [ -z "${MODULESD}" ] @@ -834,9 +848,12 @@ memory|/.unions/memory/xino"' "${UNION}"/etc/rc.conf) && union_insert_modules ${NEW_ROOT}/mnt/modulesd fi - mkdir -p "${UNION}"/newroot/mnt/aufs - test ${AUFS_CHANGES} && test ! -d "${UNION}"/newroot/mnt/changesdev && - mkdir "${UNION}"/newroot/mnt/changesdev + # Create the directories for our new union mounts + test ! -d "${CHROOT}${NEW_ROOT}" && mkdir -p "${CHROOT}${NEW_ROOT}" + + if ${AUFS_CHANGES} && [ ! -d "${CHROOT}${NEW_ROOT}/mnt/changesdev" ]; then + mkdir -p "${CHROOT}${NEW_ROOT}/mnt/changesdev" + fi fi # Unpacking additional packages from NFS mount -- cgit v1.2.3-65-gdbad From 6e5daaadb38e1bae6a30c57f9997ff01528dc6aa Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 03:03:37 +0200 Subject: Cleanup dd output from changes file creation --- defaults/initrd.scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 2fe540ba..a9ec5abb 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -280,7 +280,7 @@ create_changefs() { then bad_msg "Please give a size of at least 16 Mb" else - dd if=/dev/zero of=${CHANGESMNT}/${AUFS_CHANGESFILE} bs=1M count=${size} + dd if=/dev/zero of=${CHANGESMNT}/${AUFS_CHANGESFILE} bs=1M count=${size} &>/dev/null if [ $? = '0' ] then good_msg "Creation of ${AUFS_CHANGESFILE}, ${size} Mb on ${CHANGESDEV} successful, formatting it ext2" -- cgit v1.2.3-65-gdbad From d8f76f80288f19c0d2d90e9c4999879ad0c61d1e Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 04:02:30 +0200 Subject: Restructure the setup_aufs function, it had redundant code and moved the call to it further down the pipe. --- defaults/initrd.scripts | 181 +++++++++++++++++++++++------------------------- defaults/linuxrc | 2 +- 2 files changed, 89 insertions(+), 94 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index a9ec5abb..14800e49 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -302,115 +302,110 @@ create_changefs() { } setup_aufs() { - if [ "${USE_AUFS_NORMAL}" -eq '1' ] + # 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 - # 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 + 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 ${CDROOT_PATH} 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 + mkdir -p ${MEMORY} + mkdir -p ${UNION} + mkdir -p ${CHANGESMNT} + for i in dev mnt ${CDROOT_PATH} 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}" ] + bootstrapCD + if [ -n "${AUFS}" ] + then + if [ "${AUFS}" = "detect" ] then - if [ "${AUFS}" = "detect" ] + CHANGESMNT="${NEW_ROOT}${CDROOT_PATH}" + CHANGESDEV=${REAL_ROOT} + else + CHANGESDEV=${AUFS} + good_msg "mounting ${CHANGESDEV} to ${MEMORY} for aufs support" + mount -t auto ${CHANGESDEV} ${CHANGESMNT} + ret=$? + if [ "${ret}" -ne 0 ] then - CHANGESMNT="${NEW_ROOT}${CDROOT_PATH}" - CHANGESDEV=${REAL_ROOT} - else - CHANGESDEV=${AUFS} - good_msg "mounting ${CHANGESDEV} to ${MEMORY} for aufs support" - mount -t auto ${CHANGESDEV} ${CHANGESMNT} + 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}/${AUFS_CHANGESFILE} ] && [ -n "${AUFS}" ] + then + create_changefs + mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} + elif [ -n "${AUFS}" ] + then + local nbpass=0 + while [ 1 ] + do + mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} 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}/${AUFS_CHANGESFILE} ] && [ -n "${AUFS}" ] - then - create_changefs - mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} - elif [ -n "${AUFS}" ] - then - local nbpass=0 - while [ 1 ] - do - mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} - ret=$? - if [ "${ret}" -ne 0 ] + if [ ${nbpass} -eq 0 ] then - if [ ${nbpass} -eq 0 ] - then - bad_msg "mounting of changes file failed, Running e2fsck" - e2fsck ${CHANGESMNT}/${AUFS_CHANGESFILE} - nbpass=$((${nbpass} + 1)) - else - bad_msg "mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" - bad_msg "your ${AUFS_CHANGESFILE} might be messed up, and I couldn't fix it" - bad_msg "moving ${AUFS_CHANGESFILE} to ${AUFS_CHANGESFILE}.bad" - mv ${CHANGESMNT}/${AUFS_CHANGESFILE} ${CHANGESMNT}/${AUFS_CHANGESFILE}.bad - bad_msg "try to fix it yourself with e2fsck later on, sorry for disturbing" - break - fi + bad_msg "mounting of changes file failed, Running e2fsck" + e2fsck ${CHANGESMNT}/${AUFS_CHANGESFILE} + nbpass=$((${nbpass} + 1)) else - if [ ${nbpass} -eq 1 ] - then - good_msg "e2fsck ran successfully. Please check your files after bootup" - fi + bad_msg "mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" + bad_msg "your ${AUFS_CHANGESFILE} might be messed up, and I couldn't fix it" + bad_msg "moving ${AUFS_CHANGESFILE} to ${AUFS_CHANGESFILE}.bad" + mv ${CHANGESMNT}/${AUFS_CHANGESFILE} ${CHANGESMNT}/${AUFS_CHANGESFILE}.bad + bad_msg "try to fix it yourself with e2fsck later on, sorry for disturbing" break fi - done - 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}/${AUFS_CHANGESFILE} ] - then - umount ${MEMORY} - bad_msg "failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" - bad_msg "create an ext2 ${AUFS_CHANGESFILE} 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} + else + if [ ${nbpass} -eq 1 ] + then + good_msg "e2fsck ran successfully. Please check your files after bootup" + fi + break + fi + done 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 ] + # 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}/${AUFS_CHANGESFILE} ] then - bad_msg "Can't setup union ${UNION} in directory!" - USE_AUFS_NORMAL=0 + umount ${MEMORY} + bad_msg "failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" + bad_msg "create an ext2 ${AUFS_CHANGESFILE} 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 } diff --git a/defaults/linuxrc b/defaults/linuxrc index 5d4d2a17..894ec45a 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -457,9 +457,9 @@ rundebugshell "before setting up the root filesystem" if [ "${CDROOT}" = '1' ] then - setup_aufs if [ "${USE_AUFS_NORMAL}" -eq '1' ] then + setup_aufs CHROOT=${UNION} else CHROOT=${NEW_ROOT} -- cgit v1.2.3-65-gdbad From eeb82b88ce756f4c6569820129b6fb3e27829edb Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 04:06:42 +0200 Subject: Output cleaning --- defaults/initrd.scripts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 14800e49..0e44e614 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -335,7 +335,7 @@ setup_aufs() { else CHANGESDEV=${AUFS} good_msg "mounting ${CHANGESDEV} to ${MEMORY} for aufs support" - mount -t auto ${CHANGESDEV} ${CHANGESMNT} + mount -t auto ${CHANGESDEV} ${CHANGESMNT} &>/dev/null ret=$? if [ "${ret}" -ne 0 ] then @@ -383,7 +383,7 @@ setup_aufs() { # empty or we were not able to mount the storage device if [ "${CDROOT}" -eq '1' -a ! -f ${CHANGESMNT}/${AUFS_CHANGESFILE} ] then - umount ${MEMORY} + umount ${MEMORY} &>/dev/null bad_msg "failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" bad_msg "create an ext2 ${AUFS_CHANGESFILE} file on this device if you wish to use it for aufs" bad_msg "falling back to ramdisk based aufs for safety" -- cgit v1.2.3-65-gdbad From de648288f5cc03636396e93b7128969b95101a53 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 04:31:13 +0200 Subject: Wording changes, cosmetic crap --- defaults/initrd.scripts | 21 +++++++++++---------- defaults/linuxrc | 7 ++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 0e44e614..fe563fe2 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -334,12 +334,12 @@ setup_aufs() { CHANGESDEV=${REAL_ROOT} else CHANGESDEV=${AUFS} - good_msg "mounting ${CHANGESDEV} to ${MEMORY} for aufs support" + good_msg "Mounting ${CHANGESDEV} to ${MEMORY} for aufs support" mount -t auto ${CHANGESDEV} ${CHANGESMNT} &>/dev/null ret=$? if [ "${ret}" -ne 0 ] then - bad_msg "mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" + bad_msg "Mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" unset AUFS fi fi @@ -359,15 +359,15 @@ setup_aufs() { then if [ ${nbpass} -eq 0 ] then - bad_msg "mounting of changes file failed, Running e2fsck" + bad_msg "Mounting of changes file failed, Running e2fsck" e2fsck ${CHANGESMNT}/${AUFS_CHANGESFILE} nbpass=$((${nbpass} + 1)) else - bad_msg "mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" + bad_msg "Mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" bad_msg "your ${AUFS_CHANGESFILE} might be messed up, and I couldn't fix it" bad_msg "moving ${AUFS_CHANGESFILE} to ${AUFS_CHANGESFILE}.bad" mv ${CHANGESMNT}/${AUFS_CHANGESFILE} ${CHANGESMNT}/${AUFS_CHANGESFILE}.bad - bad_msg "try to fix it yourself with e2fsck later on, sorry for disturbing" + bad_msg "Try to fix it yourself with e2fsck" break fi else @@ -383,19 +383,20 @@ setup_aufs() { # empty or we were not able to mount the storage device if [ "${CDROOT}" -eq '1' -a ! -f ${CHANGESMNT}/${AUFS_CHANGESFILE} ] then + XINO=${MEMORY} umount ${MEMORY} &>/dev/null - bad_msg "failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" - bad_msg "create an ext2 ${AUFS_CHANGESFILE} file on this device if you wish to use it for aufs" - bad_msg "falling back to ramdisk based aufs for safety" + bad_msg "Failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" + bad_msg "Create an ext2 ${AUFS_CHANGESFILE} file on this device if you wish to use it for aufs" + bad_msg "Falling back to ramdisk based aufs for safety" + good_msg "Mounting ramdisk to $MEMORY for aufs support" 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..." + good_msg "Mounting ramdisk to $MEMORY for aufs support" mount -t tmpfs tmpfs ${MEMORY} XINO=${MEMORY} fi diff --git a/defaults/linuxrc b/defaults/linuxrc index 894ec45a..009b4c44 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -758,9 +758,10 @@ then do_rundebugshell } else - good_msg 'Mounting squashfs & aufs filesystems' + good_msg 'Mounting squashfs filesystem' + setup_squashfs_aufs - test_success 'Mount filesystem' + test_success 'Mount aufs filesystem' fi FS_LOCATION='mnt/livecd' elif [ "${LOOPTYPE}" = 'gcloop' ] @@ -1027,7 +1028,7 @@ then str="${str} ${i}" done warn_msg "${str}are mounted in ram" - warn_msg "consider saving important files elsewhere..." + warn_msg "consider saving important files elsewhere" read -t 3 UNUSEDVAL for i in ${CDROOT_PATH} ${overlay} ${static}; do mount --move ${NEW_ROOT}${i} ${CHROOT}${i} -- cgit v1.2.3-65-gdbad From dbf39867145b304b63ade4f52c21f28d4ea8aa89 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 04:46:09 +0200 Subject: Better handle on if aufs.modules kernel parameter is used --- defaults/initrd.defaults | 1 + defaults/linuxrc | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index 9937e008..b08ff50c 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -68,6 +68,7 @@ CDROOT_PATH='/mnt/cdrom' CDROOT_MARKER='/livecd' # AUFS variables +AUFS_MODULES=false AUFS_CHANGES=false AUFS_CHANGESFILE=livecd.aufs diff --git a/defaults/linuxrc b/defaults/linuxrc index 009b4c44..281de8e4 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -284,6 +284,7 @@ do # Allow user to specify the modules location aufs.modules\=*) MODULESD=${x#*=} + AUFS_MODULES=true ;; unionfs) if [ ! -x /sbin/unionfs ] @@ -839,15 +840,18 @@ then test ! $(grep -o ^aufs "${CHROOT}"/etc/fstab) && echo "aufs / aufs defaults 0 0" > "${CHROOT}"/etc/fstab - warn_msg "Adding all modules in $MODULESD/modules/" - if [ -z "${MODULESD}" ] - then - union_insert_modules ${CDROOT_PATH} - else - mkdir ${NEW_ROOT}/mnt/modulesd - mount "${MODULESD}" ${NEW_ROOT}/mnt/modulesd - union_insert_modules ${NEW_ROOT}/mnt/modulesd - fi + if ${AUFS_MODULES}; then + warn_msg "Adding all modules in $MODULESD/modules/" + + if [ -z "${MODULESD}" ] + then + union_insert_modules ${CDROOT_PATH} + else + mkdir ${NEW_ROOT}/mnt/modulesd + mount "${MODULESD}" ${NEW_ROOT}/mnt/modulesd + union_insert_modules ${NEW_ROOT}/mnt/modulesd + fi + fi # Create the directories for our new union mounts test ! -d "${CHROOT}${NEW_ROOT}" && mkdir -p "${CHROOT}${NEW_ROOT}" -- cgit v1.2.3-65-gdbad From 064e285bbe80b527b6a53256382fd40beea0de5b Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Fri, 30 May 2014 04:57:13 +0200 Subject: coding style changes --- defaults/linuxrc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index 281de8e4..42749d6f 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -1014,26 +1014,34 @@ verbose_kmsg if [ "${USE_AUFS_NORMAL}" -eq '1' ] then - mkdir -p /${CHROOT}/.unions/memory - mount -o move /memory /${CHROOT}/.unions/memory + UNION_MEMORY=${CHROOT}/.unions/memory + + mkdir -p "${UNION_MEMORY}" + mount --move "${MEMORY}" "${UNION_MEMORY}" test_success "Failed to move aufs /memory into the system root" - for i in mnt/gentoo mnt/livecd /mnt/overlay ${CDROOT_PATH} + + for i in /mnt/gentoo /mnt/livecd /mnt/overlay ${CDROOT_PATH} do - mkdir -p ${CHROOT}/$i - chmod 755 ${CHROOT}/$i + mkdir -p "${CHROOT}${i}" + chmod 755 "${CHROOT}${i}" done + # This will prevent from putting junk on the CHANGESDEV str="" - for i in tmp var/tmp usr/portage/distfiles + for i in /tmp /var/tmp /usr/portage/distfiles do - mkdir -p ${CHROOT}/$i - chmod 755 ${CHROOT}/$i - mount -t tmpfs tmpfs ${CHROOT}/$i - str="${str} ${i}" + mkdir -p "${CHROOT}${i}" + chmod 755 "${CHROOT}${i}" + + mount -t tmpfs tmpfs "${CHROOT}${i}" + str="${i} ${str}" done + warn_msg "${str}are mounted in ram" warn_msg "consider saving important files elsewhere" - read -t 3 UNUSEDVAL + + sleep 2 + for i in ${CDROOT_PATH} ${overlay} ${static}; do mount --move ${NEW_ROOT}${i} ${CHROOT}${i} done -- cgit v1.2.3-65-gdbad From 09cce549319068807b9e1dba7a3ad3160da3f160 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Mon, 2 Jun 2014 17:19:23 +0200 Subject: This improves the way we handle RC_NO_UMOUNT variable in openrc so that future changes can scale and fixes previous bugs which didn't actually remove duplicates. --- defaults/linuxrc | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index 42749d6f..86b1954e 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -816,24 +816,39 @@ then # RC_NO_UMOUNTS variable for a clean shutdown/reboot RC_MOUNTS=$(grep 'RC_NO_UMOUNTS' "${CHROOT}"/etc/rc.conf) - RESULTS=false # Iterate through ${RC_MOUNTS} to find our duplicate(s) and or remove obsolete lines when ever # our RC_NO_UMOUNTS variable changes. - printf '%s\n' ${RC_MOUNTS} | while read -r mount; do - if [[ "${mount}" = "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"" ]]; then - RESULTS=true - else - # Escape characters in ${mounts} for use in sed - mount_re=$(echo ${mount} | sed -e 's/\//\\\//g' -e 's/\&/\\\&/g') - - # Remove non matching pattern - sed -i "/${mount_re}/d" "${CHROOT}"/etc/rc.conf - fi - done + if [ -n "${RC_MOUNTS}" ]; then + printf '%s\n' ${RC_MOUNTS} | + { + while read -r mount; do + # Remove double quotes from ${mount} + new_mount=$(echo ${mount} | sed 's/"//g') + + if [[ "${new_mount}" = "RC_NO_UMOUNTS="${RC_NO_UMOUNTS}"" ]]; then + RESULTS=false + else + # Escape characters in ${mounts} for use in sed + mount_re=$(echo ${mount} | sed -e 's/\//\\\//g' -e 's/\&/\\\&/g') + + # Remove non matching pattern + sed -i "/${mount_re}/d" "${CHROOT}"/etc/rc.conf + + RESULTS=true + fi + done + + # no RC_NO_UMOUNTS match found + if ${RESULTS}; then return 1;fi + } + else + echo "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"">> "${CHROOT}"/etc/rc.conf + fi - if ! ${RESULTS}; then - echo 'RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/overlay|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino"'>> "${CHROOT}"/etc/rc.conf + # An RC_NO_UMOUNTS was not found that matches our current one + if [ $? -eq 1 ]; then + echo "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"">> "${CHROOT}"/etc/rc.conf fi # Fstab change for aufs -- cgit v1.2.3-65-gdbad From adce982154f2139c47bf3514fd4d11424a00392d Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Tue, 3 Jun 2014 02:46:43 +0200 Subject: dokeymap implementation for AUFS's union --- defaults/linuxrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/defaults/linuxrc b/defaults/linuxrc index 86b1954e..da88bf02 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -868,6 +868,12 @@ then fi fi + # Copy user keymap file + if [ -e /etc/sysconfig/keyboard ]; then + [ ! -d ${CHROOT}/etc/sysconfig ] && mkdir -p ${CHROOT}/etc/sysconfig + cp /etc/sysconfig/keyboard ${CHROOT}/etc/sysconfig/ + fi + # Create the directories for our new union mounts test ! -d "${CHROOT}${NEW_ROOT}" && mkdir -p "${CHROOT}${NEW_ROOT}" -- cgit v1.2.3-65-gdbad From 75fe8bf4d8eb452cbd866140f76e847666f30598 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Tue, 3 Jun 2014 03:36:28 +0200 Subject: A new bootstrapFS function has been added to cut on duplicate code use which both aufs and squashfs boot types use and this it's moved to the top of the boot process. --- defaults/initrd.scripts | 70 +++++++++++++++++++++++++++++++++---------------- defaults/linuxrc | 29 +++----------------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index fe563fe2..eb5ed6a4 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -177,6 +177,52 @@ devicelist(){ echo ${DEVICES} } +bootstrapFS() { + if [ "${USE_AUFS_NORMAL}" -eq '1' ]; then + # Directories 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} ${UNION} ${CHANGESMNT} + else + # Legacy SquashFS implementation + good_msg "Making tmpfs for ${NEW_ROOT}" + mount -n -t tmpfs tmpfs ${NEW_ROOT} + fi + + # Setup the filesystem nodes and directories + for i in ${CDROOT_PATH} /mnt/livecd /mnt/key /mnt/gentoo /tmp /tmp/.initrd /dev /proc /run /sys; do + mkdir -p "${NEW_ROOT}${i}" + chmod 755 "${NEW_ROOT}${i}" + done + + [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" + [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 + [ ! -e "${NEW_ROOT}/dev/zero" ] && mknod -m 660 "${NEW_ROOT}"/dev/zero c 1 5 + [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1 + [ ! -e "${NEW_ROOT}/dev/ttyS0" ] && mknod -m 600 "${NEW_ROOT}"/dev/ttyS0 c 4 64 + + # For SGI LiveCDs + if [ "${LOOPTYPE}" = "sgimips" ]; then + [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0 + [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0 + fi + + # Required for splash to work. Not an issue with the initrd as this + # device isn't created there and is not needed. + for minor in 0 1 ; do + [ ! -e "${NEW_ROOT}/dev/$minor" ] && mknod -m 600 "${NEW_ROOT}/dev/tty$minor" c 4 $minor + done +} + bootstrapCD() { local DEVICES= @@ -302,30 +348,8 @@ create_changefs() { } setup_aufs() { - # 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 ${CDROOT_PATH} 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" ] diff --git a/defaults/linuxrc b/defaults/linuxrc index da88bf02..0e40d165 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -458,40 +458,17 @@ rundebugshell "before setting up the root filesystem" if [ "${CDROOT}" = '1' ] then + # Setup the root filesystem + bootstrapFS + if [ "${USE_AUFS_NORMAL}" -eq '1' ] then setup_aufs CHROOT=${UNION} else CHROOT=${NEW_ROOT} - good_msg "Making tmpfs for ${NEW_ROOT}" - mount -n -t tmpfs tmpfs ${NEW_ROOT} - - for i in dev mnt ${CDROOT_PATH} proc run mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys - do - mkdir -p "${NEW_ROOT}/${i}" - chmod 755 "${NEW_ROOT}/${i}" - done - [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" - [ ! -e "${NEW_ROOT}/dev/null" ] && mknod -m 666 "${NEW_ROOT}"/dev/null c 1 3 - [ ! -e "${NEW_ROOT}/dev/zero" ] && mknod -m 666 "${NEW_ROOT}"/dev/zero c 1 5 - [ ! -e "${NEW_ROOT}/dev/console" ] && mknod -m 600 "${NEW_ROOT}"/dev/console c 5 1 - [ ! -e "${NEW_ROOT}/dev/ttyS0" ] && mknod -m 660 "${NEW_ROOT}"/dev/ttyS0 c 4 64 fi - # For SGI LiveCDs ... - if [ "${LOOPTYPE}" = "sgimips" ] - then - [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0 - [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0 - fi - - # Required for splash to work. Not an issue with the initrd as this - # device isn't created there and is not needed. - for minor in 0 1 ; do - [ ! -e "${NEW_ROOT}/dev/$minor" ] && mknod -m 600 "${NEW_ROOT}/dev/tty$minor" c 4 $minor - done - if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] && [ "${USE_AUFS_NORMAL}" != '1' ] then bootstrapCD -- cgit v1.2.3-65-gdbad From aa073bf7ee057fa5d7b1643ccb25618162c2bbd6 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Tue, 3 Jun 2014 19:48:14 +0200 Subject: Better implementation which was originally done in 946918e & 7a38d63. --- defaults/initrd.scripts | 36 ++++++++++++++++++++++++++++++++++++ defaults/linuxrc | 38 ++------------------------------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index eb5ed6a4..91056b1c 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -310,6 +310,42 @@ union_insert_modules() { done } +# Implements RC_NO_UMOUNTS variable into ${CHROOT}/etc/rc.conf for a cleaner shutdown process +# This should really go into /etc/init.d/localmounts but until then we manually set this here +conf_rc_no_umounts() { + local conf nomount fnd + conf="${CHROOT}/etc/rc.conf" + fnd=0 + + if nomount=$(grep -n '^[[:blank:]]*RC_NO_UMOUNTS=' $conf); then + local i n data cmd IFS + IFS=' +' + set -- $nomount + unset IFS + + for i; do + n=${i%%:*}; i=${i#"$n"} + data=${i#*=} + + case $data in + "\"$RC_NO_UMOUNTS\""|"'$RC_NO_UMOUNTS'") fnd=1;; + *) cmd="$cmd$n d;" + esac + done + + if [ -n "$cmd" ]; then + sed -i "${cmd%;}" $conf + test_success "Unable to edit rc.conf" + fi + fi + + if [ 0 -eq "$fnd" ]; then + printf 'RC_NO_UMOUNTS="%s"\n' "$RC_NO_UMOUNTS" >> $conf + test_success "Unable to write to rc.conf" + fi +} + # Function to create an ext2 fs on $CHANGESDEV, $CHANGESMNT mountpoint create_changefs() { local size diff --git a/defaults/linuxrc b/defaults/linuxrc index 0e40d165..a6c4806c 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -791,42 +791,8 @@ then #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 - # RC_NO_UMOUNTS variable for a clean shutdown/reboot - RC_MOUNTS=$(grep 'RC_NO_UMOUNTS' "${CHROOT}"/etc/rc.conf) - - # Iterate through ${RC_MOUNTS} to find our duplicate(s) and or remove obsolete lines when ever - # our RC_NO_UMOUNTS variable changes. - if [ -n "${RC_MOUNTS}" ]; then - printf '%s\n' ${RC_MOUNTS} | - { - while read -r mount; do - # Remove double quotes from ${mount} - new_mount=$(echo ${mount} | sed 's/"//g') - - if [[ "${new_mount}" = "RC_NO_UMOUNTS="${RC_NO_UMOUNTS}"" ]]; then - RESULTS=false - else - # Escape characters in ${mounts} for use in sed - mount_re=$(echo ${mount} | sed -e 's/\//\\\//g' -e 's/\&/\\\&/g') - - # Remove non matching pattern - sed -i "/${mount_re}/d" "${CHROOT}"/etc/rc.conf - - RESULTS=true - fi - done - - # no RC_NO_UMOUNTS match found - if ${RESULTS}; then return 1;fi - } - else - echo "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"">> "${CHROOT}"/etc/rc.conf - fi - - # An RC_NO_UMOUNTS was not found that matches our current one - if [ $? -eq 1 ]; then - echo "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"">> "${CHROOT}"/etc/rc.conf - fi + # Function to handle the RC_NO_UMOUNTS variable in ${CHROOT}/etc/rc.conf + conf_rc_no_umounts # Fstab change for aufs test ! $(grep -o ^aufs "${CHROOT}"/etc/fstab) && -- cgit v1.2.3-65-gdbad From 98da3645c1cd72895af0c9131db6024388f63af2 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 5 Jun 2014 01:04:30 +0200 Subject: This introduces changes to former commits d8e2d4d & 720a60f in which there are fstab changes and tmpfs mounts which are combined into one /etc/fstab instead. --- defaults/linuxrc | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index a6c4806c..8b3ff875 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -794,9 +794,19 @@ then # Function to handle the RC_NO_UMOUNTS variable in ${CHROOT}/etc/rc.conf conf_rc_no_umounts - # Fstab change for aufs - test ! $(grep -o ^aufs "${CHROOT}"/etc/fstab) && - echo "aufs / aufs defaults 0 0" > "${CHROOT}"/etc/fstab + # Fstab changes for aufs + if ! grep -q '^aufs' "${CHROOT}"/etc/fstab 2>/dev/null; then + for i in /var/tmp /tmp /usr/portage/distfiles; do + [ ! -d "${CHROOT}${i}" ] && mkdir -p "${CHROOT}${i}" + done + + cat > "${CHROOT}"/etc/fstab << FSTAB +aufs / aufs defaults 0 0 +vartmp /var/tmp tmpfs defaults 0 0 +tmp /tmp tmpfs defaults 0 0 +distfiles /usr/portage/distfiles tmpfs defaults 0 0 +FSTAB + fi if ${AUFS_MODULES}; then warn_msg "Adding all modules in $MODULESD/modules/" @@ -990,22 +1000,6 @@ then chmod 755 "${CHROOT}${i}" done - # This will prevent from putting junk on the CHANGESDEV - str="" - for i in /tmp /var/tmp /usr/portage/distfiles - do - mkdir -p "${CHROOT}${i}" - chmod 755 "${CHROOT}${i}" - - mount -t tmpfs tmpfs "${CHROOT}${i}" - str="${i} ${str}" - done - - warn_msg "${str}are mounted in ram" - warn_msg "consider saving important files elsewhere" - - sleep 2 - for i in ${CDROOT_PATH} ${overlay} ${static}; do mount --move ${NEW_ROOT}${i} ${CHROOT}${i} done -- cgit v1.2.3-65-gdbad From 482a092a86bd4889482cffc9004230a68bece1db Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 5 Jun 2014 03:29:32 +0200 Subject: Fixes a bug introduced by 8405e23 that broke none AUFS boots --- defaults/initrd.defaults | 1 + 1 file changed, 1 insertion(+) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index b08ff50c..2d79fc36 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -68,6 +68,7 @@ CDROOT_PATH='/mnt/cdrom' CDROOT_MARKER='/livecd' # AUFS variables +USE_AUFS_NORMAL=0 AUFS_MODULES=false AUFS_CHANGES=false AUFS_CHANGESFILE=livecd.aufs -- cgit v1.2.3-65-gdbad From 935febab43502bfd27a0b18d2d4e0cc99a8a4b11 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Mon, 23 Jun 2014 19:58:33 +0200 Subject: Coding style changes throughout all the AUFS related code. --- defaults/initrd.defaults | 4 +- defaults/initrd.scripts | 179 ++++++++++++++++++------------------- defaults/linuxrc | 227 +++++++++++++++++++++-------------------------- 3 files changed, 188 insertions(+), 222 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index 2d79fc36..17847fe0 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -58,7 +58,7 @@ KSUFF='.ko' REAL_ROOT='' CONSOLE='/dev/console' NEW_ROOT='/newroot' -RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/overlay|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino" +RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/rw_branch|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino" CDROOT='0' CDROOT_DEV='' CDROOT_TYPE='auto' @@ -71,7 +71,7 @@ CDROOT_MARKER='/livecd' USE_AUFS_NORMAL=0 AUFS_MODULES=false AUFS_CHANGES=false -AUFS_CHANGESFILE=livecd.aufs +AUFS_CHANGESFILE=/livecd.aufs LOOPS='/livecd.loop /zisofs /livecd.squashfs /image.squashfs /livecd.gcloop' diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 91056b1c..c258c004 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -314,8 +314,7 @@ union_insert_modules() { # This should really go into /etc/init.d/localmounts but until then we manually set this here conf_rc_no_umounts() { local conf nomount fnd - conf="${CHROOT}/etc/rc.conf" - fnd=0 + conf=$CHROOT/etc/rc.conf fnd=0 if nomount=$(grep -n '^[[:blank:]]*RC_NO_UMOUNTS=' $conf); then local i n data cmd IFS @@ -350,33 +349,28 @@ conf_rc_no_umounts() { create_changefs() { local size - while [ 1 ] - do + while :; do read -p '<< Size of file (Press Enter for default 256 Mb): ' size - if [ -z "${size}" ]; then - size=256 - fi - size="${size}" - if [ ${size} -lt 16 ] - then - bad_msg "Please give a size of at least 16 Mb" + [ -n "$size" ] || size=256 + + size=$size + + if [ 15 -ge "$size" ]; then + bad_msg "Please give a size of at least 16 Megabytes" else - dd if=/dev/zero of=${CHANGESMNT}/${AUFS_CHANGESFILE} bs=1M count=${size} &>/dev/null - if [ $? = '0' ] - then - good_msg "Creation of ${AUFS_CHANGESFILE}, ${size} Mb on ${CHANGESDEV} successful, formatting it ext2" - mke2fs -F ${CHANGESMNT}/${AUFS_CHANGESFILE} &>/dev/null + if dd if=/dev/zero "of=$CHANGESMNT$AUFS_CHANGESFILE" bs=1M count="$size" &>/dev/null; then + good_msg "Creation of $AUFS_CHANGESFILE, ${size}Mb on $CHANGESDEV successful, formatting it ext2" + mke2fs -F "$CHANGESMNT$AUFS_CHANGESFILE" >/dev/null AUFS_CHANGES=true break else - rm -f ${CHANGESMNT}/${AUFS_CHANGESFILE} - bad_msg "Unable to create ${AUFS_CHANGESFILE} on ${CHANGESDEV} of ${size} Mb" + rm -f "$CHANGESMNT$AUFS_CHANGESFILE" + bad_msg "Unable to create ${AUFS_CHANGESFILE#*/} on $CHANGESDEV of ${size}Mb" bad_msg "Ensure your disk is not full or read-only" + read -p '<< Type "a" to abort, anything else to continue : ' doabort - if [ "${doabort}" = "a" ]; then - return 1 - fi + if [ a = "$doabort" ]; then return 1; fi fi fi done @@ -386,87 +380,80 @@ create_changefs() { setup_aufs() { bootstrapCD - if [ -n "${AUFS}" ] - then - if [ "${AUFS}" = "detect" ] - then - CHANGESMNT="${NEW_ROOT}${CDROOT_PATH}" - CHANGESDEV=${REAL_ROOT} + if [ -n "$AUFS" ]; then + if [ detect = "$AUFS" ]; then + CHANGESMNT=$NEW_ROOT$CDROOT_PATH + CHANGESDEV=$REAL_ROOT else - CHANGESDEV=${AUFS} - good_msg "Mounting ${CHANGESDEV} to ${MEMORY} for aufs support" - mount -t auto ${CHANGESDEV} ${CHANGESMNT} &>/dev/null - ret=$? - if [ "${ret}" -ne 0 ] - then - bad_msg "Mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" + CHANGESDEV=$AUFS + good_msg "Mounting $CHANGESDEV to $MEMORY for aufs support" + + if ! mount -t auto "$CHANGESDEV" "$CHANGESMNT" &>/dev/null; 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}/${AUFS_CHANGESFILE} ] && [ -n "${AUFS}" ] - then + if [ ! -e $CHANGESMNT$AUFS_CHANGESFILE ] && [ -n "$AUFS" ]; then create_changefs - mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} - elif [ -n "${AUFS}" ] - then - local nbpass=0 - while [ 1 ] - do - mount -t auto ${CHANGESMNT}/${AUFS_CHANGESFILE} ${MEMORY} - ret=$? - if [ "${ret}" -ne 0 ] - then - if [ ${nbpass} -eq 0 ] - then - bad_msg "Mounting of changes file failed, Running e2fsck" - e2fsck ${CHANGESMNT}/${AUFS_CHANGESFILE} - nbpass=$((${nbpass} + 1)) - else - bad_msg "Mount of ${CHANGESDEV} failed, falling back to ramdisk based aufs" - bad_msg "your ${AUFS_CHANGESFILE} might be messed up, and I couldn't fix it" - bad_msg "moving ${AUFS_CHANGESFILE} to ${AUFS_CHANGESFILE}.bad" - mv ${CHANGESMNT}/${AUFS_CHANGESFILE} ${CHANGESMNT}/${AUFS_CHANGESFILE}.bad - bad_msg "Try to fix it yourself with e2fsck" + mount -t auto "$CHANGESMNT$AUFS_CHANGESFILE" "$MEMORY" + elif [ -n "$AUFS" ]; then + while :; do + if mount -t auto "$CHANGESMNT$AUFS_CHANGESFILE" "$MEMORY" &>/dev/null; then + break + else + bad_msg "Mounting of changes file failed, Running e2fsck" + + if ! hash e2fsck &>/dev/null; then + bad_msg "/sbin/e2fsck not found! aborting filesystem check" + bad_msg "Moving ${AUFS_CHANGESFILE#*/} to ${AUFS_CHANGESFILE#*/}.bad" + + mv "$CHANGESMNT$AUFS_CHANGESFILE" "$CHANGESMNT$AUFS_CHANGESFILE.bad" + break + + fi + + if e2fsck "$CHANGESMNT$AUFS_CHANGESFILE" &>/dev/null; then + good_msg "e2fsck ran successfully. Please verify data after bootup" + else + bad_msg "Your ${AUFS_CHANGESFILE#*/} image might be corrupted" + bad_msg "moving ${AUFS_CHANGESFILE#*/} to ${AUFS_CHANGESFILE#*/}.bad" + + mv "$CHANGESMNT$AUFS_CHANGESFILE" "$CHANGESMNT$AUFS_CHANGESFILE.bad" break fi - else - if [ ${nbpass} -eq 1 ] - then - good_msg "e2fsck ran successfully. Please check your files after bootup" - fi - break fi done 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}/${AUFS_CHANGESFILE} ] - then - XINO=${MEMORY} - umount ${MEMORY} &>/dev/null - bad_msg "Failed to find ${AUFS_CHANGESFILE} file on ${CHANGESDEV}" - bad_msg "Create an ext2 ${AUFS_CHANGESFILE} file on this device if you wish to use it for aufs" - bad_msg "Falling back to ramdisk based aufs for safety" + if [ 1 = "$CDROOT" ] && [ ! -f "$CHANGESMNT$AUFS_CHANGESFILE" ]; then + XINO=$MEMORY + umount "$MEMORY" &>/dev/null + + bad_msg "Create an extfs ${AUFS_CHANGESFILE#*/} file on this device" + bad_msg "if you wish to have aufs data persistency on reboots" + bad_msg "Falling back to ramdisk based aufs" good_msg "Mounting ramdisk to $MEMORY for aufs support" - mount -t tmpfs tmpfs ${MEMORY} + + mount -t tmpfs tmpfs "$MEMORY" else - XINO=${MEMORY}/xino - mkdir -p ${XINO} - mount -t tmpfs tmpfs ${XINO} + XINO=$MEMORY/xino + + mkdir -p "$XINO" + mount -t tmpfs aufs-xino "$XINO" fi else - good_msg "Mounting ramdisk to $MEMORY for aufs support" - mount -t tmpfs tmpfs ${MEMORY} - XINO=${MEMORY} + XINO=$MEMORY + + good_msg "Mounting ramdisk to $MEMORY for aufs support" + mount -t tmpfs tmpfs "$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!" + mkdir -p "$CHANGES" + if ! mount -t aufs -n -o "nowarn_perm,udba=none,xino=$XINO/.aufs.xino,br:$CHANGES=rw" aufs "$UNION"; then + bad_msg "Can't setup union $UNION in directory!" USE_AUFS_NORMAL=0 fi } @@ -1420,22 +1407,24 @@ getdvhoff() { setup_squashfs_aufs() { # Setup aufs directories and vars - overlay=/mnt/overlay - static=/mnt/livecd + rw_branch=/mnt/rw_branch ro_branch=/mnt/livecd - for i in "${overlay}" "${static}"; do - [ ! -d "${i}" ] && mkdir -p "${i}" + for dir in $rw_branch $ro_branch; do + [ ! -d $dir ] && mkdir -p "$dir" done - good_msg "Loading aufs" - modprobe aufs > /dev/null 2>&1 - mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${static}" - mount -t tmpfs none "${overlay}" - mount -t aufs -o br:${overlay}:${static} aufs "${NEW_ROOT}" + good_msg "Loading aufs module ..." + modprobe aufs &>/dev/null - [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}" - [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}" - for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done + mount -t squashfs -o loop,ro "$CDROOT_PATH/$LOOPEXT$LOOP" "$ro_branch" + mount -t tmpfs none "$rw_branch" + mount -t aufs -o "br:$rw_branch:$ro_branch" aufs "$NEW_ROOT" + + [ ! -d $NEW_ROOT$rw_branch ] && mkdir -p "$NEW_ROOT$rw_branch" + [ ! -d $NEW_ROOT$ro_branch ] && mkdir -p "$NEW_ROOT$ro_branch" + for mount in $rw_branch $ro_branch; do + mount --move "$mount" "$NEW_ROOT$mount" + done } setup_unionfs() { diff --git a/defaults/linuxrc b/defaults/linuxrc index 8b3ff875..5a341afd 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -255,31 +255,17 @@ do ;; aufs\=*) USE_AUFS_NORMAL=1 - echo ${x#*=} | grep , &>/dev/null - if [ "$?" -eq '0' ] - then + if echo "${x#*=}" | grep , &>/dev/null; then UID=${x#*,} AUFS=${x%,*} else AUFS=${x#*=} fi ;; - aufs.changes\=*) - USE_AUFS_NORMAL=1 - echo ${x#*=} | grep , &>/dev/null - - if [ "$?" -eq '0' ] - then - UID=${x#*,} - AUFS=${x%,*} - else - AUFS=${x#*=} - fi - ;; aufs.persistent) USE_AUFS_NORMAL=1 - AUFS="detect" + AUFS=detect ;; # Allow user to specify the modules location aufs.modules\=*) @@ -461,16 +447,14 @@ then # Setup the root filesystem bootstrapFS - if [ "${USE_AUFS_NORMAL}" -eq '1' ] - then + if [ 1 = "$USE_AUFS_NORMAL" ]; then setup_aufs - CHROOT=${UNION} + CHROOT=$UNION else CHROOT=${NEW_ROOT} fi - if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] && [ "${USE_AUFS_NORMAL}" != '1' ] - then + if [ /dev/nfs != "$REAL_ROOT" ] && [ sgimips != "$LOOPTYPE" ] && [ 1 != "$USE_AUFS_NORMAL" ]; then bootstrapCD fi @@ -502,7 +486,7 @@ then fi # Determine root device -good_msg 'Determining root device...' +good_msg 'Determining root device ...' while true do while [ "${got_good_root}" != '1' ] @@ -720,7 +704,7 @@ then FS_LOCATION='mnt/livecd' elif [ "${LOOPTYPE}" = 'squashfs' ] then - if [ "${USE_AUFS_NORMAL}" != '1' ]; then + if [ 1 != "$USE_AUFS_NORMAL" ]; then good_msg 'Mounting squashfs filesystem' _CACHED_SQUASHFS_PATH="${NEW_ROOT}/mnt/${LOOP}" _squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" # Default to uncached @@ -782,25 +766,23 @@ then fi fi # if [ -n "${CRYPT_ROOT}" ] - if [ "${USE_AUFS_NORMAL}" -eq '1' ] - then - union_insert_dir ${CHROOT} ${NEW_ROOT}/${FS_LOCATION} - - # Make sure fstab notes livecd is mounted ro. Makes system skip remount which fails on aufs dirs. - # TODO: remounting all tmpfs as RO seems weird, can we be more specific? - #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 + if [ 1 = "$USE_AUFS_NORMAL" ]; then + union_insert_dir "$CHROOT" "$NEW_ROOT/$FS_LOCATION" # Function to handle the RC_NO_UMOUNTS variable in ${CHROOT}/etc/rc.conf conf_rc_no_umounts # Fstab changes for aufs - if ! grep -q '^aufs' "${CHROOT}"/etc/fstab 2>/dev/null; then - for i in /var/tmp /tmp /usr/portage/distfiles; do - [ ! -d "${CHROOT}${i}" ] && mkdir -p "${CHROOT}${i}" + if ! grep -q '^aufs' "$CHROOT/etc/fstab" 2>/dev/null; then + for dir in /var/tmp /tmp /usr/portage/distfiles; do + [ ! -d $CHROOT$dir ] && mkdir -p "$CHROOT$dir" done - cat > "${CHROOT}"/etc/fstab << FSTAB + cat > "$CHROOT/etc/fstab" << FSTAB +#################################################### +## ATTENTION: THIS IS THE FSTAB ON THE LIVECD ## +## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ## +#################################################### aufs / aufs defaults 0 0 vartmp /var/tmp tmpfs defaults 0 0 tmp /tmp tmpfs defaults 0 0 @@ -808,30 +790,29 @@ distfiles /usr/portage/distfiles tmpfs defaults 0 0 FSTAB fi - if ${AUFS_MODULES}; then + if $AUFS_MODULES; then warn_msg "Adding all modules in $MODULESD/modules/" - if [ -z "${MODULESD}" ] - then - union_insert_modules ${CDROOT_PATH} + if [ -z "$MODULESD" ]; then + union_insert_modules "$CDROOT_PATH" else - mkdir ${NEW_ROOT}/mnt/modulesd - mount "${MODULESD}" ${NEW_ROOT}/mnt/modulesd - union_insert_modules ${NEW_ROOT}/mnt/modulesd + mkdir "$NEW_ROOT/mnt/modulesd" + mount "$MODULESD" "$NEW_ROOT/mnt/modulesd" + union_insert_modules "$NEW_ROOT/mnt/modulesd" fi fi # Copy user keymap file if [ -e /etc/sysconfig/keyboard ]; then - [ ! -d ${CHROOT}/etc/sysconfig ] && mkdir -p ${CHROOT}/etc/sysconfig - cp /etc/sysconfig/keyboard ${CHROOT}/etc/sysconfig/ + [ ! -d $CHROOT/etc/sysconfig ] && mkdir -p "$CHROOT/etc/sysconfig" + cp /etc/sysconfig/keyboard "$CHROOT/etc/sysconfig/" fi # Create the directories for our new union mounts - test ! -d "${CHROOT}${NEW_ROOT}" && mkdir -p "${CHROOT}${NEW_ROOT}" + [ ! -d $CHROOT$NEW_ROOT ] && mkdir -p "$CHROOT$NEW_ROOT" - if ${AUFS_CHANGES} && [ ! -d "${CHROOT}${NEW_ROOT}/mnt/changesdev" ]; then - mkdir -p "${CHROOT}${NEW_ROOT}/mnt/changesdev" + if $AUFS_CHANGES && [ ! -d $CHROOT$NEW_ROOT/mnt/changesdev ]; then + mkdir -p "$CHROOT$NEW_ROOT/mnt/changesdev" fi fi @@ -856,67 +837,67 @@ FSTAB then setup_unionfs ${NEW_ROOT} /${FS_LOCATION} CHROOT=/union - else - #XXX Note to potential reviewers. diff formats this section very very oddly. Be sure to review this hunk after applied, do NOT simply read the diff - if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] - then - 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}") || { - bad_msg "Copying failed, dropping into a shell." - do_rundebugshell - } - - # Now we do the links. - for x in ${ROOT_LINKS} - do - if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] - 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}/}" - - # 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 # if [ -e "/${NEW_ROOT}/${directory}" ] ... else - done # while read directory - fi # if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] ... else - done # for x in ${ROOT_LINKS} - mkdir -p initramfs proc tmp run sys 2>/dev/null - chmod 1777 tmp - - fi # if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] - #XXX: end extremely confusing hunk - - # have handy /mnt/cdrom (CDROOT_PATH) as well - _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" - mount --bind "${CDROOT_PATH}" "${_new_cdroot}" - - fi # if [ "${USE_UNIONFS_NORMAL}" = '1' ] ... else + else + #XXX Note to potential reviewers. diff formats this section very very oddly. Be sure to review this hunk after applied, do NOT simply read the diff + if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] + then + 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}") || { + bad_msg "Copying failed, dropping into a shell." + do_rundebugshell + } + + # Now we do the links. + for x in ${ROOT_LINKS} + do + if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] + 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}/}" + + # 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 # if [ -e "/${NEW_ROOT}/${directory}" ] ... else + done # while read directory + fi # if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] ... else + done # for x in ${ROOT_LINKS} + mkdir -p initramfs proc tmp run sys 2>/dev/null + chmod 1777 tmp + + fi # if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] + #XXX: end extremely confusing hunk + + # have handy /mnt/cdrom (CDROOT_PATH) as well + _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" + [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" + mount --bind "${CDROOT_PATH}" "${_new_cdroot}" + + fi # if [ "${USE_UNIONFS_NORMAL}" = '1' ] ... else #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||') #if [ "${UML}" = 'UML' ] @@ -928,18 +909,16 @@ FSTAB # Let Init scripts know that we booted from CD export CDBOOT CDBOOT=1 -else # if [ "${CDROOT}" = '1' ] +else if [ "${USE_UNIONFS_NORMAL}" = '1' ] then mkdir /union_changes mount -t tmpfs tmpfs /union_changes 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 + elif [ 1 = "$USE_AUFS_NORMAL" ]; then + union_insert_dir "$UNION" "$NEW_ROOT" + mkdir -p "$UNION/tmp/.initrd" fi fi # if [ "${CDROOT}" = '1' ] @@ -986,22 +965,20 @@ fi verbose_kmsg -if [ "${USE_AUFS_NORMAL}" -eq '1' ] -then - UNION_MEMORY=${CHROOT}/.unions/memory +if [ 1 = "$USE_AUFS_NORMAL" ]; then + UNION_MEMORY=$CHROOT/.unions/memory - mkdir -p "${UNION_MEMORY}" - mount --move "${MEMORY}" "${UNION_MEMORY}" + mkdir -p "$UNION_MEMORY" + mount --move "$MEMORY" "$UNION_MEMORY" test_success "Failed to move aufs /memory into the system root" - for i in /mnt/gentoo /mnt/livecd /mnt/overlay ${CDROOT_PATH} - do - mkdir -p "${CHROOT}${i}" - chmod 755 "${CHROOT}${i}" + for dir in /mnt/gentoo $rw_branch $ro_branch $CDROOT_PATH; do + mkdir -p "$CHROOT$dir" + chmod 755 "$CHROOT$dir" done - for i in ${CDROOT_PATH} ${overlay} ${static}; do - mount --move ${NEW_ROOT}${i} ${CHROOT}${i} + for dir in $CDROOT_PATH $rw_branch $ro_branch; do + mount --move "$NEW_ROOT$dir" "$CHROOT$dir" done fi -- cgit v1.2.3-65-gdbad From 2eae1bbb0da75bec6d38b98c97a3de3a3365f901 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Mon, 23 Jun 2014 22:03:36 +0200 Subject: Introduced a new funtion to test for numeric values that that our changes_fs doesn't fail when non-numeric values are given, also the styling of changes_fs was changed to reflect new logic. --- defaults/initrd.scripts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index c258c004..02842bff 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -345,6 +345,18 @@ conf_rc_no_umounts() { fi } +# is_int "$A" ["$B"..] +# NOTE we consider a leading 0 false as it would be interpreted as octal +is_int(){ + local i + for i; do + case $i in + ''|*[!0-9]*|0?*) return 1 ;; + *) : + esac + done +} + # Function to create an ext2 fs on $CHANGESDEV, $CHANGESMNT mountpoint create_changefs() { local size @@ -352,11 +364,12 @@ create_changefs() { while :; do read -p '<< Size of file (Press Enter for default 256 Mb): ' size - [ -n "$size" ] || size=256 - - size=$size + size=${size:-256} - if [ 15 -ge "$size" ]; then + if ! is_int $size; then + bad_msg "Non numeric value given for size, try again" + continue + elif [ 15 -ge "$size" ]; then bad_msg "Please give a size of at least 16 Megabytes" else if dd if=/dev/zero "of=$CHANGESMNT$AUFS_CHANGESFILE" bs=1M count="$size" &>/dev/null; then -- cgit v1.2.3-65-gdbad From 075da3bc84ffec2a39d70f9bb155f1ecbe03a963 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Wed, 25 Jun 2014 00:36:40 +0200 Subject: Reverting back old mknod permission settings for netboot compatibility --- defaults/initrd.scripts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 02842bff..9b88d6a8 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -205,10 +205,10 @@ bootstrapFS() { done [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" - [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 - [ ! -e "${NEW_ROOT}/dev/zero" ] && mknod -m 660 "${NEW_ROOT}"/dev/zero c 1 5 - [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1 - [ ! -e "${NEW_ROOT}/dev/ttyS0" ] && mknod -m 600 "${NEW_ROOT}"/dev/ttyS0 c 4 64 + [ ! -e "${NEW_ROOT}/dev/null" ] && mknod -m 666 "${NEW_ROOT}"/dev/null c 1 3 + [ ! -e "${NEW_ROOT}/dev/zero" ] && mknod -m 666 "${NEW_ROOT}"/dev/zero c 1 5 + [ ! -e "${NEW_ROOT}/dev/console" ] && mknod -m 600 "${NEW_ROOT}"/dev/console c 5 1 + [ ! -e "${NEW_ROOT}/dev/ttyS0" ] && mknod -m 660 "${NEW_ROOT}"/dev/ttyS0 c 4 64 # For SGI LiveCDs if [ "${LOOPTYPE}" = "sgimips" ]; then -- cgit v1.2.3-65-gdbad From b4d40c20a5cb327540ea2f7d84f818b39b8657dc Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Wed, 25 Jun 2014 18:12:11 +0200 Subject: This is commit contains several changes summarized below. 1. Changed renaming of RC_NO_UMOUNTS directories 2. Upper to lowercase variables because this is the year 2014 3. Renamed aufs related variables for better readability 4. Fixed a typo in mke2fs command which was missing an "&" 5. Cleaned up setup_squashfs_aufs() function 6. Fixed an issue with legacy squashfs implementation which caused /mnt/cdrom to be shown twice in 'mount' and removed the --bind and replaced this with --move 7. Restructured the union_* functions so that we don't parse 'ls' and enabled globbing 8. Coding style changes - rid of the unnecessary braces - fix a missing & for mke2fs on livecd.aufs - renamed variables for more readabilit 9. Better error handling for changesfs() 10. Removed aufs.persistent since 'aufs' already mounts a tmpfs which uses half the available ram, and since this feature is not true persistent we remove it in favor of aufs= --- defaults/initrd.defaults | 10 +-- defaults/initrd.scripts | 208 ++++++++++++++++++++++++----------------------- defaults/linuxrc | 151 +++++++++++++++++----------------- 3 files changed, 185 insertions(+), 184 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index 17847fe0..782fd14f 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -12,6 +12,8 @@ BAD="\033[31;1m" BOLD="\033[1m" GOOD="\033[32;1m" +# Sets the default collation order +LC_COLLATE=C # From KNOPPIX LINUXRC # Reset fb color mode RESET="]R" @@ -58,7 +60,7 @@ KSUFF='.ko' REAL_ROOT='' CONSOLE='/dev/console' NEW_ROOT='/newroot' -RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/rw_branch|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino" +RC_NO_UMOUNTS='/newroot|/mnt/aufs-dev|/mnt/aufs-rw-branch|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino' CDROOT='0' CDROOT_DEV='' CDROOT_TYPE='auto' @@ -68,10 +70,8 @@ CDROOT_PATH='/mnt/cdrom' CDROOT_MARKER='/livecd' # AUFS variables -USE_AUFS_NORMAL=0 -AUFS_MODULES=false -AUFS_CHANGES=false -AUFS_CHANGESFILE=/livecd.aufs +aufs=0 +aufs_union_file=/livecd.aufs LOOPS='/livecd.loop /zisofs /livecd.squashfs /image.squashfs /livecd.gcloop' diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 9b88d6a8..2e485049 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -178,20 +178,20 @@ devicelist(){ } bootstrapFS() { - if [ "${USE_AUFS_NORMAL}" -eq '1' ]; then - # Directories used for rw changes in union mount filesystem - UNION=/union MEMORY=/memory + if [ 1 = "$aufs" ]; then + # Directories used for rw aufs mount filesystem + aufs_union=/union aufs_memory=/memory - # Mountpoint for the changesdev - CHANGESMNT=${NEW_ROOT}/mnt/changesdev + # Mountpoint for the aufs dev + aufs_dev_mnt=/mnt/aufs-dev - if [ -z "$UID" ]; then - CHANGES=${MEMORY}/aufs_changes/default + if [ -z "$aufs_dev_uid" ]; then + aufs_branch=$aufs_memory/aufs-branch/default else - CHANGES=${MEMORY}/aufs_changes/${UID} + aufs_branch=$aufs_memory/aufs-branch/$aufs_dev_uid fi - mkdir -p ${MEMORY} ${UNION} ${CHANGESMNT} + mkdir -p $aufs_memory $aufs_union $aufs_dev_mnt else # Legacy SquashFS implementation good_msg "Making tmpfs for ${NEW_ROOT}" @@ -280,37 +280,51 @@ mount_sysfs() { [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!" } -# Insert a directory tree ${2} to an union specified by ${1} +# 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 +# $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" + if mount -n -o "remount,add:1:$2=rr" aufs "$1"; then + good_msg "Addition of $2 to $1 successful" fi } -# Insert all modules found in $1, usually ${CDROOT_PATH} +# Insert all modules found in $1, usually $CDROOT_PATH # 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) - 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 + local module + + for module in "$NEW_ROOT/$1/modules/"*.mo; do + union_mod "$module" || bad_msg "Unable to load module: '$module'" + done + + for module in "$NEW_ROOT/$1/modules/"*.lzm; do + union_mod "$module" lzm || bad_msg "Unable to load module: '$module'" + done } -# Implements RC_NO_UMOUNTS variable into ${CHROOT}/etc/rc.conf for a cleaner shutdown process +# Helper function for union_insert_modules() +union_mod() { + [ -e "$1" ] || return 0 + + local mod + + mod=${1##*/} + mod=${mod%.*} + + mkdir -p "$aufs_memory/modules/$mod" || return + + if [ lzm = "$2" ]; then + mount -o loop,ro "$1" "$aufs_memory/modules/$mod" + fi + + union_insert_dir "$aufs_union" "$aufs_memory/modules/$mod" +} + +# Implements RC_NO_UMOUNTS variable into $CHROOT/etc/rc.conf for a cleaner shutdown process # This should really go into /etc/init.d/localmounts but until then we manually set this here conf_rc_no_umounts() { local conf nomount fnd @@ -357,7 +371,7 @@ is_int(){ done } -# Function to create an ext2 fs on $CHANGESDEV, $CHANGESMNT mountpoint +# Function to create an ext2 fs on $aufs_dev, $aufs_dev_mnt mountpoint create_changefs() { local size @@ -372,102 +386,98 @@ create_changefs() { elif [ 15 -ge "$size" ]; then bad_msg "Please give a size of at least 16 Megabytes" else - if dd if=/dev/zero "of=$CHANGESMNT$AUFS_CHANGESFILE" bs=1M count="$size" &>/dev/null; then - good_msg "Creation of $AUFS_CHANGESFILE, ${size}Mb on $CHANGESDEV successful, formatting it ext2" - mke2fs -F "$CHANGESMNT$AUFS_CHANGESFILE" >/dev/null - AUFS_CHANGES=true + if dd if=/dev/zero "of=$aufs_dev_mnt$aufs_union_file" bs=1M count="$size" &>/dev/null; then + good_msg "Creation of $aufs_union_file, ${size}Mb on $aufs_dev successful, formatting it ext2" + mke2fs -F "$aufs_dev_mnt$aufs_union_file" &>/dev/null break else - rm -f "$CHANGESMNT$AUFS_CHANGESFILE" - bad_msg "Unable to create ${AUFS_CHANGESFILE#*/} on $CHANGESDEV of ${size}Mb" + rm "$aufs_dev_mnt$aufs_union_file" + bad_msg "Unable to create ${aufs_union_file#*/} on $aufs_dev of ${size}Mb" bad_msg "Ensure your disk is not full or read-only" read -p '<< Type "a" to abort, anything else to continue : ' doabort - if [ a = "$doabort" ]; then return 1; fi + if [ a = "$doabort" ]; then + bad_msg "Aborting creation of $aufs_union_file!" + umount "$aufs_dev" && rmdir "$aufs_dev_mnt" + return 1 + fi fi fi done - return 0 + return $? } setup_aufs() { bootstrapCD - if [ -n "$AUFS" ]; then - if [ detect = "$AUFS" ]; then - CHANGESMNT=$NEW_ROOT$CDROOT_PATH - CHANGESDEV=$REAL_ROOT - else - CHANGESDEV=$AUFS - good_msg "Mounting $CHANGESDEV to $MEMORY for aufs support" + if [ -n "$aufs_dev" ]; then + good_msg "Mounting $aufs_dev to $aufs_memory for aufs support" - if ! mount -t auto "$CHANGESDEV" "$CHANGESMNT" &>/dev/null; then - bad_msg "Mount of $CHANGESDEV failed, falling back to ramdisk based aufs" - unset AUFS - fi + if ! mount -t auto "$aufs_dev" "$aufs_dev_mnt" &>/dev/null; then + bad_msg "Mount of $aufs_dev failed, falling back to ramdisk based aufs" + unset aufs_dev fi - # Check and attempt to create the changesfile - if [ ! -e $CHANGESMNT$AUFS_CHANGESFILE ] && [ -n "$AUFS" ]; then - create_changefs - mount -t auto "$CHANGESMNT$AUFS_CHANGESFILE" "$MEMORY" - elif [ -n "$AUFS" ]; then - while :; do - if mount -t auto "$CHANGESMNT$AUFS_CHANGESFILE" "$MEMORY" &>/dev/null; then + # Check and attempt to create the AUFS union file + if [ ! -e $aufs_dev_mnt$aufs_union_file ] && [ -n "$aufs_dev" ]; then + create_changefs && mount -t auto "$aufs_dev_mnt$aufs_union_file" "$aufs_memory" + elif [ -n "$aufs_dev" ]; then + while :; do + if mount -t auto "$aufs_dev_mnt$aufs_union_file" "$aufs_memory" &>/dev/null; then break else bad_msg "Mounting of changes file failed, Running e2fsck" if ! hash e2fsck &>/dev/null; then bad_msg "/sbin/e2fsck not found! aborting filesystem check" - bad_msg "Moving ${AUFS_CHANGESFILE#*/} to ${AUFS_CHANGESFILE#*/}.bad" + bad_msg "Moving ${aufs_union_file#*/} to ${aufs_union_file#*/}.bad" - mv "$CHANGESMNT$AUFS_CHANGESFILE" "$CHANGESMNT$AUFS_CHANGESFILE.bad" + mv "$aufs_dev_mnt$aufs_union_file" "$aufs_dev_mnt$aufs_union_file.bad" break - fi - if e2fsck "$CHANGESMNT$AUFS_CHANGESFILE" &>/dev/null; then + if e2fsck "$aufs_dev_mnt$aufs_union_file" &>/dev/null; then good_msg "e2fsck ran successfully. Please verify data after bootup" else - bad_msg "Your ${AUFS_CHANGESFILE#*/} image might be corrupted" - bad_msg "moving ${AUFS_CHANGESFILE#*/} to ${AUFS_CHANGESFILE#*/}.bad" + bad_msg "Your ${aufs_union_file#*/} image might be corrupted" + bad_msg "moving ${aufs_union_file#*/} to ${aufs_union_file#*/}.bad" - mv "$CHANGESMNT$AUFS_CHANGESFILE" "$CHANGESMNT$AUFS_CHANGESFILE.bad" - break - fi - fi - done - fi - # mount tmpfs only in the case when changes= boot parameter was - # empty or we were not able to mount the storage device - if [ 1 = "$CDROOT" ] && [ ! -f "$CHANGESMNT$AUFS_CHANGESFILE" ]; then - XINO=$MEMORY - umount "$MEMORY" &>/dev/null + mv "$aufs_dev_mnt$aufs_union_file" "$aufs_dev_mnt$aufs_union_file.bad" + break + fi + fi + done + fi + + # Mount tmpfs only in the case when aufs= boot parameter was + # empty or we were not able to mount the storage device + if [ 1 = "$CDROOT" ] && [ ! -f "$aufs_dev_mnt$aufs_union_file" ]; then + aufs_xino=$aufs_memory + umount "$aufs_memory" &>/dev/null - bad_msg "Create an extfs ${AUFS_CHANGESFILE#*/} file on this device" + bad_msg "Create an extfs ${aufs_union_file#*/} file on this device" bad_msg "if you wish to have aufs data persistency on reboots" - bad_msg "Falling back to ramdisk based aufs" - good_msg "Mounting ramdisk to $MEMORY for aufs support" + bad_msg "Falling back to ramdisk based aufs" + good_msg "Mounting ramdisk to $aufs_memory for aufs support" - mount -t tmpfs tmpfs "$MEMORY" - else - XINO=$MEMORY/xino + mount -t tmpfs tmpfs "$aufs_memory" + else + aufs_xino=$aufs_memory/xino - mkdir -p "$XINO" - mount -t tmpfs aufs-xino "$XINO" - fi - else - XINO=$MEMORY + mkdir -p "$aufs_xino" + mount -t tmpfs aufs-xino "$aufs_xino" + fi + else + aufs_xino=$aufs_memory - good_msg "Mounting ramdisk to $MEMORY for aufs support" - mount -t tmpfs tmpfs "$MEMORY" - fi + good_msg "Mounting ramdisk to $aufs_memory for aufs support" + mount -t tmpfs tmpfs "$aufs_memory" + fi - mkdir -p "$CHANGES" - if ! mount -t aufs -n -o "nowarn_perm,udba=none,xino=$XINO/.aufs.xino,br:$CHANGES=rw" aufs "$UNION"; then - bad_msg "Can't setup union $UNION in directory!" - USE_AUFS_NORMAL=0 + mkdir -p "$aufs_branch" + if ! mount -t aufs -n -o "nowarn_perm,udba=none,xino=$aufs_xino/.aufs.xino,br:$aufs_branch=rw" aufs "$aufs_union"; then + bad_msg "Can't setup union $aufs_union in directory!" + aufs=0 fi } @@ -1420,24 +1430,18 @@ getdvhoff() { setup_squashfs_aufs() { # Setup aufs directories and vars - rw_branch=/mnt/rw_branch ro_branch=/mnt/livecd + aufs_rw_branch=/mnt/aufs-rw-branch aufs_ro_branch=/mnt/livecd - for dir in $rw_branch $ro_branch; do + for dir in $aufs_rw_branch $aufs_ro_branch; do [ ! -d $dir ] && mkdir -p "$dir" done good_msg "Loading aufs module ..." modprobe aufs &>/dev/null - mount -t squashfs -o loop,ro "$CDROOT_PATH/$LOOPEXT$LOOP" "$ro_branch" - mount -t tmpfs none "$rw_branch" - mount -t aufs -o "br:$rw_branch:$ro_branch" aufs "$NEW_ROOT" - - [ ! -d $NEW_ROOT$rw_branch ] && mkdir -p "$NEW_ROOT$rw_branch" - [ ! -d $NEW_ROOT$ro_branch ] && mkdir -p "$NEW_ROOT$ro_branch" - for mount in $rw_branch $ro_branch; do - mount --move "$mount" "$NEW_ROOT$mount" - done + mount -t squashfs -o loop,ro "$CDROOT_PATH/$LOOPEXT$LOOP" "$aufs_ro_branch" + mount -t tmpfs none "$aufs_rw_branch" + mount -t aufs -o "br:$aufs_rw_branch:$aufs_ro_branch" aufs "$NEW_ROOT" } setup_unionfs() { diff --git a/defaults/linuxrc b/defaults/linuxrc index 5a341afd..276f1501 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -251,26 +251,22 @@ do keymap=${x#*=} ;; aufs) - USE_AUFS_NORMAL=1 + aufs=1 ;; aufs\=*) - USE_AUFS_NORMAL=1 + aufs=1 if echo "${x#*=}" | grep , &>/dev/null; then - UID=${x#*,} - AUFS=${x%,*} + aufs_dev_uid=${x#*,} + aufs_dev=${x%,*} else - AUFS=${x#*=} + aufs_dev=${x#*=} fi ;; - aufs.persistent) - USE_AUFS_NORMAL=1 - AUFS=detect - ;; # Allow user to specify the modules location aufs.modules\=*) - MODULESD=${x#*=} - AUFS_MODULES=true + aufs_modules_dev=${x#*=} + aufs_modules=1 ;; unionfs) if [ ! -x /sbin/unionfs ] @@ -447,14 +443,14 @@ then # Setup the root filesystem bootstrapFS - if [ 1 = "$USE_AUFS_NORMAL" ]; then + if [ 1 = "$aufs" ]; then setup_aufs - CHROOT=$UNION + CHROOT=$aufs_union else CHROOT=${NEW_ROOT} fi - if [ /dev/nfs != "$REAL_ROOT" ] && [ sgimips != "$LOOPTYPE" ] && [ 1 != "$USE_AUFS_NORMAL" ]; then + if [ /dev/nfs != "$REAL_ROOT" ] && [ sgimips != "$LOOPTYPE" ] && [ 1 != "$aufs" ]; then bootstrapCD fi @@ -704,7 +700,7 @@ then FS_LOCATION='mnt/livecd' elif [ "${LOOPTYPE}" = 'squashfs' ] then - if [ 1 != "$USE_AUFS_NORMAL" ]; then + if [ 1 != "$aufs" ]; then good_msg 'Mounting squashfs filesystem' _CACHED_SQUASHFS_PATH="${NEW_ROOT}/mnt/${LOOP}" _squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" # Default to uncached @@ -766,10 +762,10 @@ then fi fi # if [ -n "${CRYPT_ROOT}" ] - if [ 1 = "$USE_AUFS_NORMAL" ]; then - union_insert_dir "$CHROOT" "$NEW_ROOT/$FS_LOCATION" + if [ 1 = "$aufs" ]; then + union_insert_dir "$CHROOT" "$aufs_ro_branch" - # Function to handle the RC_NO_UMOUNTS variable in ${CHROOT}/etc/rc.conf + # Function to handle the RC_NO_UMOUNTS variable in $CHROOT/etc/rc.conf conf_rc_no_umounts # Fstab changes for aufs @@ -780,7 +776,7 @@ then cat > "$CHROOT/etc/fstab" << FSTAB #################################################### -## ATTENTION: THIS IS THE FSTAB ON THE LIVECD ## +## ATTENTION: THIS IS THE FSTAB ON THE LIVECD ## ## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ## #################################################### aufs / aufs defaults 0 0 @@ -790,14 +786,14 @@ distfiles /usr/portage/distfiles tmpfs defaults 0 0 FSTAB fi - if $AUFS_MODULES; then - warn_msg "Adding all modules in $MODULESD/modules/" + if [ 1 = "$aufs_modules" ]; then + warn_msg "Adding all modules in $aufs_modules_dev/modules/" - if [ -z "$MODULESD" ]; then + if [ -z "$aufs_modules_dev" ]; then union_insert_modules "$CDROOT_PATH" else mkdir "$NEW_ROOT/mnt/modulesd" - mount "$MODULESD" "$NEW_ROOT/mnt/modulesd" + mount "$aufs_modules_dev" "$NEW_ROOT/mnt/modulesd" union_insert_modules "$NEW_ROOT/mnt/modulesd" fi fi @@ -808,11 +804,13 @@ FSTAB cp /etc/sysconfig/keyboard "$CHROOT/etc/sysconfig/" fi - # Create the directories for our new union mounts + # Create the diuectories for our new union mounts [ ! -d $CHROOT$NEW_ROOT ] && mkdir -p "$CHROOT$NEW_ROOT" - if $AUFS_CHANGES && [ ! -d $CHROOT$NEW_ROOT/mnt/changesdev ]; then - mkdir -p "$CHROOT$NEW_ROOT/mnt/changesdev" + # Check to see if we successfully mounted $aufs_dev + if [ -n "$aufs_dev" ] && grep $aufs_dev /etc/mtab 1>/dev/null; then + [ ! -d $CHROOT$aufs_dev_mnt ] && mkdir -p "$CHROOT$aufs_dev_mnt" + mount --move "$aufs_dev_mnt" "$CHROOT$aufs_dev_mnt" fi fi @@ -833,31 +831,30 @@ FSTAB fi - if [ "${USE_UNIONFS_NORMAL}" = '1' ] - then + if [ "${USE_UNIONFS_NORMAL}" = '1' ]; then setup_unionfs ${NEW_ROOT} /${FS_LOCATION} CHROOT=/union - else - #XXX Note to potential reviewers. diff formats this section very very oddly. Be sure to review this hunk after applied, do NOT simply read the diff - if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] - then - 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}") || { - bad_msg "Copying failed, dropping into a shell." - do_rundebugshell - } - - # Now we do the links. - for x in ${ROOT_LINKS} - do - if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] - 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 + elif [ 1 != "$aufs" ]; then + 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}" + ) || + { + bad_msg "Copying failed, dropping into a shell." + do_rundebugshell + } + + # Now we do the links. + for x in ${ROOT_LINKS}; do + if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]; 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}/}" @@ -869,11 +866,9 @@ FSTAB fi fi # Test if the directory exists already - if [ -e "/${NEW_ROOT}/${directory}" ] - then + if [ -e "/${NEW_ROOT}/${directory}" ]; then # It does exist, link all the individual files - for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory}) - do + 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 @@ -882,22 +877,24 @@ FSTAB # It does not exist, make a link to the livecd ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null current_parent="${directory}" - fi # if [ -e "/${NEW_ROOT}/${directory}" ] ... else - done # while read directory - fi # if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ] ... else - done # for x in ${ROOT_LINKS} - mkdir -p initramfs proc tmp run sys 2>/dev/null - chmod 1777 tmp + fi + done + fi + done - fi # if [ ! "${USE_AUFS_NORMAL}" -eq '1' ] - #XXX: end extremely confusing hunk + mkdir -p initramfs proc tmp run sys 2>/dev/null + chmod 1777 tmp - # have handy /mnt/cdrom (CDROOT_PATH) as well - _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" - mount --bind "${CDROOT_PATH}" "${_new_cdroot}" + fi - fi # if [ "${USE_UNIONFS_NORMAL}" = '1' ] ... else + # Have handy /mnt/cdrom (CDROOT_PATH) as well + if [ 1 = "$aufs" ]; then + [ ! -d "$CHROOT$CDROOT_PATH" ] && mkdir "$CHROOT$CDROOT_PATH" + mount --move "$CDROOT_PATH" "$CHROOT$CDROOT_PATH" + else + [ ! -d "$NEW_ROOT$CDROOT_PATH" ] && mkdir -p "$NEW_ROOT$CDROOT_PATH" + mount --move "$CDROOT_PATH" "$NEW_ROOT$CDROOT_PATH" + fi #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||') #if [ "${UML}" = 'UML' ] @@ -916,9 +913,9 @@ else mount -t tmpfs tmpfs /union_changes setup_unionfs /union_changes ${NEW_ROOT} mkdir -p ${UNION}/tmp/.initrd - elif [ 1 = "$USE_AUFS_NORMAL" ]; then - union_insert_dir "$UNION" "$NEW_ROOT" - mkdir -p "$UNION/tmp/.initrd" + elif [ 1 = "$aufs" ]; then + union_insert_dir "$aufs_union" "$NEW_ROOT" + mkdir -p "$aufs_union/tmp/.initrd" fi fi # if [ "${CDROOT}" = '1' ] @@ -965,20 +962,20 @@ fi verbose_kmsg -if [ 1 = "$USE_AUFS_NORMAL" ]; then - UNION_MEMORY=$CHROOT/.unions/memory +if [ 1 = "$aufs" ]; then + aufs_union_memory=$CHROOT/.unions/memory - mkdir -p "$UNION_MEMORY" - mount --move "$MEMORY" "$UNION_MEMORY" - test_success "Failed to move aufs /memory into the system root" + mkdir -p "$aufs_union_memory" + mount --move "$aufs_memory" "$aufs_union_memory" + test_success "Failed to move aufs $aufs_memory into the system root" - for dir in /mnt/gentoo $rw_branch $ro_branch $CDROOT_PATH; do + for dir in /mnt/gentoo $aufs_rw_branch $aufs_ro_branch; do mkdir -p "$CHROOT$dir" chmod 755 "$CHROOT$dir" done - for dir in $CDROOT_PATH $rw_branch $ro_branch; do - mount --move "$NEW_ROOT$dir" "$CHROOT$dir" + for mount in $aufs_rw_branch $aufs_ro_branch; do + mount --move "$mount" "$CHROOT$mount" done fi -- cgit v1.2.3-65-gdbad From 2222b9de2417a6587f2d206841e15ad53c8a4672 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Thu, 10 Jul 2014 03:53:07 +0200 Subject: Changed to the dd command which creates the livecd.aufs image for the aufs writable branch to make the process faster we create a sparse file. Added a check for a block device so that we don't try mounting the aufs device & some small comestic changes. --- defaults/initrd.scripts | 33 ++++++++++++++++++++++----------- defaults/linuxrc | 3 ++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 2e485049..5c7703ba 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -376,7 +376,7 @@ create_changefs() { local size while :; do - read -p '<< Size of file (Press Enter for default 256 Mb): ' size + read -p '<< Size of file (Press Enter for default 256 MB): ' size size=${size:-256} @@ -386,13 +386,13 @@ create_changefs() { elif [ 15 -ge "$size" ]; then bad_msg "Please give a size of at least 16 Megabytes" else - if dd if=/dev/zero "of=$aufs_dev_mnt$aufs_union_file" bs=1M count="$size" &>/dev/null; then - good_msg "Creation of $aufs_union_file, ${size}Mb on $aufs_dev successful, formatting it ext2" + if dd if=/dev/zero "of=$aufs_dev_mnt$aufs_union_file" bs=1 seek="$size"M count=0 &>/dev/null; then + good_msg "Creation of $aufs_union_file, ${size}MB on $aufs_dev successful, formatting it ext2" mke2fs -F "$aufs_dev_mnt$aufs_union_file" &>/dev/null break else rm "$aufs_dev_mnt$aufs_union_file" - bad_msg "Unable to create ${aufs_union_file#*/} on $aufs_dev of ${size}Mb" + bad_msg "Unable to create ${aufs_union_file#*/} on $aufs_dev of ${size}MB" bad_msg "Ensure your disk is not full or read-only" read -p '<< Type "a" to abort, anything else to continue : ' doabort @@ -410,13 +410,19 @@ create_changefs() { setup_aufs() { bootstrapCD - if [ -n "$aufs_dev" ]; then - good_msg "Mounting $aufs_dev to $aufs_memory for aufs support" + if [ -n "$aufs_dev" ]; then + if [ ! -b $aufs_dev ]; then + bad_msg "$aufs_dev is not a valid block device" + local invalidblk=1 + unset aufs_dev + else + good_msg "Mounting $aufs_dev to $aufs_memory for aufs support" - if ! mount -t auto "$aufs_dev" "$aufs_dev_mnt" &>/dev/null; then - bad_msg "Mount of $aufs_dev failed, falling back to ramdisk based aufs" - unset aufs_dev - fi + if ! mount -t auto "$aufs_dev" "$aufs_dev_mnt" &>/dev/null; then + bad_msg "Mount of $aufs_dev failed, falling back to ramdisk based aufs" + unset aufs_dev + fi + fi # Check and attempt to create the AUFS union file if [ ! -e $aufs_dev_mnt$aufs_union_file ] && [ -n "$aufs_dev" ]; then @@ -455,7 +461,12 @@ setup_aufs() { aufs_xino=$aufs_memory umount "$aufs_memory" &>/dev/null - bad_msg "Create an extfs ${aufs_union_file#*/} file on this device" + if [ 1 = "$invalidblk" ]; then + bad_msg "Verify that you've entered a valid device path" + else + bad_msg "Create an extfs ${aufs_union_file#*/} file on this device" + fi + bad_msg "if you wish to have aufs data persistency on reboots" bad_msg "Falling back to ramdisk based aufs" good_msg "Mounting ramdisk to $aufs_memory for aufs support" diff --git a/defaults/linuxrc b/defaults/linuxrc index 276f1501..3098866b 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -786,6 +786,7 @@ distfiles /usr/portage/distfiles tmpfs defaults 0 0 FSTAB fi + # When aufs.modules= is used if [ 1 = "$aufs_modules" ]; then warn_msg "Adding all modules in $aufs_modules_dev/modules/" @@ -804,7 +805,7 @@ FSTAB cp /etc/sysconfig/keyboard "$CHROOT/etc/sysconfig/" fi - # Create the diuectories for our new union mounts + # Create the directories for our new union mounts [ ! -d $CHROOT$NEW_ROOT ] && mkdir -p "$CHROOT$NEW_ROOT" # Check to see if we successfully mounted $aufs_dev -- cgit v1.2.3-65-gdbad From a5f4045080278ac43d13ff79bfbad388055867c5 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Mon, 4 Aug 2014 03:23:02 +0200 Subject: Fixed a bug which prevented aufs.modules from functioning properly and changed the variables names to reflect the actual logic. --- defaults/initrd.defaults | 1 + defaults/initrd.scripts | 17 ++++++++--------- defaults/linuxrc | 22 +++++++++++++--------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index 782fd14f..f2cb42ab 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -72,6 +72,7 @@ CDROOT_MARKER='/livecd' # AUFS variables aufs=0 aufs_union_file=/livecd.aufs +aufs_modules_dir=mnt/cdrom LOOPS='/livecd.loop /zisofs /livecd.squashfs /image.squashfs /livecd.gcloop' diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 5c7703ba..d168b94f 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -297,12 +297,12 @@ union_insert_dir() { union_insert_modules() { local module - for module in "$NEW_ROOT/$1/modules/"*.mo; do - union_mod "$module" || bad_msg "Unable to load module: '$module'" + for module in "$1/modules/"*.mo; do + union_mod "$module" || bad_msg "Unable to insert module: '$module'" done - for module in "$NEW_ROOT/$1/modules/"*.lzm; do - union_mod "$module" lzm || bad_msg "Unable to load module: '$module'" + for module in "$1/modules/"*.lzm; do + union_mod "$module" || bad_msg "Unable to insert module: '$module'" done } @@ -315,13 +315,12 @@ union_mod() { mod=${1##*/} mod=${mod%.*} - mkdir -p "$aufs_memory/modules/$mod" || return - - if [ lzm = "$2" ]; then - mount -o loop,ro "$1" "$aufs_memory/modules/$mod" + if [ ! -d "$aufs_union"/mnt/"$mod" ]; then + mkdir -p "$aufs_union"/mnt/modules/"$mod" || return fi - union_insert_dir "$aufs_union" "$aufs_memory/modules/$mod" + mount -o loop,ro "$1" "$aufs_union"/mnt/modules/"$mod" + union_insert_dir "$aufs_union" "$aufs_union"/mnt/modules/"$mod" } # Implements RC_NO_UMOUNTS variable into $CHROOT/etc/rc.conf for a cleaner shutdown process diff --git a/defaults/linuxrc b/defaults/linuxrc index 3098866b..951f5e12 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -265,7 +265,7 @@ do ;; # Allow user to specify the modules location aufs.modules\=*) - aufs_modules_dev=${x#*=} + aufs_modules_dir=${x#*=} aufs_modules=1 ;; unionfs) @@ -786,16 +786,20 @@ distfiles /usr/portage/distfiles tmpfs defaults 0 0 FSTAB fi - # When aufs.modules= is used - if [ 1 = "$aufs_modules" ]; then - warn_msg "Adding all modules in $aufs_modules_dev/modules/" + # When aufs.modules= is used or $CDROOT_PATH/modules + # directory is available + if [[ 1 = "$aufs_modules" || -d $CDROOT_PATH/modules ]]; then + warn_msg "Adding all modules in $aufs_modules_dir/modules/" - if [ -z "$aufs_modules_dev" ]; then + if [ mnt/cdrom = "$aufs_modules_dir" ]; then union_insert_modules "$CDROOT_PATH" - else - mkdir "$NEW_ROOT/mnt/modulesd" - mount "$aufs_modules_dev" "$NEW_ROOT/mnt/modulesd" - union_insert_modules "$NEW_ROOT/mnt/modulesd" + elif [ ! -b "$aufs_modules_dir" ]; then + bad_msg "$aufs_modules_dir is not a valid block device" + bad_msg "aborting modules insert into $aufs_union" + else + mkdir /mnt/modules + mount "$aufs_modules_dir" /mnt/modules + union_insert_modules /mnt/modules fi fi -- cgit v1.2.3-65-gdbad From 3ad1b69ab16292a28f03ed457e95ba221db7d654 Mon Sep 17 00:00:00 2001 From: "Fernando Reyes (likewhoa)" Date: Sun, 17 Aug 2014 02:18:36 +0200 Subject: restructure no_umounts from being set in /etc/rc.conf to /etc/conf.d/localmount --- defaults/initrd.defaults | 2 +- defaults/initrd.scripts | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index f2cb42ab..f6fd5648 100755 --- a/defaults/initrd.defaults +++ b/defaults/initrd.defaults @@ -60,7 +60,7 @@ KSUFF='.ko' REAL_ROOT='' CONSOLE='/dev/console' NEW_ROOT='/newroot' -RC_NO_UMOUNTS='/newroot|/mnt/aufs-dev|/mnt/aufs-rw-branch|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino' +no_umounts='/newroot|/mnt/aufs-dev|/mnt/aufs-rw-branch|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino' CDROOT='0' CDROOT_DEV='' CDROOT_TYPE='auto' diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index d168b94f..8edaea47 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -323,13 +323,12 @@ union_mod() { union_insert_dir "$aufs_union" "$aufs_union"/mnt/modules/"$mod" } -# Implements RC_NO_UMOUNTS variable into $CHROOT/etc/rc.conf for a cleaner shutdown process -# This should really go into /etc/init.d/localmounts but until then we manually set this here +# Implements no_umounts variable into $CHROOT/etc/conf.d/localmount for a cleaner shutdown process conf_rc_no_umounts() { local conf nomount fnd - conf=$CHROOT/etc/rc.conf fnd=0 + conf=$CHROOT/etc/conf.d/localmount fnd=0 - if nomount=$(grep -n '^[[:blank:]]*RC_NO_UMOUNTS=' $conf); then + if nomount=$(grep -n '^[[:blank:]]*no_umounts=' $conf); then local i n data cmd IFS IFS=' ' @@ -341,20 +340,20 @@ conf_rc_no_umounts() { data=${i#*=} case $data in - "\"$RC_NO_UMOUNTS\""|"'$RC_NO_UMOUNTS'") fnd=1;; + "\"$no_umounts\""|"'$no_umounts'") fnd=1;; *) cmd="$cmd$n d;" esac done if [ -n "$cmd" ]; then sed -i "${cmd%;}" $conf - test_success "Unable to edit rc.conf" + test_success "Unable to edit /etc/conf.d/localmount" fi fi if [ 0 -eq "$fnd" ]; then - printf 'RC_NO_UMOUNTS="%s"\n' "$RC_NO_UMOUNTS" >> $conf - test_success "Unable to write to rc.conf" + printf 'no_umounts="%s"\n' "$no_umounts" >> $conf + test_success "Unable to write to /etc/conf.d/localmount" fi } -- cgit v1.2.3-65-gdbad From 3d379af92b227994d2e82b4b068a5d706c201514 Mon Sep 17 00:00:00 2001 From: "Rick Farina (Zero_Chaos)" Date: Fri, 5 Sep 2014 12:11:48 -0400 Subject: change default aufs branch naming likewhoa didn't like my default naming, and I don't like his, so we compromised on aufs-rw-branch so no one is happy :-) --- defaults/initrd.scripts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 8edaea47..d8142a29 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -186,9 +186,9 @@ bootstrapFS() { aufs_dev_mnt=/mnt/aufs-dev if [ -z "$aufs_dev_uid" ]; then - aufs_branch=$aufs_memory/aufs-branch/default + aufs_branch=$aufs_memory/aufs-rw-branch/default else - aufs_branch=$aufs_memory/aufs-branch/$aufs_dev_uid + aufs_branch=$aufs_memory/aufs-rw-branch/$aufs_dev_uid fi mkdir -p $aufs_memory $aufs_union $aufs_dev_mnt -- cgit v1.2.3-65-gdbad From 4e55218f080fab85514112a38e6fe6aee6a922ba Mon Sep 17 00:00:00 2001 From: "Rick Farina (Zero_Chaos)" Date: Mon, 22 Sep 2014 20:07:28 -0400 Subject: aufs changes saving automation The aufs code has the ability to save changes in a file, however, it requires the user to manually tell us where the file is. This code will automatically check for the file on $CDROOT, as well as automatically pick up the casper-rw file created by unetbooting for persistence. Additionally we add the option for aufs=search which will search all drives for livecd.aufs. Possible later enhancements include searching other partitions on the CDROOT_DEV for livecd.aufs automatically instead of needing aufs=search. Then again, possible later enhancements also include just always searching, it's shockingly fast to do the search... --- defaults/initrd.scripts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index d8142a29..e05809c9 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -123,7 +123,7 @@ findmediamount() { fi good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT} - mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1 + mount -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1 if [ "$?" = '0' ] then if [ -n "${ISOBOOT}" ]; then @@ -408,12 +408,29 @@ create_changefs() { setup_aufs() { bootstrapCD + if [ "$aufs_dev" = "search" ]; then + findmediamount "aufs-dev" "$aufs_union_file" \ + "aufs_dev" "$aufs_dev_mnt" $(devicelist) + aufs_mounted="1" + elif [ -z $aufs_dev ] && [ -w "$CDROOT_PATH/$aufs_union_file" ]; then + aufs_dev="$REAL_ROOT" + aufs_dev_mnt="$CDROOT_PATH" + aufs_mounted="1" + fi + if [ -z $aufs_dev ] && [ -w "$CDROOT_PATH/casper-rw" ]; then + aufs_dev="$REAL_ROOT" + aufs_dev_mnt="$CDROOT_PATH" + aufs_union_file="/casper-rw" + aufs_mounted="1" + fi + if [ -n "$aufs_dev" ]; then if [ ! -b $aufs_dev ]; then bad_msg "$aufs_dev is not a valid block device" local invalidblk=1 unset aufs_dev - else + #skip this block when aufs_dev_mnt is already mounted + elif [ "$aufs_mounted" != "1" ]; then good_msg "Mounting $aufs_dev to $aufs_memory for aufs support" if ! mount -t auto "$aufs_dev" "$aufs_dev_mnt" &>/dev/null; then @@ -428,6 +445,9 @@ setup_aufs() { elif [ -n "$aufs_dev" ]; then while :; do if mount -t auto "$aufs_dev_mnt$aufs_union_file" "$aufs_memory" &>/dev/null; then + if [ "$aufs_union_file" = "/casper-rw" ];then + bad_msg "Use of livecd.aufs preferred to casper-rw for changes saving, please rename the file." + fi break else bad_msg "Mounting of changes file failed, Running e2fsck" -- cgit v1.2.3-65-gdbad From 3a4aa156c84bbc832618b8795bb8b3fae0be3f1f Mon Sep 17 00:00:00 2001 From: "Rick Farina (Zero_Chaos)" Date: Mon, 22 Sep 2014 20:19:43 -0400 Subject: /usr/portage/distfiles shouldn't be tmpfs It really doesn't make sense for /usr/portage/distfiles to be tmpfs, plus, if a user is using aufs and trying to save changes we don't want to lose these files. Only /tmp and /var/tmp should be tmpfs. --- defaults/linuxrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index 951f5e12..19b98789 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -770,7 +770,7 @@ then # Fstab changes for aufs if ! grep -q '^aufs' "$CHROOT/etc/fstab" 2>/dev/null; then - for dir in /var/tmp /tmp /usr/portage/distfiles; do + for dir in /var/tmp /tmp; do [ ! -d $CHROOT$dir ] && mkdir -p "$CHROOT$dir" done @@ -782,7 +782,6 @@ then aufs / aufs defaults 0 0 vartmp /var/tmp tmpfs defaults 0 0 tmp /tmp tmpfs defaults 0 0 -distfiles /usr/portage/distfiles tmpfs defaults 0 0 FSTAB fi -- cgit v1.2.3-65-gdbad