diff options
author | Fernando Reyes <fernando.r@weboperative.com> | 2014-09-04 22:57:17 -0400 |
---|---|---|
committer | Fernando Reyes <fernando.r@weboperative.com> | 2014-09-04 22:57:17 -0400 |
commit | a3702a25188312f16841623ab1f6294137705bca (patch) | |
tree | 232519c0b0112f28aa749924c933ab19d5038454 | |
parent | Bump version to 3.4.51 (diff) | |
parent | restructure no_umounts from being set in /etc/rc.conf to /etc/conf.d/localmount (diff) | |
download | genkernel-a3702a25188312f16841623ab1f6294137705bca.tar.gz genkernel-a3702a25188312f16841623ab1f6294137705bca.tar.bz2 genkernel-a3702a25188312f16841623ab1f6294137705bca.zip |
Merge branch 'aufs-new' into master-test
-rwxr-xr-x | defaults/initrd.defaults | 8 | ||||
-rw-r--r-- | defaults/initrd.scripts | 289 | ||||
-rw-r--r-- | defaults/linuxrc | 267 |
3 files changed, 447 insertions, 117 deletions
diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults index 69be5160..f6fd5648 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,6 +60,7 @@ KSUFF='.ko' REAL_ROOT='' CONSOLE='/dev/console' NEW_ROOT='/newroot' +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' @@ -66,6 +69,11 @@ CDROOT_PATH='/mnt/cdrom' # marker. It must exist RELATIVE to the cdroot. 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' DEFAULT_NFSOPTIONS="ro,nolock,rsize=1024,wsize=1024" diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 5ef5d0bb..7b8e52ff 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -177,6 +177,52 @@ devicelist(){ echo ${DEVICES} } +bootstrapFS() { + if [ 1 = "$aufs" ]; then + # Directories used for rw aufs mount filesystem + aufs_union=/union aufs_memory=/memory + + # Mountpoint for the aufs dev + aufs_dev_mnt=/mnt/aufs-dev + + if [ -z "$aufs_dev_uid" ]; then + aufs_branch=$aufs_memory/aufs-branch/default + else + aufs_branch=$aufs_memory/aufs-branch/$aufs_dev_uid + fi + + mkdir -p $aufs_memory $aufs_union $aufs_dev_mnt + 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 -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 + [ ! -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= @@ -234,6 +280,217 @@ 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:) + 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 +# added to allow users to add their own apps. +union_insert_modules() { + local module + + for module in "$1/modules/"*.mo; do + union_mod "$module" || bad_msg "Unable to insert module: '$module'" + done + + for module in "$1/modules/"*.lzm; do + union_mod "$module" || bad_msg "Unable to insert module: '$module'" + done +} + +# Helper function for union_insert_modules() +union_mod() { + [ -e "$1" ] || return 0 + + local mod + + mod=${1##*/} + mod=${mod%.*} + + if [ ! -d "$aufs_union"/mnt/"$mod" ]; then + mkdir -p "$aufs_union"/mnt/modules/"$mod" || return + fi + + mount -o loop,ro "$1" "$aufs_union"/mnt/modules/"$mod" + union_insert_dir "$aufs_union" "$aufs_union"/mnt/modules/"$mod" +} + +# 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/conf.d/localmount fnd=0 + + if nomount=$(grep -n '^[[:blank:]]*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 + "\"$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 /etc/conf.d/localmount" + fi + fi + + if [ 0 -eq "$fnd" ]; then + printf 'no_umounts="%s"\n' "$no_umounts" >> $conf + test_success "Unable to write to /etc/conf.d/localmount" + 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 $aufs_dev, $aufs_dev_mnt mountpoint +create_changefs() { + local size + + while :; do + read -p '<< Size of file (Press Enter for default 256 MB): ' size + + size=${size:-256} + + 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=$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 "Ensure your disk is not full or read-only" + + read -p '<< Type "a" to abort, anything else to continue : ' doabort + 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 $? +} + +setup_aufs() { + bootstrapCD + + 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 + fi + + # 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_union_file#*/} to ${aufs_union_file#*/}.bad" + + mv "$aufs_dev_mnt$aufs_union_file" "$aufs_dev_mnt$aufs_union_file.bad" + break + fi + + 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_union_file#*/} image might be corrupted" + bad_msg "moving ${aufs_union_file#*/} to ${aufs_union_file#*/}.bad" + + 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 + + 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" + + mount -t tmpfs tmpfs "$aufs_memory" + else + aufs_xino=$aufs_memory/xino + + mkdir -p "$aufs_xino" + mount -t tmpfs aufs-xino "$aufs_xino" + fi + else + aufs_xino=$aufs_memory + + good_msg "Mounting ramdisk to $aufs_memory for aufs support" + mount -t tmpfs tmpfs "$aufs_memory" + fi + + 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 +} + + findnfsmount() { if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q then @@ -1181,31 +1438,19 @@ getdvhoff() { } setup_squashfs_aufs() { - ( # Setup aufs directories and vars - local overlay=/mnt/overlay - local static=/mnt/livecd + aufs_rw_branch=/mnt/aufs-rw-branch aufs_ro_branch=/mnt/livecd - for i in "${overlay}" "${static}"; do - [ ! -d "${i}" ] && mkdir -p "${i}" + for dir in $aufs_rw_branch $aufs_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}" - - [ ! -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 - local new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}" - mount --bind "${CDROOT_PATH}" "${new_cdroot}" - ) + + good_msg "Loading aufs module ..." + modprobe aufs &>/dev/null + + 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 6401614f..951f5e12 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -251,7 +251,22 @@ do keymap=${x#*=} ;; aufs) - USE_AUFS_NORMAL=1 + aufs=1 + ;; + aufs\=*) + aufs=1 + + if echo "${x#*=}" | grep , &>/dev/null; then + aufs_dev_uid=${x#*,} + aufs_dev=${x%,*} + else + aufs_dev=${x#*=} + fi + ;; + # Allow user to specify the modules location + aufs.modules\=*) + aufs_modules_dir=${x#*=} + aufs_modules=1 ;; unionfs) if [ ! -x /sbin/unionfs ] @@ -425,35 +440,17 @@ 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 the root filesystem + bootstrapFS - 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 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 + if [ 1 = "$aufs" ]; then + setup_aufs + CHROOT=$aufs_union + else + CHROOT=${NEW_ROOT} 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" ] - then + if [ /dev/nfs != "$REAL_ROOT" ] && [ sgimips != "$LOOPTYPE" ] && [ 1 != "$aufs" ]; then bootstrapCD fi @@ -485,7 +482,7 @@ then fi # Determine root device -good_msg 'Determining root device...' +good_msg 'Determining root device ...' while true do while [ "${got_good_root}" != '1' ] @@ -694,7 +691,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' @@ -703,7 +700,7 @@ then FS_LOCATION='mnt/livecd' elif [ "${LOOPTYPE}" = 'squashfs' ] then - if [ "${USE_AUFS_NORMAL}" != '1' ]; 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 @@ -719,9 +716,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' ] @@ -762,10 +760,65 @@ then test_success 'mount /dev/loop0 /' FS_LOCATION='mnt/livecd' fi + fi # if [ -n "${CRYPT_ROOT}" ] + + if [ 1 = "$aufs" ]; then + union_insert_dir "$CHROOT" "$aufs_ro_branch" + + # 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 dir in /var/tmp /tmp /usr/portage/distfiles; do + [ ! -d $CHROOT$dir ] && mkdir -p "$CHROOT$dir" + done + + 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 +distfiles /usr/portage/distfiles tmpfs defaults 0 0 +FSTAB + fi + + # 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 [ mnt/cdrom = "$aufs_modules_dir" ]; then + union_insert_modules "$CDROOT_PATH" + 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 + + # 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 + [ ! -d $CHROOT$NEW_ROOT ] && mkdir -p "$CHROOT$NEW_ROOT" + + # 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 - - # Unpacking additional packages from NFS mount # This is useful for adding kernel modules to /lib # We do this now, so that additional packages can add whereever they want. @@ -783,67 +836,70 @@ then fi - if [ "${USE_UNIONFS_NORMAL}" = '1' ] - then + if [ "${USE_UNIONFS_NORMAL}" = '1' ]; 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}" ] - 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 - done - fi - done - - mkdir initramfs proc tmp sys run 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 + 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}/}" + + # 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 + fi + done + + mkdir -p initramfs proc tmp run sys 2>/dev/null + chmod 1777 tmp + + fi + + # 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' ] @@ -862,8 +918,12 @@ else mount -t tmpfs tmpfs /union_changes setup_unionfs /union_changes ${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 + +fi # if [ "${CDROOT}" = '1' ] # Mount the additional things as required by udev & systemd if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then @@ -894,7 +954,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 @@ -907,6 +967,23 @@ fi verbose_kmsg +if [ 1 = "$aufs" ]; then + aufs_union_memory=$CHROOT/.unions/memory + + 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 $aufs_rw_branch $aufs_ro_branch; do + mkdir -p "$CHROOT$dir" + chmod 755 "$CHROOT$dir" + done + + for mount in $aufs_rw_branch $aufs_ro_branch; do + mount --move "$mount" "$CHROOT$mount" + done +fi + good_msg "Booting (initramfs)" cd "${CHROOT}" |