- modprobe -Qb unionfs
- mkdir -p /cow
-
- if grep -q persistent /proc/cmdline; then
- i=0
- # We love udev and the kernel!
- while [ "$i" -lt 300 ]; do
- cowdevice=$(find_cow_device)
- if [ -b "$cowdevice" ]; then
- mount -t $(get_fstype "$cowdevice") -o rw "$cowdevice" /cow || panic "Can not mount $cowdevice on /cow"
- break
- fi
- sleep 5
-# sleep 0.1
- i=$(( $i + 1 ))
- done
- else
- mount -t tmpfs tmpfs /cow
- fi
-
- mkdir -p /rofs
- if [ "$(get_fstype $backdev)" = "unknown" ]; then
- panic "Unknown file system type on $backdev"
- fi
- mount -t $(get_fstype "$backdev") -o ro "$backdev" /rofs || panic "Can not mount $backdev on /rofs"
-
- mount -t unionfs -o dirs=/cow=rw:/rofs=ro unionfs "$rootmnt"
- if grep -q show-cow /proc/cmdline; then
- mkdir -p "$rootmnt/cow"
- mount -o bind /cow "$rootmnt/cow"
- fi
- mkdir -p "$rootmnt/rofs"
- mount -o bind /rofs "$rootmnt/rofs"
+ image_type="$3"
+
+ modprobe -qb unionfs
+ croot="" # Should really be /casper, but run-init doesn't handle
+ # mount-points in subdirectories at all
+
+ # Let's just mount the read-only file systems first
+ rofsstring=""
+ rofslist=""
+ mkdir -p "${croot}"
+ for image_type in "ext2" "squashfs" "dir" ; do
+ for image in "${image_directory}"/*."${image_type}"; do
+ imagename=$(basename "${image}")
+ if [ -d "${image}" ]; then
+ # it is a plain directory: do nothing
+ rofslist="${image} ${rofslist}"
+ rofsstring="${image}=ro:${rofsstring}"
+ elif [ -f "${image}" ]; then
+ backdev=$(get_backing_device "$image")
+ fstype=$(get_fstype "${backdev}")
+ if [ "${fstype}" = "unknown" ]; then
+ panic "Unknown file system type on ${backdev} (${image})"
+ fi
+ mkdir -p "${croot}/${imagename}"
+ mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=ro:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
+ fi
+ done
+ done
+ rofsstring=${rofsstring%:}
+
+ mkdir -p /cow
+ cowdevice="tmpfs"
+ cow_fstype="tmpfs"
+
+ # Looking for "${root_persistence}" device or file
+ if grep -q persistent /proc/cmdline; then
+ cowprobe=$(find_cow_device "${root_persistence}")
+ if [ -b "${cowprobe}" ]; then
+ cowdevice=${cowprobe}
+ cow_fstype=$(get_fstype "${cowprobe}")
+ else
+ [ "$quiet" != "y" ] && log_begin_msg "Unable to find the persistent medium"
+ fi
+ fi
+
+ mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
+
+ mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt"
+
+ for d in ${rofslist}; do
+ mkdir -p "${rootmnt}/casper/${d}"
+ mount -o bind "${d}" "${rootmnt}/${d}"
+ case d in
+ *.dir) ;; # do nothing
+ *) umount "${d}" ;;
+ esac
+ done
+
+ # Adding other custom mounts
+ if grep -q homepersistence /proc/cmdline; then
+ homecow=$(find_cow_device "${home_persistence}" )
+ if [ -b "${homecow}" ]; then
+ mount ${homecow} -t $(get_fstype "${homecow}") -o rw "${rootmnt}/home"
+ else
+ [ "$quiet" != "y" ] && log_begin_msg "Unable to find the persistent home medium"
+ fi
+ fi
+
+ if grep -q show-cow /proc/cmdline; then
+ mkdir -p "$rootmnt/cow"
+ mount -o bind /cow "$rootmnt/cow"
+ fi