10FixPartitionTable.in 2.01 KB
Newer Older
1
2
#! /bin/bash

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.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
### BEGIN TASK INFO
# Provides:		FixPartitionTable
# RunBefore:		FilesystemResizeUnmounted
# Short-Description:	Resize filesystem to use all the available space
### END TASK INFO

set -e
. "@commondir@/common.sh"

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

if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then
    log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition"
fi

retval=$(get_last_partition "$SNF_IMAGE_DEV")

id=$(echo $retval | cut -d: -f1)
40
41
42
pstart=$(echo $retval | cut -d: -f2)
pend=$(echo $retval | cut -d: -f3)
ptype=$(echo $retval | cut -d: -f5)
43
44
45
46
47
48
49

if [ $id -gt 4 ]; then
    log_error "We don't support logical volumes"
fi

if [ x"$ptype" = "x" ]; then
    # Don't know how to handle this
50
51
    warn "Last partition with id: \`$id' is empty or has unknown filesystem"
    warn "I won't resize the partition"
52
53
54
55
56
    exit 0
fi

new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")

57
58
59
60
61
62
if [ -z "$new_pend" ] ; then
    # Nothing to do
    exit 0
fi

# Extend the partition
63

64
$PARTED -s -m "$SNF_IMAGE_DEV" rm "$id"
65
66
$PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"

67
# Inform the kernel about the changes
68
69
70
71
72
partprobe "$SNF_IMAGE_DEV"

exit 0

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