I thought this was the best place to discuss, instead of doing it on the bug report, I hope I wasn’t wrong.
Hello.
As said on bugreport [1], I’m not a developer, it’s the first time I try to write a patch, unfortunately I don’t know how to do it.
Surely the code is not perfect, is there anyone who can help complete, revise and improve the code?
Mainly the changes are:
- If you choose btrfs, the code to detect the partition does not work, with the help of friends on Telegram I managed to improve the codide and now it perfectly detects Btrfs and ext4 [2].
- I create a nested subvolume (avoid mounting on /etc/fstab) [3] before activating the swap, to avoid carrying the swapfile if using snapshots, then I set the nocow [4] flag on the subvolume.
- I created ifs, if it reveals btrfs it points to the subvolume folder.
I tried the change in VM on Ubuntu 20.04, first with btrfs, then with ext4, the swpafile is created correctly on both installations
[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1818811
[2]
rootfstype=$(df -T /target | grep /target | awk ‘{print $2}’)
[3] https://www.spinics.net/lists/linux-btrfs/msg103190.html
https://www.spinics.net/lists/linux-btrfs/msg103213.html
btrfs subvolume create /target/swap
[4] chattr + C /target/swap
For a complete view of the code:
patch: 25create_swapfile
patch: 45fstab_swapfile