Skip to content

Commit 4f4e6d5

Browse files
authored
Update zram.sh
1 parent d75ebfe commit 4f4e6d5

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

scripts/zram.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,40 @@ define_zram() {
2626
if [[ $zram_size =~ ^[0-9]+$ ]]; then
2727
echo "Creating ZRAM of size ${zram_size}MB..."
2828
sudo modprobe zram
29-
echo "zram" > /sys/block/zram0/disksize
3029
sudo bash -c "echo $(($zram_size * 1024 * 1024)) > /sys/block/zram0/disksize"
3130
sudo mkswap /dev/zram0
3231
sudo swapon /dev/zram0
33-
echo "ZRAM created and activated."
32+
echo "$zram_size" | sudo tee /etc/zram_config > /dev/null
33+
echo "ZRAM created and activated. Configuration saved."
3434
else
3535
echo "Invalid size entered. Please enter a numeric value in MB."
3636
fi
3737
}
3838

39+
restore_zram() {
40+
if [[ -f /etc/zram_config ]]; then
41+
zram_size=$(cat /etc/zram_config)
42+
echo "Restoring ZRAM of size ${zram_size}MB..."
43+
sudo modprobe zram
44+
sudo bash -c "echo $(($zram_size * 1024 * 1024)) > /sys/block/zram0/disksize"
45+
sudo mkswap /dev/zram0
46+
sudo swapon /dev/zram0
47+
echo "ZRAM restored and activated."
48+
fi
49+
}
50+
3951
delete_zram() {
4052
echo "Removing ZRAM..."
4153
sudo swapoff /dev/zram0
4254
sudo modprobe -r zram
43-
echo "ZRAM removed."
55+
sudo rm -f /etc/zram_config
56+
echo "ZRAM removed and configuration deleted."
4457
}
4558

4659
install_prerequisites
4760

61+
restore_zram
62+
4863
while true; do
4964
echo "Choose an option:"
5065
echo "1 - Create ZRAM"

0 commit comments

Comments
 (0)