root / snf-image-helper / tasks / 10FixPartitionTable.in @ b126203e
History | View | Annotate | Download (2.8 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: Enlarge last partition 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 |
table=$(get_partition_table "$SNF_IMAGE_DEV") |
37 |
|
38 |
if [ $(get_partition_count "$table") -eq 0 ]; then |
39 |
log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition" |
40 |
fi |
41 |
|
42 |
table_type=$(get_partition_table_type "$table") |
43 |
|
44 |
if [ "$table_type" != "msdos" ]; then # We are planning to add gpt support |
45 |
log_error "Device: \'${SNF_IMAGE_DEV}' contains unsupported partition " |
46 |
"table type: \`$table_type'. For now only msdos partitions are supported." |
47 |
fi |
48 |
|
49 |
last_part=$(get_last_partition "$table") |
50 |
last_part_id=$(cut -d':' -f1 <<< "$last_part") |
51 |
|
52 |
if [ "$table_type" != "msdos" ]; then |
53 |
# Primary, extended and logical partitions is a concept for msdos partition |
54 |
# tables. Parted's mkpart will use part-type as partition name if applied |
55 |
# on a gpt table. |
56 |
last_part_type="" |
57 |
elif [ $last_part_id -gt 4 ]; then |
58 |
last_part_type="logical" |
59 |
extended=$(get_extended_partition "$table") |
60 |
last_primary=$(get_last_primary_partition "$table") |
61 |
|
62 |
ext_id=$(cut -d':' -f1 <<< "$extended") |
63 |
last_prim_id=$(cut -d':' -f1 <<< "$last_primary") |
64 |
|
65 |
if [ "$ext_id" != "$last_prim_id" ]; then |
66 |
#Mark last primary as the last partition |
67 |
last_part="$extended" |
68 |
last_part_id="$ext_id" |
69 |
last_part_type="primary" |
70 |
else |
71 |
#enlarge the extended partition |
72 |
enlarge_partition "$SNF_IMAGE_DEV" "$extended" "extended" |
73 |
fi |
74 |
elif [ $(is_extended_partition "$SNF_IMAGE_DEV" "$last_part_id") = "yes" ]; then |
75 |
last_part_type="extended" |
76 |
else |
77 |
last_part_type="primary" |
78 |
fi |
79 |
|
80 |
enlarge_partition "$SNF_IMAGE_DEV" "$last_part" "$last_part_type" |
81 |
|
82 |
# Inform the kernel about the changes |
83 |
partprobe "$SNF_IMAGE_DEV" |
84 |
|
85 |
exit 0 |
86 |
|
87 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |