Revision b126203e snf-image-helper/tasks/10FixPartitionTable.in

b/snf-image-helper/tasks/10FixPartitionTable.in
33 33
    log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
34 34
fi
35 35

  
36
check_partition_table "$SNF_IMAGE_DEV"
36
table=$(get_partition_table "$SNF_IMAGE_DEV")
37 37

  
38
if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then
38
if [ $(get_partition_count "$table") -eq 0 ]; then
39 39
    log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition"
40 40
fi
41 41

  
42
retval=$(get_last_partition "$SNF_IMAGE_DEV")
42
table_type=$(get_partition_table_type "$table")
43 43

  
44
id=$(echo $retval | cut -d: -f1)
45
pstart=$(echo $retval | cut -d: -f2)
46
pend=$(echo $retval | cut -d: -f3)
47
ptype=$(echo $retval | cut -d: -f5)
48

  
49
if [ $id -gt 4 ]; then
50
    log_error "We don't support logical partitions"
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."
51 47
fi
52 48

  
53
if [ x"$ptype" = "x" ]; then
54
    # Don't know how to handle this
55
    warn "Last partition with id: \`$id' is empty or has unknown filesystem"
56
    warn "I won't resize the partition"
57
    exit 0
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"
58 78
fi
59 79

  
60
new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
61

  
62
if [ -z "$new_pend" ] ; then
63
    # Nothing to do
64
    exit 0
65
fi
66

  
67
# Extend the partition
68

  
69
$PARTED -s -m "$SNF_IMAGE_DEV" rm "$id"
70
$PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"
80
enlarge_partition "$SNF_IMAGE_DEV" "$last_part" "$last_part_type"
71 81

  
72 82
# Inform the kernel about the changes
73 83
partprobe "$SNF_IMAGE_DEV"

Also available in: Unified diff