aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'defaults/initrd.scripts')
-rw-r--r--defaults/initrd.scripts208
1 files changed, 106 insertions, 102 deletions
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() {