From 66d234cc3d5495c8e236ada5ab0df31d9bcec94a Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Sun, 18 Feb 2018 12:58:09 -0500 Subject: [PATCH] add systemd unit to configure and enable /dev/zram0 swap --- .../base-files/base-files_%.bbappend | 7 +++++++ .../base-files/files/zram-swap.service | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 meta-citadel-distro/recipes-core/base-files/files/zram-swap.service diff --git a/meta-citadel-distro/recipes-core/base-files/base-files_%.bbappend b/meta-citadel-distro/recipes-core/base-files/base-files_%.bbappend index 4299479..6cca0d9 100644 --- a/meta-citadel-distro/recipes-core/base-files/base-files_%.bbappend +++ b/meta-citadel-distro/recipes-core/base-files/base-files_%.bbappend @@ -8,6 +8,7 @@ SRC_URI += "\ file://99-grsec-debootstrap.conf \ file://00-storage-tmpfiles.conf \ file://NetworkManager.conf \ + file://zram-swap.service \ " dirs1777_remove = "${localstatedir}/volatile/tmp" @@ -15,6 +16,9 @@ dirs755="/boot /dev /usr/bin /usr/sbin /usr/lib /etc /etc/default /etc/skel /usr volatiles = "" +inherit systemd +SYSTEMD_SERVICE_${PN} = "zram-swap.service" + do_install_append () { install -m 0755 -d ${D}/storage install -d ${D}${libdir}/sysctl.d @@ -30,6 +34,9 @@ do_install_append () { install -m 0644 ${WORKDIR}/00-storage-tmpfiles.conf ${D}${sysconfdir}/tmpfiles.d install -m 0644 ${WORKDIR}/NetworkManager.conf ${D}${sysconfdir}/NetworkManager + install -d ${D}${systemd_system_unitdir} + install -m 644 ${WORKDIR}/zram-swap.service ${D}${systemd_system_unitdir} + # disable some pax and grsecurity features so that debootstrap will work # this should be removed later install -m 0644 ${WORKDIR}/99-grsec-debootstrap.conf ${D}${libdir}/sysctl.d/ diff --git a/meta-citadel-distro/recipes-core/base-files/files/zram-swap.service b/meta-citadel-distro/recipes-core/base-files/files/zram-swap.service new file mode 100644 index 0000000..680216f --- /dev/null +++ b/meta-citadel-distro/recipes-core/base-files/files/zram-swap.service @@ -0,0 +1,18 @@ +[Unit] +Description=Enable/Disable zram swap device +ConditionPathExists=/dev/zram0 +ConditionPathExists=/sys/block/zram0 + +[Service] +Type=oneshot +RemainAfterExit=yes + +ExecStart=/bin/sh -c 'echo 2G > /sys/block/zram0/disksize' +ExecStart=/sbin/mkswap /dev/zram0 +ExecStart=/sbin/swapon /dev/zram0 -p 10 + +ExecStop=/sbin/swapoff /dev/zram0 +ExecStop=/bin/sh -c 'echo 1 > /sys/block/zram0/reset' + +[Install] +WantedBy=multi-user.target