How To Enable ZRAM On Rocky Linux And Other RHEL-Based Distributions
- by Tech Today News
- Posted on January 26, 2023
If you’re trying to eke as much speed from your RHEL-based Linux distribution as possible, you might want to try zRAM. The Linux kernel module zRAM uses compressed RAM for swap space instead of the traditional partition. Even though using zRAM consumes more central processing unit cycles, the increase in speed you’ll experience having a larger RAM-based swap on Linux makes the trade-off worth it. Plus, the CPU zRAM usage is minimal, and you’ll never notice the CPU hit. Most Linux distributions come with the zRAM kernel module in place. I’ll show you how to enable zRAM for Rocky Linux, but these instructions will work for most RHEL-based distributions. SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium) Jump to: You only need two things to follow the steps in this tutorial: a user with sudo privileges and a running instance of Rocky Linux. However, even if you’re using a different RHEL-based distribution such as RHEL, AlmaLinux or CentOS Stream, you’re good to go. First, create a file that will load the zRAM kernel module with the command:
In that file, paste the following:
Save and close the file. Next, we’ll create a configuration file for the kernel module with the following:
In that file, paste the following contents:
Save and close the file. Now, we need to configure the size of the zRAM partition. Create a new udev rule with the command:
In that file, paste the following, which configures a 2GB zRAM partition:
Save and close the file. To disable traditional swap, open the fstab file with the following:
In that file, comment out the swap entry by adding a # character to the beginning of the line. Save and close the file. Next, we must create a systemd unit file with the command:
In that file, paste the following contents:
Save and close the file. Enable the zRAM unit with the command:
Finally, reboot your system, and then verify zRAM is being used with the command:
The output should include something like this:
Enabling zRAM for your Linux systems will give you a quick and easy performance boost, and you won’t find any reliability issues using this system. Give zRAM a try on your test machines before doing it on production systems. Once you’re convinced it’s worth the effort, use zRAM on your production machines and start enjoying the results. Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.What you need to enable zRAM
How to enable zRAM on Rocky Linux
sudo nano /etc/modules-load.d/zram.conf
zram
sudo nano /etc/modprobe.d/zram.conf
options zram num_devices=1
sudo nano /etc/udev/rules.d/99-zram.rules
KERNEL=="zram0", ATTR{disksize}="2G",TAG+="systemd"
sudo nano /etc/fstab
sudo nano /etc/systemd/system/zram.service
[Unit]
Description=Swap with zram
After=multi-user.target[Service]
Type=oneshot
RemainAfterExit=true
ExecStartPre=/sbin/mkswap /dev/zram0
ExecStart=/sbin/swapon /dev/zram0
ExecStop=/sbin/swapoff /dev/zram0[Install]
WantedBy=multi-user.targetsudo systemctl enable zram
zramctl
/dev/zram0 lzo-rle 2G 4K 74B 12K 1 [SWAP]
Get a performance boost for your Linux systems
If you’re trying to eke as much speed from your RHEL-based Linux distribution as possible, you might want to try zRAM. Illustration: Lisa Hornung/TechRepublic The Linux kernel module zRAM uses compressed RAM for swap space instead of the traditional partition. Even though using zRAM consumes more central processing unit cycles, the increase in speed you’ll…