Swap space with mounts module not working
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
The cloud config settings
# swap can also be set up by the 'mounts' module
# default is to not create any swap files, because 'size' is set to 0
swap:
filename: /swap.img
size: "auto" or size in bytes
maxsize: size in bytes
will not result in a swap space.
Some big questions are present with respect to the operational logic behind this cloud config setting:
a) which (underlying) command is used to create the swap space?
b) is being made use of sparse files? (not desirable for swap. Answer is probably "not", given "size: auto" option)
c) what are the requirements for creation of swap? (should a partition exist and/or should the partition type be 82. Answer is probably "no", given the fact that a swap file is created)
In essence, some problems encountered when creating swap manually (instead of using the swap config setting):
1) when creating a swap file on the ephemeral disk: mkswap does not work probably (error: ...should at least be 40Kib)
2) when creating a separate partition of type 83 (hence preventing mkswap errors):
- swap file (manually created) exists, but is not active as swap,
- swap file (using the swap config setting) does not exist,
3) when creating a swap partition (of type 82): swap is not active and/or not mounted (and swap file creation therefore fails)
Note the use of partitions is not desirable for swap purposes, the sole intent was to test for the causes of failure.
Finally, some additional documentation for creating swap space with cloud-config would be (very) desirable).
Kind regards....
Hi,
what version of cloud-init are you using?
This functionality is only availble in trunk since 2014-10-01. It is only in Ubuntu vivid and utopic, not in trusty.
That said, I just launched an instance with this config:
#cloud-config
swap:
size: auto
filename: /swap.img
maxsize: 8G
/var/log/ cloud-init. log says: 153256 [CLOUDINIT] cc_mounts. py[DEBUG] : suggest 8182 MB swap for 7984 MB memory with '9092 MB' disk given max=8192 MB [max=8182 MB]' 153256 [CLOUDINIT] util.py[DEBUG]: creating swap file '/swap.img' of 8182MB took 14.301 seconds
Jan 15 15:33:18 vivid-20150115-
Jan 15 15:33:32 vivid-20150115-
$ ls -lh /swap.img ; du /swap.img
-rw------- 1 root root 8.0G Jan 15 15:33 /swap.img
8378372 /swap.img
$ free
total used free shared buffers cached
Mem: 8176028 8009932 166096 308 9280 7680480
-/+ buffers/cache: 320172 7855856
Swap: 8378364 0 8378364
Launching another instance without the specified 'max' gives me: 154415 [CLOUDINIT] cc_mounts. py[DEBUG] : suggest 2273 MB swap for 7984 MB memory with '9092 MB' disk given max=None [max=2273 MB]'
Jan 15 15:44:41 vivid-20150115-
The algorithm for 'auto' is agreeably nebulus, but I feel that any algoritm is going to seem odd/broken for some set.