3 # Copyright (C) 2011 GRNET S.A.
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.
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.
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
21 # Provides: FixPartitionTable
22 # RunBefore: FilesystemResizeUnmounted
23 # Short-Description: Resize filesystem to use all the available space
27 . "@commondir@/common.sh"
29 if [ ! -b "$SNF_IMAGE_DEV" ]; then
30 log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
33 if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then
34 log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition"
37 retval=$(get_last_partition "$SNF_IMAGE_DEV")
39 id=$(echo $retval | cut -d: -f1)
40 pstart=$(echo $retval | cut -d: -f2)
41 pend=$(echo $retval | cut -d: -f3)
42 ptype=$(echo $retval | cut -d: -f5)
44 if [ $id -gt 4 ]; then
45 log_error "We don't support logical volumes"
48 if [ x"$ptype" = "x" ]; then
49 # Don't know how to handle this
50 warn "Last partition with id: \`$id' is empty or has unknown filesystem"
51 warn "I won't resize the partition"
55 new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
57 if [ -z "$new_pend" ] ; then
62 # Extend the partition
64 $PARTED -s -m "$SNF_IMAGE_DEV" rm "$id"
65 $PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"
67 # Inform the kernel about the changes
68 partprobe "$SNF_IMAGE_DEV"
72 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :