Skip to content

Commit bba855c

Browse files
author
David Moreau Simard
committed
Use a sparse swapfile on rootfs for providers without ephemeral disks
This will allow to normalize virtual machines to all have 8GB of swap. Change-Id: I5b56ec87780fb27834acfd72567f303183ad6464
1 parent 729ce79 commit bba855c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

functions.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,13 @@ function fix_etc_hosts {
314314
}
315315

316316
function fix_disk_layout {
317-
# HPCloud and Rackspace performance nodes provide no swap, but do
318-
# have ephemeral disks we can use. HPCloud also doesn't have
319-
# enough space on / for two devstack installs, so we partition the
320-
# disk and mount it on /opt, syncing the previous contents of /opt
321-
# over.
317+
# HPCloud and Rackspace performance nodes provide no swap, but do have
318+
# ephemeral disks we can use. For providers with no ephemeral disks, such
319+
# as OVH or Internap, create and use a sparse swapfile on the root
320+
# filesystem.
321+
# HPCloud also doesn't have enough space on / for two devstack installs,
322+
# so we partition the disk and mount it on /opt, syncing the previous
323+
# contents of /opt over.
322324
if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then
323325
if [ -b /dev/xvde ]; then
324326
DEV='/dev/xvde'
@@ -329,6 +331,7 @@ function fix_disk_layout {
329331
fi
330332
fi
331333
if [ -n "$DEV" ]; then
334+
# If an ephemeral device is available, use it
332335
local swap=${DEV}1
333336
local lvmvol=${DEV}2
334337
local optdev=${DEV}3
@@ -347,6 +350,14 @@ function fix_disk_layout {
347350
sudo find /opt/ -mindepth 1 -maxdepth 1 -exec mv {} /mnt/ \;
348351
sudo umount /mnt
349352
sudo mount ${DEV}2 /opt
353+
else
354+
# If no ephemeral devices are available, use root filesystem
355+
local lodevice=$(sudo losetup -f)
356+
local swapfile='/root/swapfile'
357+
sudo dd if=/dev/zero of=${swapfile} bs=1 count=0 seek=8G
358+
sudo mkswap ${swapfile}
359+
sudo losetup ${lodevice} ${swapfile}
360+
sudo swapon ${lodevice}
350361
fi
351362
fi
352363

0 commit comments

Comments
 (0)