-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Trick: Linux swapfile with systemd
- Loading branch information
1 parent
21e28db
commit 3251d43
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
~~~ |