add systemd unit to configure and enable /dev/zram0 swap

This commit is contained in:
Bruce Leidl 2018-02-18 12:58:09 -05:00
parent ae9eb5e2a0
commit 66d234cc3d
2 changed files with 25 additions and 0 deletions

View File

@ -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/

View File

@ -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