From 14d0cdcec18deb8ae4a955d2854c24ddd6bb1cff Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 31 Mar 2022 11:49:39 -0500 Subject: [PATCH] Configure swap space on NBD volume Using zram to compress pages did not provide enough memory to run Firefox, Node, and Python for an extended period of time. Here's hoping swap-on-NBD will be fast and reliable enough to work. Note that systemd's default behavior with respect to swap areas is to enable them all rather early in the boot process, before the network is fully configured. As such, we have to use the *noauto* flag to disable the default dependencies and add our own in a later target. --- overlay/etc/fstab | 1 + overlay/etc/nbdtab | 1 + .../systemd/system/dev-nbd1.device.wants/nbd@nbd1.service | 1 + .../system/dev-nbd1.swap.d/no-default-dependencies.conf | 5 +++++ .../etc/systemd/system/multi-user.target.wants/dev-nbd1.swap | 1 + 5 files changed, 9 insertions(+) create mode 100644 overlay/etc/nbdtab create mode 120000 overlay/etc/systemd/system/dev-nbd1.device.wants/nbd@nbd1.service create mode 100644 overlay/etc/systemd/system/dev-nbd1.swap.d/no-default-dependencies.conf create mode 120000 overlay/etc/systemd/system/multi-user.target.wants/dev-nbd1.swap diff --git a/overlay/etc/fstab b/overlay/etc/fstab index d4e89d7..b299b09 100644 --- a/overlay/etc/fstab +++ b/overlay/etc/fstab @@ -2,3 +2,4 @@ tmpfs /var/lib/rsyslog tmpfs defaults 0 0 tmpfs /var/log tmpfs defaults 0 0 tmpfs /var/lib/systemd tmpfs defaults 0 0 tmpfs /var/lib/NetworkManager tmpfs defaults 0 0 +/dev/nbd1 swap swap noauto,x-systemd.makefs 0 0 diff --git a/overlay/etc/nbdtab b/overlay/etc/nbdtab new file mode 100644 index 0000000..18b7ebf --- /dev/null +++ b/overlay/etc/nbdtab @@ -0,0 +1 @@ +nbd1 pxe0.pyrocufflink.blue basementhud-swap diff --git a/overlay/etc/systemd/system/dev-nbd1.device.wants/nbd@nbd1.service b/overlay/etc/systemd/system/dev-nbd1.device.wants/nbd@nbd1.service new file mode 120000 index 0000000..34d9511 --- /dev/null +++ b/overlay/etc/systemd/system/dev-nbd1.device.wants/nbd@nbd1.service @@ -0,0 +1 @@ +/usr/lib/systemd/system/nbd@.service \ No newline at end of file diff --git a/overlay/etc/systemd/system/dev-nbd1.swap.d/no-default-dependencies.conf b/overlay/etc/systemd/system/dev-nbd1.swap.d/no-default-dependencies.conf new file mode 100644 index 0000000..0124d72 --- /dev/null +++ b/overlay/etc/systemd/system/dev-nbd1.swap.d/no-default-dependencies.conf @@ -0,0 +1,5 @@ +[Unit] +# All swap units have a default `Before=swap.target` dependency. This +# does not work for swap devices using NBD, because `swap.target` is +# reached before the network is up. +DefaultDependencies=no diff --git a/overlay/etc/systemd/system/multi-user.target.wants/dev-nbd1.swap b/overlay/etc/systemd/system/multi-user.target.wants/dev-nbd1.swap new file mode 120000 index 0000000..bb8f1d8 --- /dev/null +++ b/overlay/etc/systemd/system/multi-user.target.wants/dev-nbd1.swap @@ -0,0 +1 @@ +../dev-nbd1.swap \ No newline at end of file