How would I persistently set a Linux kernel parameter?

How would I persistently set a Linux kernel parameter? Please give me an example.

To persistently set a Linux kernel parameter, you typically need to modify the system's bootloader configuration file. The specific steps and file location can vary depending on the Linux distribution and bootloader in use. Here's an example of persistently setting a kernel parameter using the GRUB bootloader:

  1. Identify the Bootloader Configuration File:

    • The GRUB bootloader configuration file is typically located at /etc/default/grub or /etc/grub.d/.
    • Open a terminal and navigate to the appropriate directory for your system.
  2. Edit the Bootloader Configuration File:

    • Open the bootloader configuration file using a text editor with root privileges.
      sudo vi /etc/default/grub
  3. Find the Kernel Parameter Line:

    • Look for the line starting with GRUB_CMDLINE_LINUX or GRUB_CMDLINE_LINUX_DEFAULT.
    • This line specifies the kernel parameters passed to the Linux kernel during boot.
  4. Add or Modify the Kernel Parameter:

    • Add or modify the kernel parameter within the quotation marks.
    • For example, to set the net.core.somaxconn parameter to 2048, you would add or modify the line to:
      GRUB_CMDLINE_LINUX="net.core.somaxconn=2048"
  5. Save and Close the File:

    • Save the changes you made to the bootloader configuration file.
    • Close the text editor.
  6. Update the Bootloader Configuration:

    • Run the command to update the bootloader configuration based on the changes made.
      sudo update-grub
  7. Reboot the System:

    • Restart the system for the changes to take effect.
      sudo reboot

After rebooting, the Linux kernel parameter you set in the bootloader configuration file will be applied persistently.

Please note that the specific steps may differ based on your Linux distribution and the bootloader in use (e.g., GRUB, LILO, systemd-boot). It's recommended to refer to the documentation or support resources specific to your distribution and bootloader for accurate instructions.

You should also read: