Merge "Better swap alignment"

This commit is contained in:
Zuul 2021-10-27 22:20:30 +00:00 committed by Gerrit Code Review
commit 5c08804102
1 changed files with 4 additions and 2 deletions

View File

@ -24,8 +24,10 @@ if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then
SWAPFILE=/swapfile
MEMKB=`grep MemTotal /proc/meminfo | awk '{print $2; }'`
# Use the nearest power of two in MB as the swap size.
# We also shift by 8MB to start the partitions as apparently
# parted and linux prefer things aligned on multiples of 8.
# This ensures that the partitions below are aligned properly.
MEM=`python3 -c "import math ; print(min(2**int(round(math.log($MEMKB/1024, 2))),8192))"`
MEM=`python3 -c "import math ; print(min(2**int(round(math.log($MEMKB/1024, 2))),8192) + 8)"`
# Avoid using config drive device for swap
if [ -n "$DEV" ] && ! blkid | grep $DEV | grep TYPE ; then
@ -37,7 +39,7 @@ if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then
parted ${DEV} --script -- \
mklabel msdos \
mkpart primary linux-swap 1 ${MEM} \
mkpart primary linux-swap 8 ${MEM} \
mkpart primary ext2 ${MEM} -1
sync
# We are only interested in scanning $DEV, not all block devices