From f9f1ec7de4c4d2daccf5b9cfab0e324245b86ac8 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 12 Jan 2023 10:50:47 +0100 Subject: [PATCH] Fix swap.sh (#3897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script used to compare “10M” with “10” as if they were both integers. Signed-off-by: David Gageot Signed-off-by: David Gageot --- pkg/swap/swap.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/swap/swap.sh b/pkg/swap/swap.sh index 1bf9dc458..52383e8a9 100755 --- a/pkg/swap/swap.sh +++ b/pkg/swap/swap.sh @@ -121,11 +121,13 @@ else SWAPDEV=$path fi -if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $(disksize_to_count 1 $size) ]; then +count="$(disksize_to_count 1 $size)" + +if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $count ]; then ## Allocate the file ## If possible use a large blocksize: bs=1048576 # 1 MiB - if [ "$size" -lt "$bs" ]; then + if [ "$count" -lt "$bs" ]; then bs=1024 # fall back to 1KiB fi dd if=/dev/zero of=$path bs=$bs count=$(disksize_to_count $bs $size)