create_swap do not fallback to dd when fallocate fails

Bug #1897099 reported by Evaggelos Balaskas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Undecided
Dan Watkins

Bug Description

Name : cloud-init
Version : 20.2-1

Code in questioning: cloudinit/config/cc_mounts.py

        try:
            create_swap(fname, size, "fallocate")
        except util.ProcessExecutionError as e:
            LOG.warning(errmsg, fname, size, "dd", e)
            LOG.warning("Will attempt with dd.")
            create_swap(fname, size, "dd")

as there is a kernel bug in latest's linux versions, fallocate creates swap images with holes.
The workaround is to move fallocate (make create_swap function to fail) so that cloud-init will fallback to dd.

Used bootcmd (or cloud-boothook) to rename (move) fallocate binary from my system but according the the logs, it didnt fallback to dd as it should. Probably the error was not ProcessExecutionError

Logs:

/var/log/cloud-init-output.log:2020-09-24 09:13:16,470 - cc_mounts.py[WARNING]: Failed to create swapfile '/swapfile' of size 2048MB via fallocate: Unexpected
 error while running command.
/var/log/cloud-init-output.log:Command: ['fallocate', '-l', '2048M', '/swapfile']
/var/log/cloud-init-output.log:Reason: [Errno 2] No such file or directory: b'fallocate'
/var/log/cloud-init-output.log:2020-09-24 09:13:16,479 - cc_mounts.py[WARNING]: failed to setup swap: [Errno 2] No such file or directory: '/swapfile'
/var/log/cloud-init-output.log:chmod: cannot access '/usr/bin/fallocate': No such file or directory
/var/log/cloud-init.log:2020-09-24 09:13:16,460 - cc_mounts.py[DEBUG]: Attempting to determine the real name of swap
/var/log/cloud-init.log:2020-09-24 09:13:16,460 - cc_mounts.py[DEBUG]: changed default device swap => None
/var/log/cloud-init.log:2020-09-24 09:13:16,460 - cc_mounts.py[DEBUG]: Ignoring nonexistent default named mount swap
/var/log/cloud-init.log:2020-09-24 09:13:16,461 - cc_mounts.py[DEBUG]: suggest 2048.0 MB swap for 1983.953125 MB memory with '9030.296875 MB' disk given max=2048.0 MB [max=2048.0 MB]'
/var/log/cloud-init.log:2020-09-24 09:13:16,461 - cc_mounts.py[DEBUG]: Creating swapfile in '/swapfile' on fstype 'ext4' using 'fallocate'
/var/log/cloud-init.log:2020-09-24 09:13:16,461 - util.py[DEBUG]: Running command ['fallocate', '-l', '2048M', '/swapfile'] with allowed return codes [0] (she
ll=False, capture=True)
/var/log/cloud-init.log:2020-09-24 09:13:16,470 - cc_mounts.py[WARNING]: Failed to create swapfile '/swapfile' of size 2048MB via fallocate: Unexpected error while running command.
/var/log/cloud-init.log:Command: ['fallocate', '-l', '2048M', '/swapfile']
/var/log/cloud-init.log:Reason: [Errno 2] No such file or directory: b'fallocate'
/var/log/cloud-init.log:2020-09-24 09:13:16,479 - util.py[DEBUG]: Attempting to remove /swapfile
/var/log/cloud-init.log:2020-09-24 09:13:16,479 - util.py[DEBUG]: Setting up swap file took 0.019 seconds
/var/log/cloud-init.log:2020-09-24 09:13:16,479 - cc_mounts.py[WARNING]: failed to setup swap: [Errno 2] No such file or directory: '/swapfile'

Tags: fallocate swap
Dan Watkins (oddbloke)
Changed in cloud-init:
assignee: nobody → Dan Watkins (oddbloke)
status: New → In Progress
Revision history for this message
Chad Smith (chad.smith) wrote : Fixed in cloud-init version 20.4.

This bug is believed to be fixed in cloud-init in version 20.4. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: In Progress → Fix Released
Revision history for this message
Evaggelos Balaskas (ebal) wrote :

I can confirm via archlinux as 20.04 isnt yet in ubuntu

I consider this bug fixed and closed !

thanks

$ grep swap /var/log/cloud-init.log
2020-12-25 08:38:14,611 - cc_mounts.py[DEBUG]: Attempting to determine the real name of swap
2020-12-25 08:38:14,611 - cc_mounts.py[DEBUG]: changed default device swap => None
2020-12-25 08:38:14,611 - cc_mounts.py[DEBUG]: Ignoring nonexistent default named mount swap
2020-12-25 08:38:14,612 - cc_mounts.py[DEBUG]: suggest 2048.0 MB swap for 1983.93359375 MB memory with '9078.94921875 MB' disk given max=2048.0 MB [max=2048.0 MB]'
2020-12-25 08:38:14,612 - cc_mounts.py[DEBUG]: Creating swapfile in '/swapfile' on fstype 'ext4' using 'fallocate'
2020-12-25 08:38:14,612 - subp.py[DEBUG]: Running command ['fallocate', '-l', '2048M', '/swapfile'] with allowed return codes [0] (shell=False, capture=True)
2020-12-25 08:38:14,616 - cc_mounts.py[INFO]: Failed to create swapfile '/swapfile' of size 2048MB via fallocate: Unexpected error while running command.
Command: ['fallocate', '-l', '2048M', '/swapfile']
2020-12-25 08:38:14,616 - util.py[DEBUG]: Attempting to remove /swapfile
2020-12-25 08:38:14,616 - cc_mounts.py[INFO]: fallocate swap creation failed, will attempt with dd
2020-12-25 08:38:14,616 - cc_mounts.py[DEBUG]: Creating swapfile in '/swapfile' on fstype 'ext4' using 'dd'
2020-12-25 08:38:14,616 - subp.py[DEBUG]: Running command ['dd', 'if=/dev/zero', 'of=/swapfile', 'bs=1M', 'count=2048'] with allowed return codes [0] (shell=False, capture=True)
2020-12-25 08:38:34,284 - subp.py[DEBUG]: Running command ['mkswap', '/swapfile'] with allowed return codes [0] (shell=False, capture=True)
2020-12-25 08:38:42,346 - util.py[DEBUG]: Setting up swap file took 27.734 seconds
2020-12-25 08:38:42,350 - cc_mounts.py[DEBUG]: Changes to fstab: ['+ /swapfile none swap sw,comment=cloudconfig 0 0']
2020-12-25 08:38:42,350 - subp.py[DEBUG]: Running command ['swapon', '-a'] with allowed return codes [0] (shell=False, capture=True)
2020-12-25 08:38:42,387 - cc_mounts.py[DEBUG]: Activate mounts: PASS:swapon -a

$ pacman -Qi cloud-init
Name : cloud-init
Version : 20.4-1
Description : The standard for customising cloud instances
Architecture : any
URL : https://cloud-init.io
Licenses : GPL3

Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.