The swapfile on the Btrfs file system is not activated

Bug #1818811 reported by Emanuele on 2019-03-06
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Undecided
Unassigned
ubiquity (Ubuntu)
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

Emanuele (emanuc) wrote :
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

This change was made by a bot.

Changed in linux (Ubuntu):
status: New → Confirmed
Kai-Heng Feng (kaihengfeng) wrote :

Does "sudo chattr +C /swapfile" help?

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.

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

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
Emanuele (emanuc) wrote :

Now it works, swapfile will activate and work.

Emanuele (emanuc) wrote :

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

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

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.

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.

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.

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.

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

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

Other bug subscribers