Linux Mint (Ubuntu) always use a swapfile on installation, but swapfile on the main subvolume does not work on Btrfs.
To fix this, we need to create a new subvolume and put the swapfile there.
Assuming that / is on /dev/sda2 (/dev/sda1 if you are still using old BIOS, /dev/nvme0n1p2 if you are using NVME) and Linux Mint is installed at / on @ subvolume and /home is on @home subvolume.
- Mount
/dev/sda2to/mnt.sudo mount /dev/sda2 /mnt
If you runls /mnt, you’ll see@,@homeand other subvolumes that may be there. - Create a new
@swapsubvolume.sudo btrfs sub create /mnt/@swap - Unmount
/dev/sda2from/mnt.sudo umount /mnt - Create
/swapdirectory where we plan to mount the@swapsubvolume.sudo mkdir /swap - Mount the
@swapsubvolume to/swap.sudo mount -o subvol=@swap /dev/sda2 /swap - Create the swap file.
sudo touch /swap/swapfile - Set 600 permissions to the file.
sudo chmod 600 /swap/swapfile - Disable copy-on-write for this file.
sudo chattr +C /swap/swapfile - Set size of the swap file to 4 GB as an example.
sudo fallocate -l 4G /swap/swapfile - Format the swapfile.
sudo mkswap /swap/swapfile - Turn the swap file on.
sudo swapon /swap/swapfile
Now the new swap should be working. - Type
sudo xed /etc/fstabto open fstab in text editor. Be careful with this file as it can easily cause your system not to boot. - Remove
/swap/swapfile none swap sw 0 0at the last part. - Add these lines at the last part of fstab:
| |
Use the UUID of your /dev/sda2. Save the file.
- Remove the old swapfile created by the installer.
sudo rm -f /swapfile
Note: If your CPU is fast enough for zRAM, use zRAM instead.
Sources:\