Help with SWAP file, What should I do next?

Hi,

I just created SWAP file on a non-compressed, non-snapshotted subvolume as Archwiki suggested.
I'm not sure that I miss something.
Do I have to do something with grub, initrams, timeshift...etc ?
Any help/suggestions would be greatly appreciated. :pray:

What I did and How I did:
sda      8:0    0 931,5G   disk
├─sda1   8:1    0   300M   part FAT32 EFI
├─sda2   8:2    0 530,7G   part BTRFS /root
├─sda3   8:3    0    16M   part UNKWN Microsoft Reserved 
└─sda4   8:4    0 307,4G   part NTFS  Win10

1.Mount sda2
sudo mount /dev/sda2 /mnt

2.Create a new @swap subvolume
sudo btrfs subvolume create /mnt/@swap

3.Unmount sda2
sudo umount /mnt

4.Create /swap directory where I plan to mount the @swap subvolume.
sudo mkdir /swap

5.Mount the @swap subvolume to /swap.
sudo mount -o subvol=@swap /dev/sda2 /swap

6.Create swap file 16 GB.
sudo touch /swap/swapfile
sudo chattr +C /swap/swapfile
sudo truncate -s 0 /swap/swapfile
sudo fallocate -l 16000M /swap/swapfile
sudo chmod 600 /swap/swapfile
sudo mkswap /swap/swapfile

Setting up swapspace version 1, size = 15,6 GiB (16777211904 bytes)
no label, UUID=71462731-7564-424d-9cf2-1d8b69133db6

7.Turn the swap file on.
sudo swapon /swap/swapfile

8.Update /etc/fstab to mount all this on boot. Add there two lines:
UUID=2D32-43BF                            /boot/efi      vfat    umask=0077 0 2
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /              btrfs   subvol=@,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 1
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /home          btrfs   subvol=@home,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 2
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /root          btrfs   subvol=@root,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 2
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /srv           btrfs   subvol=@srv,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 2
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /var/cache     btrfs   subvol=@cache,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 2
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /var/log       btrfs   subvol=@log,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 2
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /var/tmp       btrfs   subvol=@tmp,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd 0 2
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0
UUID=3d6644cc-3196-4afd-a8d6-95fb20e38c4b /swap          btrfs   defaults,noatime,subvol=@swap 0 0
/swap/swapfile none swap sw 0 0

Looks fine. Verify it's operating with free (and look for the "Swap" line.

2 Likes

Thank you jonathon :slight_smile:

swapon --show
NAME TYPE SIZE USED PRIO
/swap/swapfile file 15,6G 0B -2
free
total used free shared buff/cache available
Mem: 8022232 2675236 2402940 255780 2944056 4385528
Swap: 16383996 0 16383996

It seems it works, but my system not using it.

Do I have to add/modify something at systemd or swapiness? :thinking:

It will be used when needed - you don't need to do anything. :wink:

4 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.