Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (1.2 kB)

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
pstart=$(echo $retval | cut -d: -f2)
24
pend=$(echo $retval | cut -d: -f3)
25
ptype=$(echo $retval | cut -d: -f5)
26

    
27
if [ $id -gt 4 ]; then
28
    log_error "We don't support logical volumes"
29
fi
30

    
31
if [ x"$ptype" = "x" ]; then
32
    # Don't know how to handle this
33
    warn "Last partition with id: \`$id' is empty or has unknown filesystem"
34
    warn "I won't resize the partition"
35
    exit 0
36
fi
37

    
38
new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
39

    
40
#Extend the partition
41

    
42
$PARTED -s -m "$SNF_IMAGE_DEV" rm "$id"
43
$PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"
44

    
45
#inform the kernel about the changes
46
partprobe "$SNF_IMAGE_DEV"
47

    
48
exit 0
49

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