From c3f3e627eac5f449ccec12dac2c1ca43c3b78d59 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Mon, 11 Sep 2017 14:42:19 -0400 Subject: [PATCH] Fix make_swap on rackspace Rackspace is now providing a partition table on /dev/xvde1, so check to see if a filesystem exists, and if now, delete it and rebuild. Import our logic from devstack-gate role to fix swap issues too. Change-Id: I81571489cab121159f48a9437a24388696db331c Signed-off-by: Paul Belanger --- make_swap.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/make_swap.sh b/make_swap.sh index b03be7c67f..2cee494ac6 100644 --- a/make_swap.sh +++ b/make_swap.sh @@ -23,15 +23,30 @@ if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then fi # Avoid using config drive device for swap - if [ -n "$DEV" ] && ! blkid | grep $DEV ; then + if [ -n "$DEV" ] && ! blkid | grep $DEV | grep TYPE ; then MEMKB=`grep MemTotal /proc/meminfo | awk '{print $2; }'` # Use the nearest power of two in MB as the swap size. # This ensures that the partitions below are aligned properly. MEM=`python -c "import math ; print 2**int(round(math.log($MEMKB/1024, 2)))"` - umount ${DEV} - parted ${DEV} --script -- mklabel msdos - parted ${DEV} --script -- mkpart primary linux-swap 1 ${MEM} - parted ${DEV} --script -- mkpart primary ext2 ${MEM} -1 + if mount | grep ${DEV} > /dev/null; then + echo "*** ${DEV} appears to already be mounted" + echo "*** ${DEV} unmounting and reformating" + umount ${DEV} + fi + + parted ${DEV} --script -- \ + mklabel msdos \ + mkpart primary linux-swap 1 ${MEM} \ + mkpart primary ext2 ${MEM} -1 + sync + # We are only interested in scanning $DEV, not all block devices + sudo partprobe ${DEV} + # The device partitions might not show up immediately, make sure + # they are ready and available for use + udevadm settle --timeout=0 || echo "Block device not ready yet. Waiting for up to 10 seconds for it to be ready" + udevadm settle --timeout=10 --exit-if-exists=${DEV}1 + udevadm settle --timeout=10 --exit-if-exists=${DEV}2 + mkswap ${DEV}1 mkfs.ext4 ${DEV}2 swapon ${DEV}1