# BTRFS Swap on Install

**URL:** <https://forum.endeavouros.com/t/btrfs-swap-on-install/27373>\
**Category:** Installation\
**Created:** [May 23, 2022, 9:36pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373 "2022-05-23T21:36:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoFax](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/n/53a042/32.png) [@NeoFax](https://forum.endeavouros.com/u/NeoFax)\
**Post date:** [May 23, 2022, 9:36pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/1 "2022-05-23T21:36:13Z")

</div>

Is there anyway we can get the Installation script to install a @SWAP partition? i am having problems creating one after the install and turning on during boot. I have created one, but I always have to do a swapon after boot. I have followed the wiki, but it doesn’t really explain how to make a @SWAP, just a swapfile.

---

<div class="post-metadata">

**Author:** ![ajgringo619](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ajgringo619/32/35599_2.png) [@ajgringo619](https://forum.endeavouros.com/u/ajgringo619)\
**Post date:** [May 23, 2022, 10:21pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/2 "2022-05-23T22:21:46Z")

</div>

Should be as simple as adding the appropriate entry in **/etc/fstab**. This is mine:

```auto
UUID=f0eef397-b328-4c1e-997b-546af5354ed6 none swap sw 0 0

```

I’m not sure what you mean by “ **@SWAP** ” partition.

---

<div class="post-metadata">

**Author:** ![NeoFax](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/n/53a042/32.png) [@NeoFax](https://forum.endeavouros.com/u/NeoFax)\
**Post date:** [May 23, 2022, 10:59pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/3 "2022-05-23T22:59:54Z")

</div>

```auto
btrfs sub create /mnt/@swap

```

---

<div class="post-metadata">

**Author:** ![sradjoker](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/sradjoker/32/64224_2.png) [@sradjoker](https://forum.endeavouros.com/u/sradjoker)\
**Post date:** [May 23, 2022, 11:08pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/4 "2022-05-23T23:08:54Z")

</div>

That’s a subvolume and not a partition.

---

<div class="post-metadata">

**Author:** ![ajgringo619](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ajgringo619/32/35599_2.png) [@ajgringo619](https://forum.endeavouros.com/u/ajgringo619)\
**Post date:** [May 23, 2022, 11:13pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/5 "2022-05-23T23:13:26Z")

</div>

This is a subvolume, not a partition. If this is the route you want to go, then you’ll need to create a swapfile inside the @swap subvolume, then add it to your `/etc/fstab`.

You have (2) sets of instructions that must be followed:

1. From [https://wiki.archlinux.org/title/Btrfs#Swap\_file](https://wiki.archlinux.org/title/Btrfs#Swap_file), you create a zero-length file that will be used to create the swapfile

2. From [https://wiki.archlinux.org/title/Swap#Swap\_file\_creation](https://wiki.archlinux.org/title/Swap#Swap_file_creation), you create/activate the swapfile, then add it to `/etc/fstab`.

While I totally understand the convenience of using swapfiles over swap partitions, it was way easier setting up a swap partition.

---

<div class="post-metadata">

**Author:** ![ajgringo619](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ajgringo619/32/35599_2.png) [@ajgringo619](https://forum.endeavouros.com/u/ajgringo619)\
**Post date:** [May 23, 2022, 11:13pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/6 "2022-05-23T23:13:53Z")

</div>

I need to type faster! 😇

---

<div class="post-metadata">

**Author:** ![sradjoker](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/sradjoker/32/64224_2.png) [@sradjoker](https://forum.endeavouros.com/u/sradjoker)\
**Post date:** [May 23, 2022, 11:16pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/7 "2022-05-23T23:16:30Z")

</div>

Does the swap file need to be in a separate subvolume?

> Wiki only says that it only needs to be not in a snapshotted subvolume.

But then wiki adds this line:

> The proper procedure is to create a new subvolume to place the swap file in.

---

<div class="post-metadata">

**Author:** ![ajgringo619](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ajgringo619/32/35599_2.png) [@ajgringo619](https://forum.endeavouros.com/u/ajgringo619)\
**Post date:** [May 23, 2022, 11:33pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/8 "2022-05-23T23:33:18Z")

</div>

It can be on any subvolume, as long as it’s not snapshotted. For example, it could reside on `/var/cache` because it’s not included in snapshots (by default, anyway). Creating a new subvolume is just a way to guarantee that it’s not going to be snapshotted.

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [May 23, 2022, 11:46pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/9 "2022-05-23T23:46:09Z")

</div>

@NeoFax

```auto
cat /etc/fstab

lsblk -f

sudo btrfs subvolume list -p /

```

could give the forum some “hard” info to go by.

---

<div class="post-metadata">

**Author:** ![NeoFax](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/n/53a042/32.png) [@NeoFax](https://forum.endeavouros.com/u/NeoFax)\
**Post date:** [May 24, 2022, 12:00pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/10 "2022-05-24T12:00:29Z")

</div>

So, If I wanted to create the subvolume @SWAP on the standard RPI4 install I would do:

```auto
sudo btrfs sub create /var/swap/@swap
cd /var/swap
sudo truncate -s 0 ./swapfile
sudo chattr +C ./swapfile
sudo btrfs property set ./swapfile compression none
sudo dd if=/dev/zero of=./swapfile bs=1M count=512 status=progress
sudo chmod 0600 ./swapfile
sudo mkswap -U clear ./swapfile
sudo swapon ./swapfile

```

Then change my /etc/fstab by adding:

```auto
UUID=XXXXXXXXXXXXXXX /swap btrfs subvol=@swap 0 0
/var/swap/swapfile none swap sw 0 0

```

Or am I missing any steps? Also, do I need to do this from another system and mount the usb inside it to create the subvolume and such?

---

<div class="post-metadata">

**Author:** ![anon75994754](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@anon75994754](https://forum.endeavouros.com/u/anon75994754)\
**Post date:** [May 24, 2022, 12:36pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/11 "2022-05-24T12:36:04Z")

</div>

🙏 i no use btrfs . I have litte dig + find this .

##### Notes if you are using Btrfs

For [Btrfs](https://wiki.archlinux.org/index.php/Btrfs), first create a zero-length file, set the `No_COW` attribute on it with [chattr](https://wiki.archlinux.org/index.php/Chattr), and make sure compression is disabled. _**This is not needed on other filesystems (like ext4)**_ !!

```auto
sudo truncate -s 0 /swapfile
sudo chattr +C /swapfile
sudo btrfs property set /swapfile compression none

```

If you are using a subvol for swap like current default BTRFS installs will do your swapfile location needs to be changed to `/swap/swapfile` instead of `/swapfile`.

HERE…  
[https://discovery.endeavouros.com/storage-and-partitions/adding-swap-after-installation/2021/03/](https://discovery.endeavouros.com/storage-and-partitions/adding-swap-after-installation/2021/03/)

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [May 24, 2022, 12:44pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/12 "2022-05-24T12:44:27Z")

</div>

Swap file is supported on Btrfs. That is the way to go. No issue.

---

<div class="post-metadata">

**Author:** ![ajgringo619](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ajgringo619/32/35599_2.png) [@ajgringo619](https://forum.endeavouros.com/u/ajgringo619)\
**Post date:** [May 24, 2022, 3:19pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/13 "2022-05-24T15:19:07Z")

</div>

You’ve got the wrong location for your swapfile:

`cd /var/swap/@swap`: this is the subvolume that you created, not `/var/swap`

Your `/etc/fstab` should look like this; no need to mount **@swap** as it’s already under a mounted filesystem (/@):

`/var/swap/@swap/swapfile none swap sw 0 0`

---

<div class="post-metadata">

**Author:** ![lorebett](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/lorebett/32/42186_2.png) [@lorebett](https://forum.endeavouros.com/u/lorebett)\
**Post date:** [May 25, 2022, 3:21pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/14 "2022-05-25T15:21:41Z")

</div>

The article at that link states

> Just a note, it’s not recommended to make a swap partition on an SSD, this can damage the medium.

I never heard of that… and I can’t see why that should be the case…

---

<div class="post-metadata">

**Author:** ![NeoFax](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/n/53a042/32.png) [@NeoFax](https://forum.endeavouros.com/u/NeoFax)\
**Post date:** [May 25, 2022, 5:02pm UTC](https://forum.endeavouros.com/t/btrfs-swap-on-install/27373/15 "2022-05-25T17:02:47Z")

</div>

It is on a PNY 128GB Atache usb drive attached to a RPI400.
