Statistics
| Branch: | Tag: | Revision:

root / snf-image-helper / tasks / 20FilesystemResizeUnmounted.in @ 365b2ed3

History | View | Annotate | Download (2.8 kB)

1
#! /bin/bash
2

    
3
# Copyright (C) 2011 GRNET S.A. 
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

    
20
### BEGIN TASK INFO
21
# Provides:		FilesystemResizeUnmounted
22
# RunBefore:		MountImage
23
# RunAfter:             FixPartitionTable
24
# Short-Description:	Resize filesystem to use all the available space
25
### END TASK INFO
26

    
27
set -e
28
. "@commondir@/common.sh"
29

    
30
trap task_cleanup EXIT
31
report_task_start
32
# Check if the task should be prevented from running.
33
check_if_excluded
34

    
35
if [ ! -b "$SNF_IMAGE_DEV" ]; then
36
    log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
37
fi
38

    
39
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = openbsd ]; then
40
   part="${SNF_IMAGE_DEV}$(@scriptsdir@/disklabel.py --print-last-linux "$SNF_IMAGE_DEV")"
41

    
42
   # If this fails the script will stop
43
   $DUMPFS_OPENBSD "$part" > /dev/null
44

    
45
   $GROWFS_OPENBSD -y "$part"
46
   exit 0
47
fi
48

    
49
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = netbsd ]; then
50
    warn "File system resizing currently not supported for NetBSD"
51
    exit 0
52
fi
53

    
54
if [ -z "$SNF_IMAGE_RESIZE_PART" ]; then
55
    warn "No partition chosen for resize"
56
    exit 0
57
fi
58

    
59
if [ "x$SNF_IMAGE_PROPERTY_DO_SYNC" = "xyes" ]; then
60
    unset EATMYDATA
61
fi
62

    
63
table=$(get_partition_table "$SNF_IMAGE_DEV")
64
partition=$(get_partition_by_num "$table" "$SNF_IMAGE_RESIZE_PART")
65
id=$(cut -d: -f1 <<< "$partition")
66
ptype=$(cut -d: -f5 <<< "$partition")
67

    
68
device="${SNF_IMAGE_DEV}${id}"
69

    
70
if [[ "$ptype" == ext[234] ]]; then
71
    state=$($TUNE2FS -l "$device" | grep ^Filesystem\ state: | cut -d: -f2);
72
    state=$(echo $state) #trim the value
73

    
74
    # We force a filesystem resize here if the file system is clean, even if
75
    # resize2fs complains. By default resize2fs will refuse to resize a file
76
    # system that has been mounted after the last fs check, but since we are
77
    # sure the file system is clean it's safe enough to bypass this.
78
    if [ "$state" = "clean" ]; then
79
        $EATMYDATA $RESIZE2FS -f "$device"
80
    else
81
        log_error "The file system state of partition: \`$device' " \
82
            " is not clean (state = $state)"
83
    fi
84
elif [[ "$ptype" == "freebsd-ufs" ]]; then
85
    $GROWFS_UFS -y "$device"
86
else
87
    warn "Don't know how to resize partition \`$id' with file system \`$ptype'."
88
fi
89

    
90
exit 0
91

    
92
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :