-setup_unionfs() {
- image_directory="$1"
- rootmnt="$2"
-
- modprobe "${MP_QUIET}" -b unionfs
-
- # 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
-
- # Read image names from ${MODULE}.lst if it exists
- if [ -e "${image_directory}/${MODULE}.lst" ]; then
- for image in $(cat "${image_directory}/${MODULE}.lst"); do
- image_string="${image_string} ${image_directory}/${image}";
- done
- else
- # If ${MODULE}.lst does not exist, create a list of images
- for image_type in "ext2" "ext3" "squashfs" "dir"; do
- for image in "${image_directory}"/*."${image_type}"; do
- if [ -e "${image}" ]; then
- image_string="${image_string} ${image}";
+setup_unionfs ()
+{
+ image_directory="${1}"
+ rootmnt="${2}"
+
+ modprobe -q -b ${UNIONTYPE}
+
+ # 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=""
+ minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
+
+ if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
+ then
+ # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
+ roopt="nfsro"
+ else
+ roopt="ro"
+ fi
+
+ # Read image names from ${MODULE}.module if it exists
+ if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
+ then
+ for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
+ do
+ image_string="${image_string} ${image_directory}/${IMAGE}"
+ done
+ elif [ -e "${image_directory}/${MODULE}.module" ]
+ then
+ for IMAGE in $(cat ${image_directory}/${MODULE}.module)
+ do
+ image_string="${image_string} ${image_directory}/${IMAGE}"
+ done
+ else
+ # ${MODULE}.module does not exist, create a list of images
+ for FILESYSTEM in squashfs ext2 ext3 xfs dir
+ do
+ for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
+ do
+ if [ -e "${IMAGE}" ]
+ then
+ image_string="${image_string} ${IMAGE}"
+ fi
+ done
+ done
+
+ # Now sort the list
+ image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
+ fi
+
+ [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
+
+ mkdir -p "${croot}"
+
+ for image in ${image_string}
+ 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}"
+ echo "debug: Can not mount backdev ${backdev} (image = ${image}) on croot/imagename ${croot}/${imagename}"
+ mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
+ fi
+ done
+
+ rofsstring=${rofsstring%:}
+
+ mkdir -p /cow
+
+ # 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
+ elif [ -n "${NFS_COW}" ]
+ then
+ # check if there are any nfs options
+ if echo ${NFS_COW}|grep -q ','
+ then
+ nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
+ nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
+ else
+ nfs_cow_opts="-o nolock"
+ nfs_cow=${NFS_COW}
+ fi
+ mac=$(get_mac)
+ if [ -n "${mac}" ]
+ then
+ cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
+ cow_fstype="nfs"
+ else
+ panic "unable to determine mac address"
+ fi
+ else
+ cowdevice="tmpfs"
+ cow_fstype="tmpfs"
+ fi
+
+ if [ "${cow_fstype}" = "nfs" ]
+ then
+ [ "${quiet}" != "y" ] && log_begin_msg \
+ "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
+ nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
+ panic "Can not mount ${cowdevice} on /cow"
+ else
+ mount ${cowdevice} -t ${cow_fstype} -o rw,noatime /cow || \
+ panic "Can not mount ${cowdevice} on /cow"
+ fi
+
+ rofscount=$(echo ${rofslist} |wc -w)
+
+ if [ -n "${EXPOSED_ROOT}" ]
+ then
+ if [ ${rofscount} -ne 1 ]
+ then
+ panic "only one RO file system supported with exposedroot: ${rofslist}"