Skip to content

Commit

Permalink
New Trick: Linux swapfile with systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
rusty-snake committed Jul 4, 2024
1 parent 21e28db commit 3251d43
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions _posts/2024-07-04-swapfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
layout: post
title: "Linux swapfile with systemd"
author: "rusty-snake"
tags: swap swapfile systemd
---

**Preliminary notes:**

* This is a short transcript of the steps necessary to add a swapfile under linux. For a more detailed
explanation I refer to the [ArchWiki page](https://wiki.archlinux.org/title/Swap#Swap_file).
* Unlike the most other tutorials for swapfiles you will find in the internet that add the
swapfile to fstab, we will create a swapfile.swap systemd unit.
* This tutorial assumes that you have a working zram swap device with priority 100.

## Create the swapfile

~~~ bash
mkswap --check -U clear --size 4G --file /swapfile
~~~

## Create a systemd swap unit for it

~~~ bash
systemctl edit --full --force swapfile.swap
systemctl enable --now swapfile.swap
~~~

~~~ systemd
[Unit]
Description=Disk Swap on /swapfile
[Swap]
What=/swapfile
Priority=50
Options=discard
[Install]
WantedBy=swap.target
~~~

0 comments on commit 3251d43

Please sign in to comment.