From 7f15690e43f1c04ba83678257c0103061fe86db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 2 Nov 2020 04:46:31 +0100 Subject: [PATCH] Add a service to enable swap early - before fsck of the root filesystem fsck may require significant amount of RAM, enable swap earlier to avoid out of memory condition. Implement this as a separate service unit, not a swap unit, because the latter requires udev running (implicit dependency on dev-xvdc1.device) which is not the case before remounting root filesystem read-write. QubesOS/qubes-issues#6174 --- Makefile | 2 +- debian/qubes-core-agent.install | 1 + rpm_spec/core-agent.spec.in | 1 + vm-systemd/75-qubes-vm.preset | 1 + vm-systemd/dev-xvdc1-swap.service | 13 +++++++++++++ .../systemd-fsck-root.service.d/30_qubes.conf | 2 ++ 6 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 vm-systemd/dev-xvdc1-swap.service create mode 100644 vm-systemd/systemd-fsck-root.service.d/30_qubes.conf diff --git a/Makefile b/Makefile index 06651a0..9d52376 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ install-init: install -m 0644 init/functions $(DESTDIR)$(LIBDIR)/qubes/init/ # Systemd service files -SYSTEMD_ALL_SERVICES := $(wildcard vm-systemd/qubes-*.service) +SYSTEMD_ALL_SERVICES := $(wildcard vm-systemd/qubes-*.service) vm-systemd/dev-xvdc1-swap.service SYSTEMD_NETWORK_SERVICES := vm-systemd/qubes-firewall.service vm-systemd/qubes-iptables.service vm-systemd/qubes-updates-proxy.service SYSTEMD_CORE_SERVICES := $(filter-out $(SYSTEMD_NETWORK_SERVICES), $(SYSTEMD_ALL_SERVICES)) diff --git a/debian/qubes-core-agent.install b/debian/qubes-core-agent.install index bbbc6a4..9ac4bbf 100644 --- a/debian/qubes-core-agent.install +++ b/debian/qubes-core-agent.install @@ -83,6 +83,7 @@ lib/systemd/system/netfilter-persistent.service.d/30_qubes.conf lib/systemd/system/org.cups.cupsd.path.d/30_qubes.conf lib/systemd/system/org.cups.cupsd.service.d/30_qubes.conf lib/systemd/system/org.cups.cupsd.socket.d/30_qubes.conf +lib/systemd/system/dev-xvdc1-swap.service lib/systemd/system/qubes-early-vm-config.service lib/systemd/system/qubes-misc-post.service lib/systemd/system/qubes-mount-dirs.service diff --git a/rpm_spec/core-agent.spec.in b/rpm_spec/core-agent.spec.in index 81d05be..9e7e984 100644 --- a/rpm_spec/core-agent.spec.in +++ b/rpm_spec/core-agent.spec.in @@ -908,6 +908,7 @@ The Qubes core startup configuration for SystemD init. %files systemd %defattr(-,root,root,-) /etc/systemd/system/xendriverdomain.service +/lib/systemd/system/dev-xvdc1-swap.service /lib/systemd/system/qubes-misc-post.service /lib/systemd/system/qubes-mount-dirs.service /lib/systemd/system/qubes-rootfs-resize.service diff --git a/vm-systemd/75-qubes-vm.preset b/vm-systemd/75-qubes-vm.preset index 93f3c58..a2f6cd8 100644 --- a/vm-systemd/75-qubes-vm.preset +++ b/vm-systemd/75-qubes-vm.preset @@ -107,6 +107,7 @@ enable qubes-sync-time.timer enable module-load-dummy-psu.service enable module-load-dummy-backlight.service enable qubes-psu-client@.service default sys-usb +enable dev-xvdc1-swap.service # Disable useless Xen services in Qubes VM disable xenstored.service diff --git a/vm-systemd/dev-xvdc1-swap.service b/vm-systemd/dev-xvdc1-swap.service new file mode 100644 index 0000000..2fb9790 --- /dev/null +++ b/vm-systemd/dev-xvdc1-swap.service @@ -0,0 +1,13 @@ +[Unit] +# have it as .service, not .swap, because .swap has implicit dependency on +# .device which needs udev running already +Description=Enable swap on /dev/xvdc1 early +DefaultDependencies=no +Before=systemd-fsck-root.service + +[Service] +Type=oneshot +ExecStart=-/usr/sbin/swapon /dev/xvdc1 + +[Install] +WantedBy=sysinit.target diff --git a/vm-systemd/systemd-fsck-root.service.d/30_qubes.conf b/vm-systemd/systemd-fsck-root.service.d/30_qubes.conf new file mode 100644 index 0000000..421c6f0 --- /dev/null +++ b/vm-systemd/systemd-fsck-root.service.d/30_qubes.conf @@ -0,0 +1,2 @@ +[Unit] +After=swap.target