20FilesystemResizeUnmounted.in 3.04 KB
Newer Older
1
#! /bin/bash
Nikos Skalkotos's avatar
Nikos Skalkotos committed
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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.

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

set -e
28
. "@commondir@/common.sh"
Nikos Skalkotos's avatar
Nikos Skalkotos committed
29

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

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

39
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = openbsd ]; then
Nikos Skalkotos's avatar
Nikos Skalkotos committed
40
41
42
43
44
    bsd_part="$(@scriptsdir@/disklabel.py --get-last-partition "$SNF_IMAGE_DEV")"
    if [ "$bsd_part" = "b" ]; then
        warn "Last partition is swap space. Resizing ommited"
        exit 0
    fi
45

Nikos Skalkotos's avatar
Nikos Skalkotos committed
46
    part="${SNF_IMAGE_DEV}$(disklabel2linux "$bsd_part")"
47

Nikos Skalkotos's avatar
Nikos Skalkotos committed
48
49
50
51
52
    $DUMPFS_OPENBSD "$part" > /dev/null ||
        { warn "Filesystem is not UFS. Resizing ommited"; exit 0; }

    $GROWFS_OPENBSD -y "$part"
    exit 0
53
54
55
56
57
58
59
fi

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

60
61
62
63
64
if [ -z "$SNF_IMAGE_RESIZE_PART" ]; then
    warn "No partition chosen for resize"
    exit 0
fi

65
if [ "x$SNF_IMAGE_PROPERTY_DO_SYNC" = "xyes" ]; then
66
67
68
    unset EATMYDATA
fi

69
table=$(get_partition_table "$SNF_IMAGE_DEV")
70
partition=$(get_partition_by_num "$table" "$SNF_IMAGE_RESIZE_PART")
71
72
id=$(cut -d: -f1 <<< "$partition")
ptype=$(cut -d: -f5 <<< "$partition")
73

Nikos Skalkotos's avatar
Nikos Skalkotos committed
74
device="${SNF_IMAGE_DEV}${id}"
75

Nikos Skalkotos's avatar
Nikos Skalkotos committed
76
if [[ "$ptype" == ext[234] ]]; then
77
    state=$($TUNE2FS -l "$device" | grep ^Filesystem\ state: | cut -d: -f2);
78
79
    state=$(echo $state) #trim the value

80
81
82
83
    # 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.
84
    if [ "$state" = "clean" ]; then
85
        $EATMYDATA $RESIZE2FS -f "$device"
86
87
88
89
    else
        log_error "The file system state of partition: \`$device' " \
            " is not clean (state = $state)"
    fi
Nikos Skalkotos's avatar
Nikos Skalkotos committed
90
91
elif [[ "$ptype" == "freebsd-ufs" ]]; then
    $GROWFS_UFS -y "$device"
92
else
93
    warn "Don't know how to resize partition \`$id' with file system \`$ptype'."
94
fi
Nikos Skalkotos's avatar
Nikos Skalkotos committed
95
96

exit 0
97

Nikos Skalkotos's avatar
Nikos Skalkotos committed
98
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :