From 6dd83fdc2cf3b415f474d06cff8bf1e7b4600aa0 Mon Sep 17 00:00:00 2001 From: Sunderland93 Date: Mon, 25 Jul 2022 13:46:00 +0400 Subject: [PATCH] Enanling Zswap --- build-rpi.sh | 52 ++++++++++++++++++++++++++++-- rpi/rootfs/system-boot/cmdline.txt | 2 +- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/build-rpi.sh b/build-rpi.sh index 42c6c84..869daed 100755 --- a/build-rpi.sh +++ b/build-rpi.sh @@ -71,9 +71,9 @@ EOF # Configure mount points cat << EOF > ubuntusway-${architecture}/etc/fstab # -proc /proc proc nodev,noexec,nosuid 0 0 -LABEL=writable / ext4 defaults,noatime 0 0 -LABEL=system-boot /boot/firmware vfat defaults 0 1 +proc /proc proc nodev,noexec,nosuid 0 0 +LABEL=writable / ext4 discard,noatime 0 1 +LABEL=system-boot /boot/firmware vfat defaults 0 1 EOF export LC_ALL=C @@ -159,6 +159,52 @@ EOF chmod +x ubuntusway-$architecture/user LANG=C chroot ubuntusway-$architecture /user +# Creating swapfile service + +# Adds lz4 and z3fold modules to initramfs. +# - https://ubuntu.com/blog/how-low-can-you-go-running-ubuntu-desktop-on-a-2gb-raspberry-pi-4 +echo lz4 >> ubuntusway-$architecture/etc/initramfs-tools/modules +echo z3fold >> ubuntusway-$architecture/etc/initramfs-tools/modules + +mkdir -p ubuntusway-$architecture/usr/lib/systemd/system/swap.target.wants + +cat <> ubuntusway-$architecture/usr/lib/systemd/system/mkswap.service +[Unit] +Description=Create the default swapfile +DefaultDependencies=no +Requires=local-fs.target +After=local-fs.target +Before=swapfile.swap +ConditionPathExists=!/swapfile + +[Service] +Type=oneshot +ExecStartPre=fallocate -l 1GiB /swapfile +ExecStartPre=chmod 600 /swapfile +ExecStart=mkswap /swapfile + +[Install] +WantedBy=swap.target +EOF + +cat <> ubuntusway-$architecture/usr/lib/systemd/system/swapfile.swap +[Unit] +Description=The default swapfile + +[Swap] +What=/swapfile +EOF + +cat <> ubuntusway-$architecture/enable_zswap +#!/bin/bash +ln -s /usr/lib/systemd/system/mkswap.service /usr/lib/systemd/system/swap.target.wants/mkswap.service +ln -s /usr/lib/systemd/system/swapfile.swap /usr/lib/systemd/system/swap.target.wants/swapfile.swap +rm -f enable_zswap +EOF + +chmod +x ubuntusway-$architecture/enable_zswap +LANG=C chroot ubuntusway-$architecture /enable_zswap + # Calculate the space to create the image. root_size="$(du -s -B1K ubuntusway-$architecture | cut -f1)" raw_size="$(($((free_space*1024))+root_size))" diff --git a/rpi/rootfs/system-boot/cmdline.txt b/rpi/rootfs/system-boot/cmdline.txt index 8228c27..8fddf6f 100644 --- a/rpi/rootfs/system-boot/cmdline.txt +++ b/rpi/rootfs/system-boot/cmdline.txt @@ -1 +1 @@ -dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait fixrtc quiet splash +zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4 dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait fixrtc quiet splash