From 6dc70731014f1ff3da0525e8cdadbdf9a88ee23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Wed, 28 Feb 2018 10:47:29 +0100 Subject: [PATCH] Fixed get_free_disk_bytes in dracut kiwi-lib The method used any device from the lsblk output, but it can happen that some device nodes with different name point to the same physical device. The method would then calculate the free space wrong. This patch takes the PARTUUID value into account to make sure any partition device size is used only once. This Fixes #648 --- .../99kiwi-lib/kiwi-partitions-lib.sh | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/dracut/modules.d/99kiwi-lib/kiwi-partitions-lib.sh b/dracut/modules.d/99kiwi-lib/kiwi-partitions-lib.sh index bfb71555..a5d8bfbd 100644 --- a/dracut/modules.d/99kiwi-lib/kiwi-partitions-lib.sh +++ b/dracut/modules.d/99kiwi-lib/kiwi-partitions-lib.sh @@ -267,10 +267,26 @@ function get_free_disk_bytes { local rest_bytes rest_bytes=${disk_bytes} local part_bytes=0 + local part_count=0 + local part_uuids for part in $( lsblk -p -r -o NAME,TYPE "${disk}" | grep part | cut -f1 -d ' ' );do - part_bytes=$((part_bytes + $(blockdev --getsize64 "${part}"))) + current_part_uuid=$(get_partition_uuid "${part}") + for part_uuid in ${part_uuids[*]};do + if [ "${current_part_uuid}" = "${part_uuid}" ];then + # this partition uuid was already handled. The device + # node is pointing to the same physical device and + # should only be taken into account once + unset part + break + fi + done + if [ ! -z "${part}" ]; then + part_bytes=$((part_bytes + $(blockdev --getsize64 "${part}"))) + part_uuids[${part_count}]=${current_part_uuid} + part_count=$((part_count + 1)) + fi done rest_bytes=$((rest_bytes - part_bytes)) echo ${rest_bytes} @@ -280,6 +296,10 @@ function get_partition_table_type { blkid -s PTTYPE -o value "$1" } +function get_partition_uuid { + blkid -s PARTUUID -o value "$1" +} + function relocate_gpt_at_end_of_disk { local cmd local cmd_file=/part.input