I always use btrfs since 20.04. Haven’t seen this issue before. But I think I found the culprit.
By default, after installing Ubuntu-Budgie with btrfs filesystem,
/swapfile is created. But since BTRFS does not allow a swapfile on a subvolume just like that (it could be snapshotted) and without CoW turned off, this will result in a warning/error and the swapfile will not be used. Most users won’t notice.
A few weeks ago I got an old Intel NUC with only 4GB RAM so I thought it would be wise to enable swap. I Googled and learned you have to create a seperate subvolume for it, mount it via fstab and apply
chattr +C to disable CoW. So I did all that and it seems that system is working fine, while swapping.
I added these steps to my postinstall script that I run after a clean install, used it on my Ryzen laptop (with 16GB ram). When I used it, the issues began. Since I have cleaned up that post-install script a lot and made lots of modifications, I wasn’t sure what the issue could be. It seemed to be too low-level to be caused by my script.
Today, before switching back to 20.10 or testing ext4, I thought I simply do a quick clean install again and did not run my script → all goes fine!
Then I ran my script but omitted the swapfile commands → for over 40min now, all seems fine!
This is what I do to enable swap on btrfs:
# Temporarily mount filesystem root
sudo mount -o subvolid=5 /dev/nvme0n1p2 /mnt/system
# create a root subvolume for user personal folders in the root filesystem
sudo btrfs subvolume create /mnt/system/@swap
# Just to be sure, disable CoW for the subvolume
sudo chattr +C /mnt/system/@swap
# now umount the filesystem root
sudo umount /mnt/system
# Temporarily mount @swap and finish configuration
sudo mkdir /swap
sudo mount -o subvol=@swap /dev/nvme0n1p2 /swap
# Configure swap file
sudo chattr +C /swap
sudo touch /swap/swapfile
sudo chattr +C /swap/swapfile
sudo chmod 600 /swap/swapfile
sudo dd if=/dev/zero of=/swap/swapfile bs=1024 count=4194304
sudo mkswap /swap/swapfile
sudo swapon /swap/swapfile
# Add mount rule to fstab
UUID=... /swap btrfs defaults,noatime,subvol=@swap 0 0
/swap/swapfile none swap sw 0 0
I can verify with
free -mh and it shows 4GB swap.
I will wait for a day or so, play with the laptop a bit to ensure it works fine without swap, then I will try to enable swap again with the above commands.
It is a pity Ubuntu Installer doesn’t take care of this automatically when btrfs filesystem is selected, instead creating
/swapfile that is broken/doesn’t work. Subvolumes
@home are created by default the installer, it could create a subvolume
@swap as well.