#! /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: FilesystemResizeUnmounted # RunBefore: MountImage # RunAfter: FixPartitionTable # Short-Description: Resize filesystem to use all the available space ### END TASK INFO set -e . "@commondir@/common.sh" trap task_cleanup EXIT report_task_start # Check if the task should be prevented from running. check_if_excluded if [ ! -b "$SNF_IMAGE_DEV" ]; then log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" fi if [ -z "$SNF_IMAGE_RESIZE_PART" ]; then warn "No partition chosen for resize" exit 0 fi if [ -n "$SNF_IMAGE_PROPERTY_DO_SYNC" ]; then unset EATMYDATA fi if [[ "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ (net)|(open)bsd ]]; then os=${SNF_IMAGE_PROPERTY_OSFAMILY^^[bsd]} warn "File sytem resizing currently not supported for ${os^?}" exit 0 fi table=$(get_partition_table "$SNF_IMAGE_DEV") partition=$(get_partition_by_num "$table" "$SNF_IMAGE_RESIZE_PART") id=$(cut -d: -f1 <<< "$partition") ptype=$(cut -d: -f5 <<< "$partition") device="${SNF_IMAGE_DEV}${id}" if [[ "$ptype" == ext[234] ]]; then state=$($TUNE2FS -l "$device" | grep ^Filesystem\ state: | cut -d: -f2); state=$(echo $state) #trim the value # We force a filesystem resize here if the file system is clean, even if # resize2fs complains. By default resize2fs will refuse to resize a file # system that has been mounted after the last fs check, but since we are # sure the file system is clean it's safe enough to bypass this. if [ "$state" = "clean" ]; then $EATMYDATA $RESIZE2FS -f "$device" else log_error "The file system state of partition: \`$device' " \ " is not clean (state = $state)" fi elif [[ "$ptype" == "freebsd-ufs" ]]; then $GROWFS_UFS -y "$device" else warn "Don't know how to resize partition \`$id' with file system \`$ptype'." fi exit 0 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :