#! /bin/bash
+# Copyright (C) 2011 GRNET S.A.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
### BEGIN TASK INFO
# Provides: MountImage
# RunBefore: UmountImage
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" = "freebsd" ]; then
+ if ! $DUMPFS_UFS "$rootdev" &> /dev/null; then
+ log_error "For FreeBSD images only UFS root partitions are supported."
+ fi
+ $MOUNT -t ufs -o ufstype=ufs2,rw "$rootdev" "$SNF_IMAGE_TARGET"
+else
+ $MOUNT -o rw "$rootdev" "$SNF_IMAGE_TARGET"
+fi
+
+if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
+ exit 0
fi
-mount "$rootdev" "$SNF_IMAGE_TARGET" -o rw
+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