Skip to content

Commit

Permalink
Remove zephemeral capabilities from codebase
Browse files Browse the repository at this point in the history
The ro-root.sh file that allowed for the zephemeral capabilities inside
of the zram-config project is licensed under the terms of the GPLv3
license. As the GPLv3 license cannot be used under the MIT license,
which is the license that the zram-config project is distributed under,
the use of the ro-root.sh file in the zram-config project violated the
terms of the GPLv3 license and as such could not legally be distributed
with the zram-config project. To prevent potential legal action against
the zram-config project, the ro-root.sh file and the capabilities it
provided in the zram-config project are removed by this commit.

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Feb 2, 2021
1 parent 87728f7 commit 9693730
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 235 deletions.
41 changes: 2 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ This project uses an OverlayFS mount with zram so that syncFromDisk on start is
In theory this should allow for faster boots and larger directories as no complete directory copy is needed as it is the lower mount in the OverlayFS.
Many thanks go to [@kmxz](https://github.com/kmxz) for the [overlayfs-tools](https://github.com/kmxz/overlayfs-tools) used to make this possible.

zram-config also allows a 'kiosk mode' which allows loading the entire system root into zram.

The rationale for zram-config is that many distributions have `zram-config` packages that are actually broken, even by name, as often they are a zram-swap-config package in reality.
But even then they do not check for other zram services or change the parameters of swap from HD based configurations to ram optimized ones.
If all you are looking for is a zram-swap utility see [zram-swap-config](https://github.com/StuartIanNaylor/zram-swap-config).
Expand All @@ -32,7 +30,6 @@ Also if the OverlayFS guys would actually make some official merge/snapshot tool
4. [Configure](#customize)
- [Example configuration](#example-configuration)
5. [Is it working?](#is-it-working)
6. [Kiosk mode](#kiosk-mode)
7. [Performance](#performance)
8. [Reference](#reference)

Expand Down Expand Up @@ -185,48 +182,14 @@ KiB Swap: 1331192 total, 1331192 free, 0 used. 412052 avail Mem
9 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_bh
```

### Kiosk mode

zram-config also allows a 'kiosk mode' which allows loading the entire system root into zram.
To enter this mode run `sudo zram-config enable-ephemeral` and reboot.
There is no sync and zdir / zlog entries will be ignored as they are already included.
To exit this mode run `sudo zram-config disable-ephemeral` and reboot.

Credit to <https://blockdev.io/read-only-rpi/> and thanks to the original sources for another great script.

You may need to reboot after the rpi-update and then mkinitramfs -o /boot/initrd as a newer kernel maybe available.
Check the 'Without NFS' section of <https://blockdev.io/read-only-rpi/> as many problems you may have require removal of the SD card and editing `/boot/cmdline.txt` to remove the `init=/bin/ro-root.sh` entry.

```
pi@raspberrypi:~/zram-config $ df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 465976 0 465976 0% /dev
tmpfs 94832 48 94784 1% /mnt/run
/dev/mmcblk0p2 14803620 1280148 12889224 10% /ro
/dev/zram0 991512 5124 918804 1% /rw
overlayfs-root 991512 5124 918804 1% /
tmpfs 474152 0 474152 0% /dev/shm
tmpfs 474152 6356 467796 2% /run
tmpfs 5120 4 5116 1% /run/lock
tmpfs 474152 0 474152 0% /sys/fs/cgroup
/dev/mmcblk0p1 44220 30137 14083 69% /boot
tmpfs 94828 0 94828 0% /run/user/1000
```
```
pi@raspberrypi:~/zram-config $ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4 1000M 19.2M 959.5K 1.4M 4 /rw
/dev/zram1 lz4 750M 4K 76B 4K 4 [SWAP]
```

### Performance

LZO-RLE offers the best performance and is probably the best choice, and from kernel 5.1 and onward it is the default.
You might have text based low impact directories such as `/var/log` or `/var/cache` where a highly effective text compressor such as zstd is optimal, with effective compression that can be up to 200% of what LZO may achieve especially with text.
With `/tmp` and `/run`, zram is unnecessary because of the blisteringly fast ram mounted `tmpfs` and, if memory gets short, then zram swap will provide extra.
With `/tmp` and `/run`, zram is unnecessary because they are RAM mounted as `tmpfs` and, if memory gets short, then the zram swap will provide extra.
It is only under intense loads that the slight overhead of zram compression becomes noticeable.

Until I can find another comparative benchmark that includes all this list is a good yardstick.
This chart from [facebook/zstd](https://github.com/facebook/zstd) provides a good benchmark for the performance of the different compressors.

| Compressor name | Ratio | Compression | Decompress. |
|:-----------------|:------|:------------|:------------|
Expand Down
1 change: 0 additions & 1 deletion install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ install -m 644 zram-config.service /etc/systemd/system/zram-config.service
install -m 644 ztab /etc/ztab
mkdir -p /usr/local/share/zram-config/log
install -m 644 uninstall.bash /usr/local/share/zram-config/uninstall.bash
install -m 644 ro-root.sh /usr/local/share/zram-config/ro-root.sh
install -m 644 zram-config.logrotate /etc/logrotate.d/zram-config
mkdir -p /usr/local/lib/zram-config/
install -m 755 overlayfs-tools/overlay /usr/local/lib/zram-config/overlay
Expand Down
135 changes: 0 additions & 135 deletions ro-root.sh

This file was deleted.

1 change: 0 additions & 1 deletion update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ echo "Updating zram-config files"
install -m 755 zram-config /usr/local/sbin/
install -m 644 zram-config.service /etc/systemd/system/zram-config.service
install -m 644 uninstall.bash /usr/local/share/zram-config/uninstall.bash
install -m 644 ro-root.sh /usr/local/share/zram-config/ro-root.sh
if ! [[ -f /etc/ztab ]]; then
install -m 644 ztab /etc/ztab
fi
Expand Down
70 changes: 11 additions & 59 deletions zram-config
Original file line number Diff line number Diff line change
Expand Up @@ -166,33 +166,6 @@ removeZswap() {
echo "/dev$ZRAM_DEV removed" >> "$ZLOG"
}

enableZephemeral() {
if [[ $ZEPHEMERAL == "false" ]]; then
mkinitramfs -o /boot/initrd
sed -i '/root=PARTUUID/ s|$| init=/bin/ro-root.sh|' /boot/cmdline.txt
echo -e "initramfs initrd followkernel\\nramfsfile=initrd\\nramfsaddr=-1" >> /boot/config.txt
cp "${ZSHARE}/ro-root.sh" /bin/ro-root.sh
chown root:root /bin/ro-root.sh
chmod a+x /bin/ro-root.sh
echo "Zephemeral enabled, after reboot all writes & changes will not be persistent"
else
echo "Zephemeral is already enabled"
fi
}

disableZephemeral() {
if [[ $ZEPHEMERAL == "true" ]]; then
sed -i -e 's| init=/bin/ro-root.sh||g' /boot/cmdline.txt
sed -i -e '/initramfs initrd followkernel/d' /boot/config.txt
sed -i -e '/ramfsfile=initrd/d' /boot/config.txt
sed -i -e '/ramfsaddr=-1/d' /boot/config.txt
rm -f /bin/ro-root.sh
echo "Zephemeral disabled, after reboot system will be write and change enabled"
else
echo "Zephemeral is already disabled"
fi
}

serviceConfiguration() {
if [[ $1 == "stop" ]]; then
echo "Stopping services that interfere with zram device configuration" >> "$ZLOG"
Expand Down Expand Up @@ -222,11 +195,6 @@ ZDIR="/opt/zram"
if [[ $2 == "shutdown" ]]; then
SERVICE="1"
fi
if [[ -f /boot/cmdline.txt ]] && grep -qs "init=/bin/ro-root.sh" /boot/cmdline.txt; then
ZEPHEMERAL="true"
else
ZEPHEMERAL="false"
fi

case "$1" in
start)
Expand Down Expand Up @@ -280,20 +248,16 @@ case "$1" in
dir)
TARGET_DIR="$5"
BIND_DIR="$6"
if [[ $ZEPHEMERAL == "false" ]]; then
serviceConfiguration "stop"
createZdir
fi
serviceConfiguration "stop"
createZdir
;;

log)
TARGET_DIR="$5"
BIND_DIR="$6"
OLDLOG_DIR="$7"
if [[ $ZEPHEMERAL == "false" ]]; then
serviceConfiguration "stop"
createZdir
fi
serviceConfiguration "stop"
createZdir
;;
esac
;;
Expand Down Expand Up @@ -338,24 +302,20 @@ case "$1" in
ZRAM_DEV="$2"
TARGET_DIR="$3"
BIND_DIR="$4"
if [[ $ZEPHEMERAL == "false" ]]; then
if [[ -z $SERVICE ]]; then
serviceConfiguration "stop"
fi
removeZdir
if [[ -z $SERVICE ]]; then
serviceConfiguration "stop"
fi
removeZdir
;;

log)
ZRAM_DEV="$2"
TARGET_DIR="$3"
BIND_DIR="$4"
if [[ $ZEPHEMERAL == "false" ]]; then
if [[ -z $SERVICE ]]; then
serviceConfiguration "stop"
fi
removeZdir
if [[ -z $SERVICE ]]; then
serviceConfiguration "stop"
fi
removeZdir
;;
esac
;;
Expand All @@ -364,16 +324,8 @@ case "$1" in
rm -fv "${TMPDIR}"/zram-device-list.rev "${TMPDIR}"/zram-device-list >> "$ZLOG"
;;

enable-ephemeral)
enableZephemeral
;;

disable-ephemeral)
disableZephemeral
;;

*)
echo "Usage: zram-config {start|stop|enable-ephemeral|disable-ephemeral}" > 2
echo "Usage: zram-config {start|stop}" > 2
exit 1
;;
esac
Expand Down

0 comments on commit 9693730

Please sign in to comment.