[Solved] ZRam service is failing to start

Ask for help with issues regarding the Installations of the Debian O/S.
Post Reply
Message
Author
ganeshmallyap
Posts: 32
Joined: 2011-02-14 10:41
Has thanked: 10 times
Been thanked: 1 time

[Solved] ZRam service is failing to start

#1 Post by ganeshmallyap »

Hello Friends,

I tried enabling ZRam on my debian 12.8 KDE 64 bits desktop computer (Dell Otiplex op3020 CFF). Installation was succesful. I cooul see zramswap service status as active. But on reboot, I see a message - [FAILED] - Failed to start zramswap.service - Linux zramswap setup. I am not sure what is causing this. On login, I tried to check the service status. Here is the output -

Code: Select all

ganeshp@aga-op3020:~$ systemctl status zramswap.service
× zramswap.service - Linux zramswap setup
     Loaded: loaded (/lib/systemd/system/zramswap.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Sun 2024-12-08 11:28:14 IST; 5min ago
       Docs: man:zramswap(8)
    Process: 866 ExecStart=/usr/sbin/zramswap start (code=exited, status=1/FAILURE)
   Main PID: 866 (code=exited, status=1/FAILURE)
        CPU: 9ms

Dec 08 11:28:14 aga-op3020 systemd[1]: Starting zramswap.service - Linux zramswap setup...
Dec 08 11:28:14 aga-op3020 root[869]: Starting Zram
Dec 08 11:28:14 aga-op3020 zramswap[869]: <13>Dec  8 11:28:14 root: Starting Zram
Dec 08 11:28:14 aga-op3020 zramswap[866]: /usr/sbin/zramswap: line 53: echo: write error: Device or resource busy
Dec 08 11:28:14 aga-op3020 root[896]: Error: setting compression algo to zstd
Dec 08 11:28:14 aga-op3020 zramswap[896]: <13>Dec  8 11:28:14 root: Error: setting compression algo to zstd
Dec 08 11:28:14 aga-op3020 systemd[1]: zramswap.service: Main process exited, code=exited, status=1/FAILURE
Dec 08 11:28:14 aga-op3020 systemd[1]: zramswap.service: Failed with result 'exit-code'.
Dec 08 11:28:14 aga-op3020 systemd[1]: Failed to start zramswap.service - Linux zramswap setup.
ganeshp@aga-op3020:~$ sudo systemctl restart  zramswap.service
Job for zramswap.service failed because the control process exited with error code.
See "systemctl status zramswap.service" and "journalctl -xeu zramswap.service" for details.
ganeshp@aga-op3020:~$ sudo journalctl -xeu zramswap.service
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit zramswap.service has finished with a failure.
░░ 
░░ The job identifier is 2215 and the job result is failed.
Dec 08 11:35:03 aga-op3020 systemd[1]: Starting zramswap.service - Linux zramswap setup...
░░ Subject: A start job for unit zramswap.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit zramswap.service has begun execution.
░░ 
░░ The job identifier is 2344.
Dec 08 11:35:03 aga-op3020 zramswap[2954]: /usr/sbin/zramswap: line 53: echo: write error: Device or resource busy
Dec 08 11:35:03 aga-op3020 root[2958]: Error: setting compression algo to zstd
Dec 08 11:35:03 aga-op3020 zramswap[2958]: <13>Dec  8 11:35:03 root: Error: setting compression algo to zstd
Dec 08 11:35:03 aga-op3020 systemd[1]: zramswap.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ An ExecStart= process belonging to unit zramswap.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Dec 08 11:35:03 aga-op3020 systemd[1]: zramswap.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit zramswap.service has entered the 'failed' state with result 'exit-code'.
Dec 08 11:35:03 aga-op3020 systemd[1]: Failed to start zramswap.service - Linux zramswap setup.
░░ Subject: A start job for unit zramswap.service has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit zramswap.service has finished with a failure.
░░ 
░░ The job identifier is 2344 and the job result is failed.


I had refered to documentation available at https://wiki.debian.org/ZRam and some other online material to configure ZRam. Here is the bash script I had used to install and configure -

Code: Select all

#!/bin/bash


function enable_zram_swap()
{
	#  for more details on the below please visit url https://wiki.debian.org/ZRam
	local myResponse

	printf "\n\nDo you want to install and enable ZRam on your computer?  If yes, please disable any other forms of swap and rerun this option. (y/n) : "
	read -r -n 1 myResponse

	# validate user input
	if [[ "$myResponse" != 'y' ]]
	then
		cancel_function_message
		return 1
	fi

	printf "\n\nAttempting to install zram-tools.\n\n" 
	apt update
	apt install zram-tools -y

	printf "\n\nEnter swappiness for ZRam swap.  Default value is 60 : "
	read -r -n 3 myResponse

	# if invalid valueentered, then assign 60 default value
	check_valid_number "$myResponse" || myResponse=60

	# configure zram 
	printf "ALGO=zstd\nPERCENT=%s\n" "$myResponse" | tee -a /etc/default/zramswap
	systemctl restart zramswap || return

	# refer to Debian documentation for details.
	printf "\n\nAttempting to install insserv.\n\n"
	apt install insserv -y
	insserv zramswap

	# install systemd-zram-generator
	printf "\n\nAttempting to install systemd-zram-generator.\n\n"
	apt install systemd-zram-generator -y

	# reload the deamon
	systemctl daemon-reload
	systemctl start /dev/zram0 || return
	systemctl enable --now zramswap

	# display the zram status
	printf "\n\nZRam enabled successfully. Showing the ZRam status.\n\n"
	zramctl || return

	printf "\n showing output of lsblk.\n"
	lsblk
	printf "\n\n"
	return 0
}

enable_zram_swap
I am not sure if I missed something important in the above script. I remember seeing a error while executing the command - insserv zramswap in above script. Here is the error message when I reproduced it from konsole -

Code: Select all

ganeshp@aga-op3020:~$ sudo insserv zramswap
insserv: zramswap: No such file or directory
ganeshp@aga-op3020:~$ lsblk
NAME                   MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda                      8:0    0 953.9G  0 disk  
├─sda1                   8:1    0   512M  0 part  /boot/efi
├─sda2                   8:2    0   1.9G  0 part  /boot
└─sda3                   8:3    0 951.5G  0 part  
  └─sda3_crypt         253:0    0 951.5G  0 crypt 
    ├─aga--vg-lv--home 253:1    0 107.9G  0 lvm   /home
    ├─aga--vg-lv--root 253:2    0 139.7G  0 lvm   /
    └─aga--vg-lv--data 253:3    0 703.8G  0 lvm   /data
zram0                  252:0    0     4G  0 disk  [SWAP]
ganeshp@aga-op3020:~$ sudo swapon --show
NAME       TYPE      SIZE USED PRIO
/dev/zram0 partition   4G   0B  100
Any advise to fix this issue would be very helpful. Thanks in advance.

Regards
Ganesh

User avatar
bbbhltz
Section Moderator
Section Moderator
Posts: 340
Joined: 2024-01-10 14:53
Location: Normandy
XMMP/Jabber: bbbhltz@mailbox.org
Has thanked: 72 times
Been thanked: 81 times

Re: ZRam service is failing to start

#2 Post by bbbhltz »

Hello. If I were you, I would manually enter the commands from the script one by one and see if that error is an error or just a warning.

Also, can you show us the contents of /etc/default/zramswap?
bbbhltz
longtime desktop Linux user; eternal newbie

ganeshmallyap
Posts: 32
Joined: 2011-02-14 10:41
Has thanked: 10 times
Been thanked: 1 time

Re: ZRam service is failing to start

#3 Post by ganeshmallyap »

bbbhltz wrote: 2024-12-08 09:55 Hello. If I were you, I would manually enter the commands from the script one by one and see if that error is an error or just a warning.

Also, can you show us the contents of /etc/default/zramswap?
Hello @bbbhltz, thank you for your time and attention. Here are the contents of the file.

Code: Select all

ganeshp@aga-op3020:~$ cat /etc/default/zramswap
# Compression algorithm selection
# speed: lz4 > zstd > lzo
# compression: zstd > lzo > lz4
# This is not inclusive of all that is available in latest kernels
# See /sys/block/zram0/comp_algorithm (when zram module is loaded) to see
# what is currently set and available for your kernel[1]
# [1]  https://github.com/torvalds/linux/blob/master/Documentation/blockdev/zram.txt#L86
#ALGO=lz4

# Specifies the amount of RAM that should be used for zram
# based on a percentage the total amount of available memory
# This takes precedence and overrides SIZE below
#PERCENT=50

# Specifies a static amount of RAM that should be used for
# the ZRAM devices, this is in MiB
#SIZE=256

# Specifies the priority for the swap devices, see swapon(2)
# for more details. Higher number = higher priority
# This should probably be higher than hdd/ssd swaps.
#PRIORITY=100
ALGO=zstd
PERCENT=60
I have 3 desktop computers on my home subnet. On the first machine I typed each command individually and completed the process. Once I saw the service running as expected, I wrote a script to copy the ssteps on other two machines. I did not get any errors except at the following command.

Code: Select all

ganeshp@aga-op3020:~$ sudo insserv zramswap
insserv: zramswap: No such file or directory
Here are the complete list of commands I had executed to enable ZRam on my desktop -

Code: Select all

apt update
apt install zram-tools -y
printf "ALGO=zstd\nPERCENT=60\n" | tee -a /etc/default/zramswap
systemctl restart zramswap
apt install insserv -y
insserv zramswap
apt install systemd-zram-generator -y
systemctl daemon-reload
systemctl start /dev/zram0
systemctl enable --now zramswap
zramctl
lsblk
Regards
Ganesh

User avatar
bbbhltz
Section Moderator
Section Moderator
Posts: 340
Joined: 2024-01-10 14:53
Location: Normandy
XMMP/Jabber: bbbhltz@mailbox.org
Has thanked: 72 times
Been thanked: 81 times

Re: ZRam service is failing to start

#4 Post by bbbhltz »

For insserv zramswap I think you might need to put in the full path

I have no idea what innserv is but the manpage does say it accepts a script as an argument, with an optional path.

Try

Code: Select all

# insserv zramswap /usr/sbin/zramswap
(or find where the script is located)
bbbhltz
longtime desktop Linux user; eternal newbie

ganeshmallyap
Posts: 32
Joined: 2011-02-14 10:41
Has thanked: 10 times
Been thanked: 1 time

Re: ZRam service is failing to start

#5 Post by ganeshmallyap »

Hello @bbbhltz,

It was my bad. Command insserv zramswap was needed only for sysinit systems only (https://wiki.debian.org/ZRam). So we can ignore that step for now. I will also correct my script accordingly. I have now removed the package insserv and restarted the computer. Issue still remains the same.

Regards
Ganesh

CwF
Global Moderator
Global Moderator
Posts: 3140
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 63 times
Been thanked: 268 times

Re: ZRam service is failing to start

#6 Post by CwF »

ganeshmallyap wrote: 2024-12-08 16:16 Issue still remains the same.
I'm unclear of the issue here. The process should be install the package and reboot...
No script, no manual configuration.

One issue from the reference page
The packages zram-tools and systemd-zram-generator can be used to automatically setup zram devices.
This should read
The packages zram-tools or systemd-zram-generator can be used to automatically setup zram devices.

Not both
Mottainai

ganeshmallyap
Posts: 32
Joined: 2011-02-14 10:41
Has thanked: 10 times
Been thanked: 1 time

[Solved] Re: ZRam service is failing to start

#7 Post by ganeshmallyap »

Hello @CwF,

Your suggestion worked perfectly fine. Thanks a ton.

Regards
Ganesh

Post Reply