Add partial support for NetBSD and OpenBSD
[snf-image] / snf-image-helper / tasks / 30MountImage.in
index 5d45123..6938e22 100644 (file)
 set -e
 . "@commondir@/common.sh"
 
+trap task_cleanup EXIT
+report_task_start
+
 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
     log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing"
 fi
 
 if [ -z "$SNF_IMAGE_PROPERTY_ROOT_PARTITION" ]; then
-    log_error "Root Partition image property not defined"
+    log_error "Required image property \`ROOT_PARTITION' not defined or empty"
 fi
 
 rootdev="${SNF_IMAGE_DEV}${SNF_IMAGE_PROPERTY_ROOT_PARTITION}"
 
 if [ ! -b "$rootdev" ]; then
-    log_error "Image root partition device:\`$rootdev' is not a block device"
+    log_error "Root partition device:\`$rootdev' is not a block device. " \
+        "Please check if the value for image property \`ROOT_PARTITION' " \
+        "(=$SNF_IMAGE_PROPERTY_ROOT_PARTITION) is valid."
+fi
+
+if [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" == *bsd ]]; then
+    if ! $DUMPFS_UFS "$rootdev" &> /dev/null; then
+        os=${SNF_IMAGE_PROPERTY_OSFAMILY^[bsd]}
+        log_error "For ${os^?} images only UFS root partitions are supported."
+    fi
+    usftype="$(get_ufstype "$rootdev")"
+    if [ "x$ufstype" = "x" ]; then
+        exit 1
+    fi
+    $MOUNT -t ufs -o ufstype="$ufstype,rw" "$rootdev" "$SNF_IMAGE_TARGET"
+else
+    $MOUNT -o rw "$rootdev" "$SNF_IMAGE_TARGET"
 fi
 
-mount "$rootdev" "$SNF_IMAGE_TARGET" -o rw
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
+    exit 0
+fi
+
+if [ ! -f "${SNF_IMAGE_TARGET}/etc/fstab" ]; then
+    log_error "/etc/fstab is missing from the root file system"
+fi
+
+# Read the local partitions from fstab and get a sorted list:
+#<mount_point> <device> <options>
+fstab="$(grep -v ^\# "${SNF_IMAGE_TARGET}/etc/fstab" | awk '{ if (match($3, "ext[234]")) { print $2,$1,$4 } }' | sort -bd)"
+
+# Mount non-root filesystems
+while read line; do
+    read -ra entry <<< "$line"
+    # Skip root. It is already mounted
+    if [ "${entry[0]}" = "/" ]; then
+        continue
+    fi
+
+    if [[ ${entry[1]} =~ ^(LABEL|UUID)= ]]; then
+        entry[1]=$(findfs "${entry[1]}")
+    fi
+
+    # I'm in doupt. Sould I mount the filesystems with the mount options
+    # found in the image's /etc/fstab or not?
+    $MOUNT "${entry[1]}" "${SNF_IMAGE_TARGET}${entry[0]}" # -o "${entry[2]}"
+
+done <<< "$fstab"
 
 exit 0