Add diskdump support in the helper (part 1)
[snf-image] / snf-image-helper / tasks / 10FixPartitionTable.in
1 #! /bin/bash
2
3 ### BEGIN TASK INFO
4 # Provides:             FixPartitionTable
5 # RunBefore:            FilesystemResizeUnmounted
6 # Short-Description:    Resize filesystem to use all the available space
7 ### END TASK INFO
8
9 set -e
10 . "@commondir@/common.sh"
11
12 if [ ! -b "$SNF_IMAGE_DEV" ]; then
13     log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
14 fi
15
16 if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then
17     log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition"
18 fi
19
20 retval=$(get_last_partition "$SNF_IMAGE_DEV")
21
22 id=$(echo $retval | cut -d: -f1)
23
24 if [ $id -gt 4 ]; then
25     log_error "We don't support logical volumes"
26 fi
27
28 pstart=$(echo $retval | cut -d: -f2)
29 pend=$(echo $retval | cut -d: -f3)
30 ptype=$(echo $retval | cut -d: -f5)
31
32 if [ x"$ptype" = "x" ]; then
33     # Don't know how to handle this
34     echo "Warning: Last partition with id: \`$id' is empty" \
35         "or has unknown filesystem"
36
37     exit 0
38 fi
39
40 new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
41
42 #Extend the partition
43
44 $PARTED -s -m "$SNF_IMAGE_DEV" rm $id
45 $PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"
46
47 #inform the kernel about the changes
48 partprobe "$SNF_IMAGE_DEV"
49
50 exit 0
51
52 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :