cloud-init: Attempt to mkswap on a partition fails: invalid block count argument: ''

Bug #1862417 reported by Graham Leggett
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Invalid
Medium
Unassigned

Bug Description

If an attempt is made to configure a swap partition on an Ubuntu Bionic machine as follows (not a swap file, a swap partition), the attempt to mkswap fails.

The expected behaviour is that mkswap and swapon are executed correctly, and /dev/xvdg becomes a valid swap disk. In addition, when filename points at a partition, size and maxsize should be ignored.

fs_setup:
  - label: vidi
    device: /dev/xvde
    filesystem: ext4
  - label: swap
    device: /dev/xvdg
    filesystem: swap
mounts:
- [ /dev/xvde, /var/lib/vidispine, ext4, defaults, 0, 0 ]
- [ /dev/xvdg, none, swap, sw, 0, 0 ]
swap:
    filename: /dev/xvdg
    size: auto
    maxsize: 17179869184
mount_default_fields: [ None, None, "auto", "defaults", "0", "2" ]

When the machine starts up for the first time, the following error is logged after the swap size parameter is passed as the empty string:

2020-02-07 20:21:55,242 - cc_disk_setup.py[WARNING]: Force flag for swap is unknown.
2020-02-07 20:21:55,255 - util.py[WARNING]: Failed during filesystem operation
Failed to exec of '['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']':
Unexpected error while running command.
Command: ['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']
Exit code: 1
Reason: -
Stdout:
Stderr: mkswap: invalid block count argument: ''
2020-02-07 20:21:55,530 - cc_mounts.py[WARNING]: Activate mounts: FAIL:swapon -a
2020-02-07 20:21:55,530 - util.py[WARNING]: Activate mounts: FAIL:swapon -a

Revision history for this message
Chad Smith (chad.smith) wrote :

Please attach the tarfile of cloud-init collect-logs. and mention the version of cloud-init that is running.

Ryan Harper (raharper)
Changed in cloud-init:
importance: Undecided → Medium
status: New → Incomplete
Revision history for this message
Graham Leggett (minfrin) wrote :

Version is 19.4-33-gbb4131a2-0ubuntu1~18.04.1 from Ubuntu Bionic.

The full log is as follows:

2020-02-07 21:00:18,780 - cc_disk_setup.py[DEBUG]: Creating new filesystem.
2020-02-07 21:00:18,780 - util.py[DEBUG]: Running command ['udevadm', 'settle'] with allowed return codes [0] (shell=False, capture=True)
2020-02-07 21:00:18,798 - cc_disk_setup.py[DEBUG]: Checking /dev/xvdg against default devices
2020-02-07 21:00:18,798 - cc_disk_setup.py[DEBUG]: Identifying device to create swap filesytem on
2020-02-07 21:00:18,798 - util.py[DEBUG]: Running command ['/bin/lsblk', '--pairs', '--output', 'NAME,TYPE,FSTYPE,LABEL', '/dev/xvdg'] with allowed return codes [0] (shel
l=False, capture=True)
2020-02-07 21:00:18,802 - cc_disk_setup.py[DEBUG]: Automatic device for /dev/xvdg identified as /dev/xvdg
2020-02-07 21:00:18,802 - cc_disk_setup.py[DEBUG]: File system type 'swap' with label 'swap' will be created on /dev/xvdg
2020-02-07 21:00:18,803 - util.py[DEBUG]: Running command ['/bin/lsblk', '--pairs', '--output', 'NAME,TYPE,FSTYPE,LABEL', '/dev/xvdg', '--nodeps'] with allowed return cod
es [0] (shell=False, capture=True)
2020-02-07 21:00:18,806 - cc_disk_setup.py[WARNING]: Force flag for swap is unknown.
2020-02-07 21:00:18,806 - cc_disk_setup.py[DEBUG]: Creating file system swap on /dev/xvdg
2020-02-07 21:00:18,806 - cc_disk_setup.py[DEBUG]: Using cmd: ['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']
2020-02-07 21:00:18,806 - util.py[DEBUG]: Running command ['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', ''] with allowed return codes [0] (shell=False, capture=True)
2020-02-07 21:00:18,817 - util.py[DEBUG]: Creating fs for /dev/xvdg took 0.037 seconds
2020-02-07 21:00:18,817 - util.py[WARNING]: Failed during filesystem operation
Failed to exec of '['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']':
Unexpected error while running command.
Command: ['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']
Exit code: 1
Reason: -
Stdout:
Stderr: mkswap: invalid block count argument: ''
2020-02-07 21:00:18,822 - util.py[DEBUG]: Failed during filesystem operation
Failed to exec of '['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']':
Unexpected error while running command.
Command: ['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']
Exit code: 1
Reason: -
Stdout:
Stderr: mkswap: invalid block count argument: ''
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py", line 994, in mkfs
    util.subp(fs_cmd, shell=shell)
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2065, in subp
    cmd=args)
cloudinit.util.ProcessExecutionError: Unexpected error while running command.
Command: ['/sbin/mkswap', '/dev/xvdg', '-L', 'swap', '']
Exit code: 1
Reason: -
Stdout:
Stderr: mkswap: invalid block count argument: ''

Revision history for this message
Ryan Harper (raharper) wrote :

Could you please attach the tarball created from running:

cloud-init collect-logs

This collects all of the cloud-init metadata and logs that are used during boot; that way we don't have to keep asking for additional logs from different places.

Revision history for this message
Graham Leggett (minfrin) wrote :

Looks like this bug was fixed in https://github.com/canonical/cloud-init/pull/143

Revision history for this message
Ryan Harper (raharper) wrote :

With some more debugging, the base image was older than when this fix went into upstream

https://github.com/canonical/cloud-init/pull/143/files

On current images, the following cloud-config is successful (I removed the swap: config):

#cloud-config
fs_setup:
  - label: vidi
    device: /dev/vdb
    filesystem: ext4
  - label: swap
    device: /dev/vdc
    filesystem: swap

mounts:
- [ /dev/vdb, /var/lib/vidispine, ext4, defaults, 0, 0 ]
- [ /dev/vdc, none, swap, sw, 0, 0 ]

mount_default_fields: [ None, None, "auto", "defaults", "0", "2" ]

----

ubuntu@test-mkswap:~$ cat /etc/fstab
LABEL=cloudimg-rootfs / ext4 defaults 0 0
LABEL=UEFI /boot/efi vfat defaults 0 0
/dev/vdb /var/lib/vidispine ext4 defaults,comment=cloudconfig 0 0
/dev/vdc none swap sw,comment=cloudconfig 0 0
ubuntu@test-mkswap:~$ cat /proc/swaps
Filename Type Size Used Priority
/dev/vdc partition 41943036 0 -2
ubuntu@test-mkswap:~$ grep mkswap /var/log/cloud-init.log
2020-02-07 21:42:01,154 - cc_set_hostname.py[DEBUG]: Setting the hostname to test-mkswap.novalocal (test-mkswap)
2020-02-07 21:42:01,155 - __init__.py[DEBUG]: Non-persistently setting the system hostname to test-mkswap
2020-02-07 21:42:01,155 - util.py[DEBUG]: Running command ['hostname', 'test-mkswap'] with allowed return codes [0] (shell=False, capture=True)
2020-02-07 21:42:04,373 - cc_disk_setup.py[DEBUG]: Using cmd: ['/sbin/mkswap', '/dev/vdc', '-L', 'swap']
2020-02-07 21:42:04,373 - util.py[DEBUG]: Running command ['/sbin/mkswap', '/dev/vdc', '-L', 'swap'] with allowed return codes [0] (shell=False, capture=True)
2020-02-07 21:42:04,712 - cc_update_hostname.py[DEBUG]: Updating hostname to test-mkswap.novalocal (test-mkswap)
2020-02-07 21:42:04,712 - __init__.py[DEBUG]: Attempting to update hostname to test-mkswap in 1 files

Revision history for this message
Ryan Harper (raharper) wrote :

<minfrin> The machine I'm working on uses cloud-init to update itself, it might only have the fix after the updates.
<rharper> ah, interesting
<rharper> cat /etc/cloud/build.info
<rharper> that'll give us a point in time for which version you have
<rharper> and I suspect you're right, the top of your cloud-init.log will the original version
<minfrin> build_name: serverserial: 20190514
<minfrin> Definitely way older than the PR.
<rharper> yep
<minfrin> I suspect the fix in our case is to use the latest image of Ubuntu from end Jan 2020.
<rharper> yep

Changed in cloud-init:
status: Incomplete → Invalid
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.