Skip to content

Commit 494a157

Browse files
authored
Update zram.sh
1 parent 6751ef5 commit 494a157

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

scripts/zram.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ define_zram() {
3131
sudo swapon /dev/zram0
3232
echo "$zram_size" | sudo tee /etc/zram_config > /dev/null
3333
echo "ZRAM created and activated. Configuration saved."
34+
35+
if ! grep -q "/etc/rc.local" /etc/rc.local; then
36+
echo "#!/bin/bash" | sudo tee /etc/rc.local > /dev/null
37+
sudo chmod +x /etc/rc.local
38+
fi
39+
sudo sed -i '/exit 0/d' /etc/rc.local
40+
sudo bash -c 'cat <<EOL >> /etc/rc.local
41+
if [[ -f /etc/zram_config ]]; then
42+
zram_size=\$(cat /etc/zram_config)
43+
modprobe zram
44+
echo \$((zram_size * 1024 * 1024)) > /sys/block/zram0/disksize
45+
mkswap /dev/zram0
46+
swapon /dev/zram0
47+
fi
48+
exit 0
49+
EOL'
3450
else
3551
echo "Invalid size entered. Please enter a numeric value in MB."
3652
fi
@@ -53,13 +69,15 @@ delete_zram() {
5369
sudo swapoff /dev/zram0
5470
sudo modprobe -r zram
5571
sudo rm -f /etc/zram_config
72+
sudo sed -i '/zram_config/,+5d' /etc/rc.local
5673
echo "ZRAM removed and configuration deleted."
5774
}
5875

5976
install_prerequisites
6077

6178
restore_zram
6279

80+
# Menu for user interaction
6381
while true; do
6482
echo "Choose an option:"
6583
echo "1 - Create ZRAM"

0 commit comments

Comments
 (0)