Statistics
| Branch: | Tag: | Revision:

root / snf-image-helper / tasks / 10FixPartitionTable.in @ 7e5d635b

History | View | Annotate | Download (2 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:		FixPartitionTable
22
# RunBefore:		FilesystemResizeUnmounted
23
# Short-Description:	Resize filesystem to use all the available space
24
### END TASK INFO
25

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

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

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

    
37
retval=$(get_last_partition "$SNF_IMAGE_DEV")
38

    
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)
43

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

    
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"
52
    exit 0
53
fi
54

    
55
new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
56

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

    
62
# Extend the partition
63

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

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

    
70
exit 0
71

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