#! /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 # Short-Description: Mount the partition that hosts the image ### END TASK INFO 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 "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 "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 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: # 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 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :