Skip to content

Commit cbe16bf

Browse files
authored
Merge pull request #3636 from gizmo98/compressed-memory
raspbiantools: Add option to enable compressed memory (ZRAM)
2 parents 90f64e6 + 06f38ff commit cbe16bf

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

scriptmodules/supplementary/raspbiantools.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,46 @@ function enable_modules_raspbiantools() {
125125
done
126126
}
127127

128+
function enable_zram_raspbiantools() {
129+
if [[ "$__os_id" == "Raspbian" ]] || [[ "$__os_id" == "Debian" ]]; then
130+
aptInstall zram-tools
131+
# Use 50% of the current memory for ZRAM
132+
local percent="50"
133+
iniConfig "=" "" "/etc/default/zramswap"
134+
# Raspbian Buster uses keyword PERCENTAGE
135+
iniSet "PERCENTAGE" "$percent"
136+
# Debian Bullseye/Bookworm use keyword PERCENT
137+
iniSet "PERCENT" "$percent"
138+
# Use zstd compression algorithm if kernel supports it
139+
[[ -f /sys/class/block/zram0/comp_algorithm ]] && [[ "$(cat /sys/class/block/zram0/comp_algorithm)" == *zstd* ]] && iniSet "ALGO" "zstd"
140+
service zramswap stop
141+
service zramswap start
142+
elif [[ "$__os_id" == "Ubuntu" ]]; then
143+
aptInstall zram-config
144+
# Ubuntu has a automatic zram configuration
145+
fi
146+
}
147+
148+
function disable_zram_raspbiantools() {
149+
if [[ "$__os_id" == "Raspbian" ]] || [[ "$__os_id" == "Debian" ]]; then
150+
apt remove -y zram-tools
151+
elif [[ "$__os_id" == "Ubuntu" ]]; then
152+
apt remove -y zram-config
153+
fi
154+
}
155+
128156
function gui_raspbiantools() {
129157
while true; do
158+
local zram_status="Enable"
159+
[[ $(cat /proc/swaps) == *zram* ]] && zram_status="Disable"
130160
local cmd=(dialog --backtitle "$__backtitle" --menu "Choose an option" 22 76 16)
131161
local options=(
132162
1 "Upgrade Raspbian packages"
133163
2 "Install Pixel desktop environment"
134164
3 "Remove some unneeded packages (pulseaudio / cups / wolfram)"
135165
4 "Disable screen blanker"
136166
5 "Enable needed kernel module uinput"
167+
6 "$zram_status compressed memory (ZRAM)"
137168
)
138169
local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
139170
if [[ -n "$choice" ]]; then
@@ -155,6 +186,9 @@ function gui_raspbiantools() {
155186
5)
156187
rp_callModule "$md_id" enable_modules
157188
;;
189+
6)
190+
[[ "$zram_status" == "Enable" ]] && rp_callModule "$md_id" enable_zram || rp_callModule "$md_id" disable_zram
191+
;;
158192
esac
159193
else
160194
break

0 commit comments

Comments
 (0)