The swap file created during install, when deleted, is recovered after reboot.
I did a clean install of Ubuntu 22.04 64-bit Desktop on a Raspberry Pi 4 8 GB using a Kingston 960 GB SSD. Added a swap partition and deleted the swap file. When I reboot, the swap file is back. Something is recovering the deleted swap file.
root@RPi:~# free
total used free shared buff/cache available
Mem: 7994256 832340 4953420 425556 2208496 6480364
Swap: 13631824 0 13631824
root@RPi:~# swapon
NAME TYPE SIZE USED PRIO
/dev/sda4 partition 12G 0B -2
/swapfile file 1024M 0B -3
root@RPi:~# swapoff -av
swapoff /swapfile
swapoff /dev/sda4
root@RPi:~# free
total used free shared buff/cache available
Mem: 7994256 848096 4925720 433404 2220440 6455352
Swap: 0 0 0
root@RPi:~# swapon -av
swapon: /dev/sda4: found signature [pagesize=4096, signature=swap]
swapon: /dev/sda4: pagesize=4096, swapsize=12885254144, devsize=12885254144
swapon /dev/sda4
root@RPi:~# free
total used free shared buff/cache available
Mem: 7994256 850320 4923016 433812 2220920 6452704
Swap: 12583252 0 12583252
root@RPi:~# ll /swapfile
-rw------- 1 root root 1073741824 Jul 1 22:37 /swapfile
root@RPi:~# rm -v /swapfile
removed '/swapfile'
root@RPi:~# ll /swapfile
ls: cannot access '/swapfile': No such file or directory
root@RPi:~#
reboot
root@RPi:~# free
total used free shared buff/cache available
Mem: 7994256 889208 4879004 434496 2226044 6414208
Swap: 13631824 0 13631824
root@RPi:~# swapon
NAME TYPE SIZE USED PRIO
/dev/sda4 partition 12G 0B -2
/swapfile file 1024M 0B -3
root@RPi:~# ll /swapfile
-rw------- 1 root root 1073741824 Jul 1 22:37 /swapfile
root@RPi:~#
root@RPi:~# cat /etc/fstab
#LABEL=writable / ext4 discard,x-systemd.growfs 0 1
#LABEL=system-boot /boot/firmware vfat defaults 0 1
UUID=D7A9-3EE6 /boot/firmware vfat defaults 0 1
UUID=09799e9f-8009-4b0c-84bc-9761d73d9670 / ext4 discard,x-systemd.growfs 0 1
UUID=6e6305ff-5e0c-4918-9de7-0f102acabe93 /home ext4 defaults 0 0
UUID=3af55a00-f9ba-4121-b77a-08f4e911459d none swap sw 0 0
root@RPi:~#
Note the timestamp on /swapfile.
I did stumble over the behavior of swapon -av not finding /swapfile, even though the swap file has not been deleted. That may be related to my earlier fumbling around trying to delete the swap file. I'm pretty sure that I did a swapoff /swapfile earlier, probably a couple of times.
I don't know if this problem is unique to Ubuntu 22.04, or unique to RPi, or both.
I'm not finding anything on the Internet about this particular problem, mostly the steps I've used to try to disable and delete the swap file. Not critical, but annoying.
update 1
The swap in fstab is the partition, not the file.
root@RPi:~# swapon --output-all
NAME TYPE SIZE USED PRIO UUID LABEL
/dev/sda4 partition 12G 0B -2 3af55a00-f9ba-4121-b77a-08f4e911459d swap
/swapfile file 1024M 0B -3 51ac3104-f6c0-4688-9b82-a4ad60bc9661
root@RPi:~#
update 2 with answer
Raffa's answer fixed the problem! Thank you Raffa, tomorrow I will go out and have an espresso in your honor. :-)
root@RPi:~#
root@RPi:~# systemctl status "*.swap"
● dev-disk-by\x2duuid-3af55a00\x2df9ba\x2d4121\x2db77a\x2d08f4e911459d.swap - /dev/disk/by-uuid/3af55a00-f9ba-4121-b77a-08f4e911459d
Loaded: loaded (/etc/fstab; generated)
Active: active since Fri 2022-07-01 22:38:27 PDT; 2 days ago
What: /dev/disk/by-uuid/3af55a00-f9ba-4121-b77a-08f4e911459d
Docs: man:fstab(5)
man:systemd-fstab-generator(8)
Tasks: 0 (limit: 8949)
Memory: 148.0K
CPU: 25ms
CGroup: /system.slice/dev-disk-by\x2duuid-3af55a00\x2df9ba\x2d4121\x2db77a\x2d08f4e911459d.swap
Jul 01 22:38:27 RPi systemd[1]: Activating swap /dev/disk/by-uuid/3af55a00-f9ba-4121-b77a-08f4e911459d...
Jul 01 22:38:27 RPi systemd[1]: Activated swap /dev/disk/by-uuid/3af55a00-f9ba-4121-b77a-08f4e911459d.
● swapfile.swap - The default swapfile
Loaded: loaded (/lib/systemd/system/swapfile.swap; static)
Active: active since Fri 2022-07-01 22:38:28 PDT; 2 days ago
What: /swapfile
Tasks: 0 (limit: 8949)
Memory: 1.2M
CPU: 11ms
CGroup: /system.slice/swapfile.swap
Jul 01 22:38:28 RPi systemd[1]: Activating swap The default swapfile...
Jul 01 22:38:28 RPi systemd[1]: Activated swap The default swapfile.
root@RPi:~#
root@RPi:~#
root@RPi:~# systemctl mask swapfile.swap
Created symlink /etc/systemd/system/swapfile.swap → /dev/null.
root@RPi:~#
root@RPi:~#
root@RPi:~# swapoff -av
swapoff /swapfile
swapoff /dev/sda4
root@RPi:~#
root@RPi:~#
root@RPi:~# swapon -av
swapon: /dev/sda4: found signature [pagesize=4096, signature=swap]
swapon: /dev/sda4: pagesize=4096, swapsize=12885254144, devsize=12885254144
swapon /dev/sda4
root@RPi:~#
root@RPi:~#
root@RPi:~# swapon --output-all
NAME TYPE SIZE USED PRIO UUID LABEL
/dev/sda4 partition 12G 0B -2 3af55a00-f9ba-4121-b77a-08f4e911459d swap
root@RPi:~#
reboot
root@RPi:~#
root@RPi:~# swapon --output-all
NAME TYPE SIZE USED PRIO UUID LABEL
/dev/sda4 partition 12G 0B -2 3af55a00-f9ba-4121-b77a-08f4e911459d swap
root@RPi:~#
update 3
Bad words and foul language!! I should rename this post to "the swapfile that would not die".
The swapfile keeps getting recovered ... at least I think it is being recovered. The timestamp and size appear to be the same, so at least the directory entry is being un-deleted and I suspect the same file blocks are being used. It appears that swap is not using the swapfile.
I'm sorry Raffa, I have to un-select your answer, but you still have my up-vote.
root@RPi:~#
root@RPi:~# swapon --output-all
NAME TYPE SIZE USED PRIO UUID LABEL
/dev/sda4 partition 12G 0B -2 3af55a00-f9ba-4121-b77a-08f4e911459d swap
root@RPi:~#
root@RPi:~#
root@RPi:~# ll /swapfile
-rw------- 1 root root 1073741824 Jul 1 22:38 /swapfile
root@RPi:~#
root@RPi:~#
root@RPi:~# rm -v /swapfile
removed '/swapfile'
root@RPi:~#
root@RPi:~#
root@RPi:~# ll /swapfile
ls: cannot access '/swapfile': No such file or directory
root@RPi:~#
reboot
root@RPi:~#
root@RPi:~# ll /swapfile
-rw------- 1 root root 1073741824 Jul 1 22:38 /swapfile
root@RPi:~#
root@RPi:~# swapon --output-all
NAME TYPE SIZE USED PRIO UUID LABEL
/dev/sda4 partition 12G 0B -2 3af55a00-f9ba-4121-b77a-08f4e911459d swap
root@RPi:~#
/etc/fstab. – waltinator Jul 02 '22 at 22:26sudo apt remove dphys-swapfile… ***carefully check no other packages are to be removed before you answer yes** I will update the answer tomorrow as now I’m commenting on my phone. – Raffa Jul 04 '22 at 19:40sudo apt remove dphys-swapfile, gotPackage 'dphys-swapfile' is not installed, so not removed. – WaffleHouse2t2 Jul 04 '22 at 20:19/swapfileand rebooted multiple times and confirmed it was gone forever(normal expected behavior) ... So, I can now confirm that this behavior(/swapfilecoming back from the dead) is neither related to swap(anymore) nor related to a fresh install of Ubuntu 22.04 ... However, inspecting the output ofjournalctl -o short-precise -k -b all | grep -i swapmight help understand what is happening – Raffa Jul 05 '22 at 08:03journalctl -o short-precise -k -b all | grep -i swap, lot of swapper, zswap, swap partition. Reran replacing swap with swapfile, just adding swapfile to swap before masking swapfile from your answer, nothing about recovering the swapfile. – WaffleHouse2t2 Jul 06 '22 at 01:14