Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thypon/runit-swap
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: WindwardIsland/nosystemd-swap
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
Loading
Showing with 218 additions and 121 deletions.
  1. +42 −13 README.md
  2. +5 −0 dinit/nosystemd-swap
  3. +38 −5 install.sh
  4. +118 −98 runit-swap → nosystemd-swap
  5. +2 −0 runit/finish
  6. +1 −1 {swap → runit}/run
  7. +12 −2 swap.conf
  8. +0 −2 swap/finish
55 changes: 42 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
# runit-swap
Script for auto-creation and mounting of: zram swaps, swap files (through loop) devices, swap partitions.
It is configurable in /etc/runit/swap.conf.
Source:
# nosystemd-swap

This repository was originally forked from the [runit-swap](https://github.com/thypon/runit-swap) repository since I saw it as a nice method to either enable and use zram, zswap, or a swapfile, just by running a wrapper shell script.

I had been looking for quite some time now for a good program on Linux that would enable zram for me automatically, without having to do it [manually](https://wiki.archlinux.org/title/Zram#Manually). However, most of the "zram generators" for Linux out there are SystemD only (even SystemD itself has its own [zram generator](https://github.com/systemd/zram-generator)), which don't work on Linux distributions like Void or Artix Linux since they don't use SystemD as their primary init system.

There's always tools like [zramen](https://github.com/atweiden/zramen) or [zramd](https://github.com/maximumadmin/zramd) (which includes a SystemD service when installed, but the program can be run manually from the terminal, allowing it to [work on any init system](https://github.com/maximumadmin/zramd?tab=readme-ov-file#manual-installation-on-any-distribution-without-systemd)) but I always had issues with these tools not creating the amount of size for zram I specified, most likely since both of these tools create zram based on a fraction of your actual RAM.

I then found runit-swap and while I really liked the idea of just being a wrapper shell script that uses `modprobe` and `zramctl` under the hood to create and enable zram, it unfortunately only supports runit and has not been updated in the last 8 years. Hence, this fork exists to be more up-to-date and to work on init systems other than runit.

## Installation

Clone this repository, and make any necessary modifications inside `swap.conf`.

You can enable or disable zswap, zram, a universal swap file, or a chunked swap file by setting the corresponding value to either `0` or `1`.
For example, if I wanted to only enable zram, I would only set `zram_enabled` to 1 and change the zram-related settings.

**NOTE**: Leave the `swapd_auto_swapon` value to be 1 despite any other modifications you have made so that all available swap devices are always toggled on.

Once you're done with your modifications inside `swap.conf`, you can now run the `install.sh` script with the following command:
```
/etc/runit/swap.conf
/usr/bin/runit-swap
/etc/sv/swap/run
/etc/sv/swap/finish
$ sudo ./install.sh
```
Using:

**NOTE**: The instructions for installation in this README use `sudo`, but replace `sudo` with `doas` if you use that instead.

This will copy over the necessary service files to directories that your init system uses to manage services. Once that's done, we're now ready to enable and start the nosystemd-swap service for our init system in the next step.

### Enabling the service
#### runit

Void Linux:
```
$ sudo ln -s /etc/sv/nosystemd-swap /var/service/
```
# ln -s /etc/sv/swap /var/services
Artix Linux (runit flavor):
```
$ sudo ln -s /etc/runit/sv/nosystemd-swap /run/runit/service/
```

#### dinit

Note:
=======
Dependence: util-linux >= 2.26
Artix Linux (dinit flavor) (and possibly Chimera Linux as well, though untested):
```
$ sudo dinitctl enable nosystemd-swap
```
**NOTE**: As of right now, this only supports the runit and dinit init systems. OpenRC and s6 will be supported in the future. This means that this will work on Void, Artix (the runit and dinit flavors), and possibly Chimera Linux, but not Gentoo or the OpenRC and s6 flavors of Artix.
5 changes: 5 additions & 0 deletions dinit/nosystemd-swap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = scripted
command = nosystemd-swap start
stop-command = nosystemd-swap stop
smooth-recovery = true
waits-for = pseudofs
43 changes: 38 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
#!/bin/bash
cd `dirname $0`
[ "$UID" != "0" ] && [ -f /usr/bin/sudo ] && export SUDO="sudo"
$SUDO cp -v ./runit-swap /usr/bin/runit-swap
$SUDO cp -v ./swap.conf /etc/runit/
$SUDO cp -rv ./swap /etc/sv/swap

# The install script for nosystemd-swap. Currently only the runit and dinit init systems are supported.
# Support for openrc and s6 will come in the near future.

# Make sure that this script is run with root permissions since it needs to copy over files to root-protected directories
if [ "$UID" != "0" ]; then
echo "Be sure to run this script with root permissions! (either with sudo or doas)"
exit 1
fi

cp -v ./nosystemd-swap /usr/bin/

# Find what the current init system is
INIT_SYSTEM="$(readlink /sbin/init | sed 's/-init//')"

case "${INIT_SYSTEM}" in
runit)
distro="$(grep -m 1 "ID=" /etc/os-release | sed 's/ID=//')"
case "${distro}" in
artix)
INIT_PATH="/etc/runit/sv" ;;
void)
INIT_PATH="/etc/sv" ;;
esac
SERVICE_FOLDER="nosystemd-swap"
cp -rv ./runit ${INIT_PATH}/${SERVICE_FOLDER}
;;
dinit)
INIT_PATH="/etc/dinit.d"
SERVICE_FOLDER="nosystemd-swap-config"
mkdir -p ${INIT_PATH}/${SERVICE_FOLDER}
cp -v ./dinit/nosystemd-swap "${INIT_PATH}/"
;;
esac

CONF="${INIT_PATH}/${SERVICE_FOLDER}/swap.conf"

cp -v ./swap.conf "${CONF}"
Loading