SwapFile Resize On Btrfs

I tried it before and it didn’t work because i am obviously making mistakes in the path because I’m think differently about subvolumes and not understanding.

What you have written down i understand.

Turn swap off path /swap/swapfile
truncate or make the file zero in size? again path to the file
Then use dd command to create file with size of choosing.
Then make the file a swap file … path
Turn on swap file …path

What is or was confusing to me is the path and looking at the structure and seeing @swap and not seeing a swap directory… Is it inside the subvolume? Obviously i was using /swap or /swapfile and not /swap/swapfile.

Thank You for the explanation so now i see where i was making the error.

Edit: So this worked. Now i ask why is the way it’'s explained on the arch wiki different. Also on the Arch wiki for swap file it has chmod command

chmod 600 /swapfile

This is why i don’t understand half the stuff because there are so many different explanations but nothing methodical in order do this when or do this if. I find the Arch wiki convoluted with lots of information but not much detail. It has detail about information but not detail about order and instructions. It’s easy for people who already know this stuff and they think it’s great. For those less knowledgeable not so much.

@swap is mounted at /swap in the same way that @home is mounted at /home

Given that, /swap/swapfile means there is a file named swapfile inside the subvolume @swap

1 Like

Yes i understand that the swapfile is /swap/swapfile and it’s inside @swap.

Thank You!

The way you have written out the instructions is the way i understand things. In order and i know what they do.

1 Like

Feel so sorry that an initially supposed to be easy method to modify the swap file size turned into such a pain with btrfs.

I agree, I found the arch wiki a little bit ambiguous, what swap file location and all these things about subvolumes. I am not using btrfs yet, so my knowledge is pretty limited with that file system…

It is easy but the Arch wiki makes it more difficult because it tells you stuff and just assumes you know what to do then it gives commands below but if you haven’t done the other stuff then it doesn’t work. They just assume you know what they mean to do. I would like to have it all in one. So the commands would show you creating the director and the subvolume and then continuing on with the rest. Then also when the link switches to all the commands and instructions to create the swap file it’s on another page and it’s not btrfs so they are using /swapfile instead of /swap/swapfile in the commands. So i’m just blindly following along not thinking of all these things. Then of course nothing works. I find it very frustrating. Once i understand it it’s okay.

I don’t actually think any of those steps are btrfs specific. Wouldn’t those steps work with any swapfile?

These commands are necessary for the btrfs swap file but not on ext4.

truncate -s 0 ./swapfile
chattr +C ./swapfile
btrfs property set ./swapfile compression none

But those are only for creating the file, not resizing an existing swapfile.

Actually I did a swap file resize for the first time yesterday and put the instructions that worked for me on ext4 here:

Yes! the next steps are the same.

Edit: but I am not sure whether the 3 other commands (to initialize a swap file is to first create a non-compressed, non-snapshotted subvolume to host the file) I posted above need to be run each time one wants to resize on btrfs.

Those are basically the exact same instructions. The only differences are that I truncated the file first and you changed the permissions on it. In reality, neither of those steps are probably required when resizing the file. I just like starting clean so I truncated it and since the swapfile already exists it should already have the correct permissions.

They do not.

1 Like

Ok!

I added this based on @joekamprad ’s comment when I posted the code sequence. But I suspected the permissions should be set correctly since I created a swapfile during the eos install. I was just not sure whether the dd command overrides that permission.

If the file already exists, the dd command shouldn’t change the permissions.

Ok good to know!

Just wondering if it could be useful to summarize these nifty tricks into a short “how to create a swap file and resize it on ext4 and btrfs” on the eos discovery/article website. For future reference.

1 Like

I was confused about that too because i also don’t know that much about changing file permissions.

These two are different in the instructions on the arch wiki was what i was getting at because they point you to a different link which is not about btrfs but specifically about manually creating the file. So I’m not thinking about this and then commands don’t work.

# mkswap /swapfile
# swapon /swapfile

The only difference is that they are putting the swapfile at different locations. There isn’t a predetermined location where the swapfile must be. It is just an example.