The swapfile on the Btrfs file system is not activated

Bug #1818811 reported by Emanuele
46
This bug affects 9 people
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Invalid
Undecided
Unassigned
partman-swapfile (Ubuntu)
Confirmed
Undecided
Unassigned
ubiquity (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

From 5.0 kernel is implemented support for the swapfile on Btrfs (https://patchwork.kernel.org/cover/10584515/), today arrived on the repositories of Ubuntu 19.04 proposed kernel 5.0, but the swapfile is not activated.

Log:

mar 06 11:17:55 notebook-Lenovo-V110 kernel: BTRFS warning (device sda1): swapfile must not be copy-on-write
mar 06 11:17:55 notebook-Lenovo-V110 swapon[517]: swapon: /swapfile: swapon failed: Argomento non valido
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: Activating swap /swapfile...
mar 06 11:17:57 notebook-Lenovo-V110 swapon[916]: swapon: /swapfile: swapon failed: Argomento non valido
mar 06 11:17:57 notebook-Lenovo-V110 kernel: BTRFS warning (device sda1): swapfile must not be copy-on-write
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: swapfile.swap: Swap process exited, code=exited, status=255/EXCEPTION
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: swapfile.swap: Failed with result 'exit-code'.
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: Failed to activate swap /swapfile.
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: Activating swap /swapfile...
mar 06 11:17:57 notebook-Lenovo-V110 kernel: BTRFS warning (device sda1): swapfile must not be copy-on-write
mar 06 11:17:57 notebook-Lenovo-V110 swapon[1006]: swapon: /swapfile: swapon failed: Argomento non valido
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: swapfile.swap: Swap process exited, code=exited, status=255/EXCEPTION
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: swapfile.swap: Failed with result 'exit-code'.
mar 06 11:17:57 notebook-Lenovo-V110 systemd[1]: Failed to activate swap /swapfile.

ProblemType: Bug
DistroRelease: Ubuntu 19.04
Package: linux-image-generic 5.0.0.7.8
ProcVersionSignature: Ubuntu 5.0.0-7.8-generic 5.0.0
Uname: Linux 5.0.0-7-generic x86_64
ApportVersion: 2.20.10-0ubuntu23
Architecture: amd64
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: emanu 1744 F.... pulseaudio
CurrentDesktop: ubuntu:GNOME
Date: Wed Mar 6 11:19:52 2019
InstallationDate: Installed on 2019-01-30 (34 days ago)
InstallationMedia: Kubuntu 19.04 "Disco Dingo" - Alpha amd64 (20190130)
Lsusb:
 Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
 Bus 001 Device 005: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
 Bus 001 Device 003: ID 13d3:5745 IMC Networks
 Bus 001 Device 002: ID 10c4:8105 Cygnal Integrated Products, Inc.
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
MachineType: LENOVO 80TL
ProcEnviron:
 TERM=screen-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=it_IT.UTF-8
 SHELL=/bin/bash
ProcFB: 0 inteldrmfb
ProcKernelCmdLine: BOOT_IMAGE=/@/boot/vmlinuz-5.0.0-7-generic root=UUID=91fdf6c0-1b5d-4bb5-9aa4-aeb946236b8a ro rootflags=subvol=@ quiet splash vt.handoff=1
RelatedPackageVersions:
 linux-restricted-modules-5.0.0-7-generic N/A
 linux-backports-modules-5.0.0-7-generic N/A
 linux-firmware 1.177
SourcePackage: linux
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 10/29/2018
dmi.bios.vendor: LENOVO
dmi.bios.version: 1KCN46WW
dmi.board.asset.tag: No Asset Tag
dmi.board.name: LNVNB161216
dmi.board.vendor: LENOVO
dmi.board.version: SDK0J40700 WIN
dmi.chassis.asset.tag: No Asset Tag
dmi.chassis.type: 10
dmi.chassis.vendor: LENOVO
dmi.chassis.version: Lenovo V110-15ISK
dmi.modalias: dmi:bvnLENOVO:bvr1KCN46WW:bd10/29/2018:svnLENOVO:pn80TL:pvrLenovoV110-15ISK:rvnLENOVO:rnLNVNB161216:rvrSDK0J40700WIN:cvnLENOVO:ct10:cvrLenovoV110-15ISK:
dmi.product.family: V110-15ISK
dmi.product.name: 80TL
dmi.product.sku: LENOVO_MT_80TL_BU_idea_FM_V110-15ISK
dmi.product.version: Lenovo V110-15ISK
dmi.sys.vendor: LENOVO

Revision history for this message
Emanuele (emanuc) wrote :
Revision history for this message
Emanuele (emanuc) wrote :

I forgot to mention that the swapfile was created during the installation of Ubuntu 19.04, not selecting any swap partition, knowing that the swapfile would be activated and that the support would be shortly arrived for the swapfile, on the 5. * kernel

Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote : Status changed to Confirmed

This change was made by a bot.

Changed in linux (Ubuntu):
status: New → Confirmed
Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :

Does "sudo chattr +C /swapfile" help?

Revision history for this message
Emanuele (emanuc) wrote :

Unfortunately it doesn't help.

mar 29 12:01:18 notebook-Lenovo-V110 sudo[11977]: emanu : TTY=pts/1 ; PWD=/home/emanu ; USER=root ; COMMAND=/usr/bin/chattr +C /swapfile
mar 29 12:02:20 notebook-Lenovo-V110 kernel: BTRFS warning (device sda1): swapfile must not be copy-on-write
mar 29 12:02:20 notebook-Lenovo-V110 swapon[538]: swapon: /swapfile: swapon failed: Argomento non valido
mar 29 12:02:22 notebook-Lenovo-V110 systemd[1]: Activating swap /swapfile...
mar 29 12:02:22 notebook-Lenovo-V110 swapon[1059]: swapon: /swapfile: swapon failed: Argomento non valido
mar 29 12:02:22 notebook-Lenovo-V110 kernel: BTRFS warning (device sda1): swapfile must not be copy-on-write
mar 29 12:02:22 notebook-Lenovo-V110 systemd[1]: swapfile.swap: Swap process exited, code=exited, status=255/EXCEPTION
mar 29 12:02:22 notebook-Lenovo-V110 systemd[1]: swapfile.swap: Failed with result 'exit-code'.
mar 29 12:02:22 notebook-Lenovo-V110 systemd[1]: Failed to activate swap /swapfile.

Revision history for this message
Emanuele (emanuc) wrote :

I don't know if it's useful, but I paste my "/etc/fstab" configuration

$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during installation
UUID=b383c3a8-39dd-4edd-98e1-0217a87d266a / btrfs defaults,noatime,compress=lzo,autodefrag,subvol=@ 0 1
# /boot/efi was on /dev/sda1 during installation
UUID=76C5-B080 /boot/efi vfat umask=0077 0 1
# /home was on /dev/sda2 during installation
UUID=b383c3a8-39dd-4edd-98e1-0217a87d266a /home btrfs defaults,noatime,compress=lzo,autodefrag,subvol=@home 0 2
/swapfile none swap sw 0 0
LABEL=dati1 /media/emanu/dati btrfs defaults,compress=zstd,autodefrag 0 3
LABEL=backup /media/emanu/backup btrfs defaults,compress-force=zstd,autodefrag,nofail,noauto 0 0

Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :

So the swapfile needs to be NOCOW before allocation [1]:
# truncate -s 0 /swapfile
# chattr +C /swapfile
# fallocate -l 512M /swapfile

We should make the installer use these steps instead.

[1] https://wiki.archlinux.org/index.php/Swap#Swap_file_creation

Changed in linux (Ubuntu):
status: Confirmed → Invalid
Revision history for this message
Emanuele (emanuc) wrote :

Now it works, swapfile will activate and work.

Revision history for this message
Emanuele (emanuc) wrote :

Hello. Are there any news? Will it be correct for the 20.04 LTS release?

Revision history for this message
Emanuele (emanuc) wrote :

I tried to make it work, doing a Ubuntu ISO chroot (I used Cubic software), I saw the part where the Btrfs subvolts are created and tried to modify them, obviously not having the skills in an advanced way, I'm not managed to make it work.

I ran it manually after installation:
mount -t btrfs -o options /dev/sda1 /mnt
btrfs subvol create /mnt/@swapfile
chattr +C /mnt/@swapfile

then I created the swapfile inside the subvol "@swapfile":
fallocate -l 512M /mnt/@swapfile/swapfile
chmod 600 /mnt/@swapfile/swapfile
chattr +C /mnt/@swapfile/swapfile

Then I edit fstab:
UUID=b383c3a8-39dd-4edd-98e1-0217a87d266a /swap btrfs defaults,subvol=@swap 0 0
/swap/swapfile none swap sw 0 0

Are these the files to make these changes?
/usr/lib/partman/mount.d/70btrfs
/usr/lib/partman/mount.d/70btrfs
/usr/lib/partman/finish.d

Revision history for this message
Emanuele (emanuc) wrote :

Hello. I finally managed to work and locate the files and the code to change to make the swapfile work on Btrfs, I have tested it on several installations for a few months and the swapfile is created both if you choose ext4 or btrfs.
I'm not a developer, so I don't know if the changes are correct and in style.
Hope it helps.

Revision history for this message
Emanuele (emanuc) wrote :

Hello. I finally managed to work and locate the files and the code to change to make the swapfile work on Btrfs, I have tested it on several installations for a few months and the swapfile is created both if you choose ext4 or btrfs.
I'm not a developer, so I don't know if the changes are correct and in style.
Hope it helps.

Revision history for this message
Emanuele (emanuc) wrote :

Hello. I finally managed to work and locate the files and the code to change to make the swapfile work on Btrfs, I have tested it on several installations for a few months and the swapfile is created both if you choose ext4 or btrfs.
I'm not a developer, so I don't know if the changes are correct and in style.
Hope it helps.

Revision history for this message
Emanuele (emanuc) wrote :

Hello. I finally managed to work and locate the files and the code to change to make the swapfile work on Btrfs, I have tested it on several installations for a few months and the swapfile is created both if you choose ext4 or btrfs.
I'm not a developer, so I don't know if the changes are correct and in style.
Hope it helps.

Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :

Thanks for your work.
Can you please open a merge request at [1]? Thanks!

[1]https://salsa.debian.org/installer-team/partman-swapfile

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in ubiquity (Ubuntu):
status: New → Confirmed
Revision history for this message
Norbert (nrbrtx) wrote :

Latest Ubuntu MATE 21.10 20210812 - btrfs rootfs, swapfile is not attached (output of `swapon -s` is empty).

tags: added: impish iso-testing
removed: disco
Revision history for this message
Dawid M. (dawid.mlyn) wrote :

This bug still remains in the latest Xubuntu CORE 22.04 (xubuntu-22.04-core-amd64.iso from the end of Feb 2022). During boot process, I can briefly see "[FAILED] Failed to activate swap /swapfile" and "[DEPEND] Dependency failed for Swaps". When I execute "sudo dmesg | grep -i swap", I get some more BTRFS warnings and swap-related failures:

[ 4.121985] systemd[1]: Activating swap /swapfile...
[ 4.136293] BTRFS warning (device sda6): swapfile must not be copy-on-write
[ 4.160578] systemd[1]: swapfile.swap: Swap process exited, code=exited, status=255/EXCEPTION
[ 4.160586] systemd[1]: swapfile.swap: Failed with result 'exit-code'.
[ 4.161012] systemd[1]: Failed to activate swap /swapfile.
[ 4.161100] systemd[1]: Dependency failed for Swaps.
[ 4.161145] systemd[1]: swap.target: Job swap.target/start failed with result 'dependency'.
[ 6.902501] BTRFS warning (device sda6): swapfile must not be copy-on-write

Revision history for this message
Norbert (nrbrtx) wrote :

What do you actually mean by "xubuntu-22.04-core-amd64.iso"? Is it official daily image?

tags: added: jammy
no longer affects: ubuntu-mate
Changed in ubiquity (Ubuntu):
status: Confirmed → Invalid
Changed in partman-swapfile (Ubuntu):
status: New → Confirmed
Revision history for this message
amano (jyaku) wrote (last edit ):

I can confirm that with the proper Ubuntu 22.04 Beta on baremetal. I get the error message on bootup. Is there a workaround?

(output of `swapon -s` is empty).

15:41:11 systemd-oomd: Swap is currently not detected; memory pressure usage will be degraded
15:41:11 systemd: swap.target: Job swap.target/start failed with result 'dependency'.
15:41:11 systemd: swap.target: Job swap.target/start failed with result 'dependency'.
15:41:11 systemd: Dependency failed for Swaps.
15:41:11 systemd: Failed to activate swap /swapfile.
15:41:11 systemd: swapfile.swap: Failed with result 'exit-code'.
15:41:11 systemd: swapfile.swap: Swap process exited, code=exited, status=255/EXCEPTION
15:41:11 kernel: BTRFS warning (device nvme0n1p2): swapfile must not be copy-on-write
15:41:11 swapon: swapon: /swapfile: swapon fehlgeschlagen: Das Argument ist ungültig
15:41:11 systemd: Activating swap /swapfile...
15:41:10 kernel: swapon: /swapfile: swapon fehlgeschlagen: Das Argument ist ungültig
15:41:10 kernel: swap.target: Job swap.target/start failed with result 'dependency'.
15:41:10 kernel: Dependency failed for Swaps.
15:41:10 kernel: Failed to activate swap /swapfile.
15:41:10 kernel: swapfile.swap: Failed with result 'exit-code'.
15:41:10 kernel: BTRFS warning (device nvme0n1p2): swapfile must not be copy-on-write
15:41:10 kernel: Activating swap /swapfile...
15:41:10 kernel: zswap: loaded using pool lzo/zbud

Fixed that by:
# truncate -s 0 /swapfile
# chattr +C /swapfile
# btrfs property set /swapfile compression none
# fallocate -l 512M /swapfile
# chmod 600 /swapfile
# mkswap /swapfile

Now swapon /swapfile should succeed.

Revision history for this message
Andre Ruiz (andre-ruiz) wrote :

The problem is that a swapfile in btrfs cannot have CoW activated on the file, and cannot be compressed. Also, you should not leave the file in the root filesystem (even if it would work with the above settings) because it will make snapshots of /@ messy.

If you manually do this, it will work:

- create a separate subvolume just for swap
- mount it somewhere like /swap (also add to fstab)
- create an empty file (/swap/swapfile)
- set non-compress and no-CoW on the file
- grow the file to the desired size
- mkswap on the file
- add swap file to fstab

now you can swapon -a and it will work.

The installer does not do that, it just creates a /swapfile as it would do on any other filesystem and then on reboot it will not start.

Amano instructions above will work, but I would advise to also create the subvolume.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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