Revision 8576747b snf-image-helper/common.sh
b/snf-image-helper/common.sh | ||
---|---|---|
30 | 30 |
SFDISK=sfdisk |
31 | 31 |
MKSWAP=mkswap |
32 | 32 |
BLKID=blkid |
33 |
BLOCKDEV=blockdev |
|
33 | 34 |
REGLOOKUP=reglookup |
34 | 35 |
CHNTPW=chntpw |
35 | 36 |
|
... | ... | |
97 | 98 |
fi |
98 | 99 |
} |
99 | 100 |
|
100 |
get_last_partition_id() { |
|
101 |
local dev="$1" |
|
102 |
if ! output="$("$PARTED" -s -m "$dev" print)"; then |
|
103 |
log_error "Unable to read partition table for device \`${dev}'" |
|
104 |
fi |
|
105 |
|
|
106 |
last_line=$(tail -1 <<< "$output") |
|
107 |
|
|
108 |
echo $(cut -d: -f1 <<< "$last_line") |
|
109 |
} |
|
110 | 101 |
|
111 | 102 |
get_partition_table() { |
112 | 103 |
local dev="$1" |
113 |
if ! output="$("$PARTED" -s -m "$dev" unit s print)"; then |
|
104 |
# If the partition table is gpt then parted will raise an error if the |
|
105 |
# secondary gpt is not it the end of the disk, and a warning that has to |
|
106 |
# do with the "Last Usable LBA" entry in gpt. |
|
107 |
if ! output="$("$PARTED" -s -m "$dev" unit s print | grep -E -v "^(Warning|Error): ")"; then |
|
114 | 108 |
log_error "Unable to read partition table for device \`${dev}'" |
115 | 109 |
fi |
116 | 110 |
|
... | ... | |
133 | 127 |
expr $(echo "$ptable" | wc -l) - 2 |
134 | 128 |
} |
135 | 129 |
|
136 |
get_partition_by_id() {
|
|
130 |
get_partition_by_num() {
|
|
137 | 131 |
local ptable="$1" |
138 | 132 |
local id="$2" |
139 | 133 |
|
... | ... | |
198 | 192 |
echo "" |
199 | 193 |
} |
200 | 194 |
|
195 |
get_partition_to_resize() { |
|
196 |
local dev="$1" |
|
197 |
|
|
198 |
table=$(get_partition_table "$dev") |
|
199 |
|
|
200 |
if [ $(get_partition_count "$table") -eq 0 ]; then |
|
201 |
return 0 |
|
202 |
fi |
|
203 |
|
|
204 |
table_type=$(get_partition_table_type "$table") |
|
205 |
last_part=$(get_last_partition "$table") |
|
206 |
last_part_num=$(cut -d: -f1 <<< "$last_part") |
|
207 |
|
|
208 |
if [ "$table_type" == "msdos" -a $last_part_num -gt 4 ]; then |
|
209 |
extended=$(get_extended_partition "$table") |
|
210 |
last_primary=$(get_last_primary_partition "$table") |
|
211 |
ext_num=$(cut -d: -f1 <<< "$extended") |
|
212 |
prim_num=$(cut -d: -f1 <<< "$last_primary") |
|
213 |
|
|
214 |
if [ "$ext_num" != "$last_prim_num" ]; then |
|
215 |
echo "$last_prim_num" |
|
216 |
else |
|
217 |
echo "$last_part_num" |
|
218 |
fi |
|
219 |
else |
|
220 |
echo "$last_part_num" |
|
221 |
fi |
|
222 |
} |
|
223 |
|
|
201 | 224 |
create_partition() { |
202 | 225 |
local device="$1" |
203 | 226 |
local part="$2" |
Also available in: Unified diff