Change swap size on start if needed

balenaOS now creates a /dev/zram0 device sized as min(25% of ram, 1G)
which on EtcherPro is 256M. We need 1G, so we resize it on start if
the amount is not 1G.
Also modprobe is no longer necessary as zram is built into the kernel.

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-10-23 13:04:39 +02:00
parent 86fb91ec9d
commit 32bd9efa11
3 changed files with 6 additions and 9 deletions

View File

@ -44,11 +44,6 @@ WORKDIR /usr/src/app/node_modules/.bin
RUN ln -s ../electron/cli.js electron RUN ln -s ../electron/cli.js electron
WORKDIR /usr/src/app WORKDIR /usr/src/app
RUN \
apt-get update \
&& apt-get install -y kmod \
&& rm -rf /var/lib/apt/lists/*
CMD \ CMD \
./zram.sh \ ./zram.sh \
&& node /usr/src/app/update-config-and-start.js && node /usr/src/app/update-config-and-start.js

View File

@ -14,7 +14,6 @@ services:
labels: labels:
io.balena.features.dbus: 1 io.balena.features.dbus: 1
io.balena.features.supervisor-api: 1 io.balena.features.supervisor-api: 1
io.balena.features.kernel-modules: 1
volumes: volumes:
- 'etcher_pki:/root/.pki' - 'etcher_pki:/root/.pki'
- 'etcher_cache:/root/.cache' - 'etcher_cache:/root/.cache'

View File

@ -1,10 +1,13 @@
#!/bin/bash #!/bin/bash
DEVICE=/dev/zram0 DEVICE=/dev/zram0
SIZE=1G
if [ ! -b $DEVICE ]; then CURRENT_SIZE=$(zramctl --raw --noheadings --output DISKSIZE $DEVICE)
modprobe zram
zramctl $DEVICE --size 1024M if [ $CURRENT_SIZE != $SIZE ]; then
swapoff $DEVICE
zramctl $DEVICE --algorithm lz4 --size $SIZE
mkswap $DEVICE mkswap $DEVICE
swapon $DEVICE swapon $DEVICE
fi fi