SoFunction
Updated on 2025-03-09

Automatically load kernel module overlayfs operation when CentOS starts

Automatically load kernel modules in CentOS, you can add a script to the /etc/sysconfig/modules/ directory to load the required modules in this script.

Here is a script I'm using called to automatically load the overlayfs module in my CentOS:

#! /bin/sh

/sbin/modinfo -F filename overlayfs> /dev/null 2>&1
if [ $? -eq 0 ]; then
 /sbin/modprobe overlayfs
fi

The script first checks whether the overlayfs module file exists. If it exists, call the /sbin/modprobe command to load this module.

Place this file in the /etc/sysconfig/modules/ directory and add executable permissions to it. In this way, the module will be automatically loaded the next time the system is restarted.

Supplementary knowledge:Centos7 automatic loading module ko

Suppose there is now a kernel module file name

1. The preferred copy of the compiled module to the kernel device directory

sudo cp /lib/modules/$(uname -r)/kernel/drivers/

2. Create a module startup file

sudo cat > /etc// <<EOF
# Load  at boot
c1004
EOF

3. Update the module and restart

sudo depmod

reboot

4. After restarting, check whether the module has been installed normally

lsmod |grep c1004

# The output is similar to the following description of auto-start OKc1004     30081 0

If you run insmod and report an error, you need to recompile the driver file.

Uninstall driver rmmod c1004

The above article automatically loading the kernel module overlayfs operation when CentOS is started is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.