Good morning everyone.
I have swap enabled on a file in the main subvolume, but TimeShift obviously refuses to work.
I’d like to move the swap file to a dedicated subvolume and would like to know if the procedure below is correct.
Thanks in advance.
- Creating and Mounting the @swap Subvolume
Open a terminal and run these commands to create the subvolume and the folder to mount it in:
Bash
Create the subvolume in the root
sudo btrfs subvolume create /@swap
Create the mount folder
sudo mkdir /swap
Now we need to make the system mount this subvolume at startup. Open the /etc/fstab file:
Bash
sudo nano /etc/fstab
Copy the UUID of your Btrfs disk (you can see it from other existing lines, such as / or /home) and add this line:
Plaintext
UUID=YOUR_UUID_HERE /swap btrfs subvolume=@swap,defaults,noatime 0 0
Save with Ctrl+O, press Enter, and exit with Ctrl+X.
Now mount the newly configured subvolume:
Bash
sudo mount /swap
- Creating the swapfile with the native command
Now that we’re inside the isolated subvolume, let’s use the Btrfs-specific command. Replace 4g with the desired size (e.g., 8g if you want 8 gigabytes):
Bash
Navigate to the folder
cd /swap
Create and configure the swapfile in one go (e.g., 4 gigabytes)
sudo btrfs swapfile create --size 4g ./swapfile
This single command has already created the file, disabled CoW (+C), removed compression, and formatted the file as swap.
- Permanently enable swap
To test it right away, enable swap on your system:
Bash
sudo swapon ./swapfile
Finally, to have Manjaro load it automatically on every reboot, reopen the /etc/fstab file:
Bash
sudo nano /etc/fstab
And add this line right at the bottom of the file:
Plaintext
/swap/swapfile none swap defaults 0 0
Save (Ctrl+O, Enter) and exit (Ctrl+X).
Final check
To make sure everything is up and running, you can run the command:
Bash
swapon --show
You’ll see a line showing your new ./swapfile associated with the /swap directory, ready for use and completely isolated from your system snapshots.