root / snf-image-helper / tasks / 10FixPartitionTable.in @ 2a0c492d
History | View | Annotate | Download (2.1 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 |
# Check if the task should be prevented from running. |
30 |
check_if_excluded |
31 |
|
32 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
33 |
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" |
34 |
fi |
35 |
|
36 |
if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then |
37 |
log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition" |
38 |
fi |
39 |
|
40 |
retval=$(get_last_partition "$SNF_IMAGE_DEV") |
41 |
|
42 |
id=$(echo $retval | cut -d: -f1) |
43 |
pstart=$(echo $retval | cut -d: -f2) |
44 |
pend=$(echo $retval | cut -d: -f3) |
45 |
ptype=$(echo $retval | cut -d: -f5) |
46 |
|
47 |
if [ $id -gt 4 ]; then |
48 |
log_error "We don't support logical volumes" |
49 |
fi |
50 |
|
51 |
if [ x"$ptype" = "x" ]; then |
52 |
# Don't know how to handle this |
53 |
warn "Last partition with id: \`$id' is empty or has unknown filesystem" |
54 |
warn "I won't resize the partition" |
55 |
exit 0 |
56 |
fi |
57 |
|
58 |
new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV") |
59 |
|
60 |
if [ -z "$new_pend" ] ; then |
61 |
# Nothing to do |
62 |
exit 0 |
63 |
fi |
64 |
|
65 |
# Extend the partition |
66 |
|
67 |
$PARTED -s -m "$SNF_IMAGE_DEV" rm "$id" |
68 |
$PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend" |
69 |
|
70 |
# Inform the kernel about the changes |
71 |
partprobe "$SNF_IMAGE_DEV" |
72 |
|
73 |
exit 0 |
74 |
|
75 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |