-setup_unionfs() {
- image_directory="$1"
- rootmnt="$2"
- 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
+ # run-init can't deal with images in a subdir, but we're going to
+ # move all of these away before it runs anyway. No, we're not,
+ # put them in / since move-mounting them into / breaks mono and
+ # some other apps.
+
+ croot="/"
+
+ # Let's just mount the read-only file systems first
+ rofsstring=""
+ rofslist=""
+ if [ "${NETBOOT}" == "nfs" ] ; then
+ roopt="nfsro" # go aroung a bug in nfs-unionfs locking
+ else
+ roopt="ro"
+ fi
+
+ 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
+ rofsstring="${image}=${roopt}:${rofsstring}"
+ rofslist="${image} ${rofslist}"
+ 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}=${roopt}:${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 [ -n "${PERSISTENT}" ]; then
+ cowprobe=$(find_cow_device "${root_persistence}")
+ if [ -b "${cowprobe}" ]; then
+ cowdevice=${cowprobe}
+ cow_fstype=$(get_fstype "${cowprobe}")
+ else
+ [ "$quiet" != "y" ] && log_warning_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" || panic "Unionfs mount failed"
+
+ # Adding other custom mounts
+ if [ -n "${PERSISTENT}" ]; then
+ # directly mount /home
+ # FIXME: add a custom mounts configurable system
+ homecow=$(find_cow_device "${home_persistence}" )
+ if [ -b "${homecow}" ]; then
+ mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
+ export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
+ else
+ [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
+ fi
+ # Look for other snapshots to copy in
+ try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
+ try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
+ fi
+
+ if [ -n "${SHOWMOUNTS}" ]; then
+ for d in ${rofslist}; do
+ mkdir -p "${rootmnt}/casper/${d##*/}"
+ case d in
+ *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
+ ;;
+ *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
+ ;;
+ esac
+ done
+ fi
+
+ # shows cow fs on /cow for use by casper-snapshot
+ mkdir -p "${rootmnt}/cow"
+ mount -o bind /cow "${rootmnt}/cow"