Help with swap file on BTRFS

Hi,

I installed new installation but with btrfs.

As I can see, I dont have swap file or swap partition.

I want swap file , but I also saw somewhere that I need swapfile on separate subvolume * which is not included in snapshots.

I am reading Arch wiki, but I am not sure how to do it.
I dont how which path is for subvolume etc…

Little help please xD

Thanks

Try this:


1. sudo btrfs subvolume create @swap  

2. sudo mkdir /swap

3. sudo mount -o subvol=@swap /dev/XXX /swap   ## replace XXX with your actual partition for example sda2, nvme0n1p2 

4. cd /swap

5. sudo truncate -s 0 swapfile 

6. sudo chattr +C swapfile 

7. sudo btrfs property set swapfile compression none

8. sudo dd if=/dev/zero of=swapfile bs=1M count=512 status=progress

9. sudo chmod 600 swapfile


10. sudo mkswap swapfile


11. sudo swapon swapfile

12. Now Edit the /etc/fstab and add the following two lines:

 UUID=NNNN                                    /swap                  btrfs    subvol=@swap ## replace NNNN with the UUID of the partition where @swap resides 

 /swap/swapfile                              none                   swap     defaults 0 0
3 Likes

This is what I have for now

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
nvme0n1     259:0    0 476.9G  0 disk 
├─nvme0n1p1 259:1    0   512M  0 part /boot
└─nvme0n1p2 259:2    0 476.4G  0 part /

I dont know what I did and where are others subvolumes , like home,var etc

You can list them with:

sudo btrfs subvolume list /

ID 259 gen 15 top level 5 path var/lib/portables
ID 260 gen 16 top level 5 path var/lib/machines

I screwed something right

Post:

lsblk -fs

cat /etc/fstab

lsblk -fs

[marko@marko ~]$ lsblk -fs
NAME      FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
nvme0n1p1 vfat   FAT32       1D05-8F9F                             412.1M    19% /boot
└─nvme0n1                                                                        
nvme0n1p2 btrfs              3148ec9f-34e6-421b-81ff-142263a3a76c  460.6G     3% /
└─nvme0n1

cat /etc/fstab

[marko@marko ~]$ cat /etc/fstab
# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dump> <pass>

tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
# /dev/nvme0n1p2
UUID=3148ec9f-34e6-421b-81ff-142263a3a76c       /               btrfs           rw,relatime,ssd,space_cache,subvolid=5,subvol=/ 0 0

# /dev/nvme0n1p1
UUID=1D05-8F9F          /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro   0 2

Probably is best to reinstall again, maybe btrfs is not for me xD

Doesn’t look quite right.
I would do an erase disk and install this time and choose swapfile already from the installer.

1 Like

Sure, I will try… Thanks btw

1 Like

Imho don’t bother with making swap work within btrfs. Just create a normal swap partition and keep the two separated. Makes life easier in the long run.

1 Like