Skip to content

Commit 8157098

Browse files
committed
Fixed check for unallocated space on disk
So far the check for unallocated space was only working for GPT and there it was also not really stable. The check was based on verifying if the backup GPT table is really at the end of the disk. Depending on which tool was used to dump the image on the target this "mistake" often got corrected by the tools that dumped the image. In this case the check no longer worked. This commit improves the check by another test which looks for the real free bytes on disk compared to the current partition geometry.
1 parent 356a7b7 commit 8157098

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

dracut/modules.d/99kiwi-lib/kiwi-partitions-lib.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ function relocate_gpt_at_end_of_disk {
328328

329329
function disk_has_unallocated_space {
330330
local disk_device=$1
331+
local free_mbytes
331332
local pt_table_type
333+
local end="end of the disk"
332334
pt_table_type=$(get_partition_table_type "${disk_device}")
333335
if [ "${pt_table_type}" = "gpt" ];then
334336
# GPT disks store a backup table at the end of the disk
@@ -337,13 +339,20 @@ function disk_has_unallocated_space {
337339
# checked and used to detect that there is space
338340
# unallocated due to a geometry change of the underlying
339341
# block device layer
340-
sgdisk --verify "${disk_device}" 2>&1 | grep -q "end of the disk"
341-
else
342-
# There is currently no method we could come up with
343-
# to detect a geometry change for non GPT based disks.
344-
# Thus we assume it's not fully allocated and allow
345-
# for resize
342+
if sgdisk --verify "${disk_device}" 2>&1 | grep -q "${end}"; then
343+
return
344+
fi
345+
fi
346+
# lookup if there is free space on disk compared to
347+
# the current geometry values in the partition table
348+
free_mbytes=$(
349+
sfdisk --list-free "${disk_device}" |\
350+
grep -i Unpartitioned | cut -f2 -d, | grep -o -E '[0-9]+'
351+
)
352+
if [ "${free_mbytes}" != "0" ];then
346353
true
354+
else
355+
false
347356
fi
348357
}
349358

0 commit comments

Comments
 (0)