summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_mounts.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-08-12 12:51:39 -0400
committerScott Moser <smoser@ubuntu.com>2015-08-12 12:51:39 -0400
commit827b7b903abc07d5fb04591bbae5587e6dc44993 (patch)
tree021196d7ed01fc14705bce011bb3003c7ca44b99 /cloudinit/config/cc_mounts.py
parenta9c1e3f747ae69401ebfca9ae64eec1c6d20ebe7 (diff)
downloadvyos-cloud-init-827b7b903abc07d5fb04591bbae5587e6dc44993.tar.gz
vyos-cloud-init-827b7b903abc07d5fb04591bbae5587e6dc44993.zip
swap: create swap with fallocate if possible
fallocate is much faster than 'dd' for creating and initializing a swap file. LP: #1482994
Diffstat (limited to 'cloudinit/config/cc_mounts.py')
-rw-r--r--cloudinit/config/cc_mounts.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 73b42f91..47b63dfc 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -206,7 +206,8 @@ def setup_swapfile(fname, size=None, maxsize=None):
util.log_time(LOG.debug, msg, func=util.subp,
args=[['sh', '-c',
('rm -f "$1" && umask 0066 && '
- 'dd if=/dev/zero "of=$1" bs=1M "count=$2" && '
+ '{ fallocate -l "${2}M" "$1" || '
+ ' dd if=/dev/zero "of=$1" bs=1M "count=$2"; } && '
'mkswap "$1" || { r=$?; rm -f "$1"; exit $r; }'),
'setup_swap', fname, mbsize]])