Setting kernel parameters linux

Chapter 40. Configuring kernel command-line parameters

Kernel command-line parameters are a way to change the behavior of certain aspects of the Red Hat Enterprise Linux kernel at boot time. As a system administrator, you have full control over what options get set at boot. Certain kernel behaviors are only able to be set at boot time, so understanding how to make these changes is a key administration skill.

Opting to change the behavior of the system by modifying kernel command-line parameters may have negative effects on your system. You should therefore test changes prior to deploying them in production. For further guidance, contact Red Hat Support.

40.1. Understanding kernel command-line parameters

Kernel command-line parameters are used for boot time configuration of:

  • The Red Hat Enterprise Linux kernel
  • The initial RAM disk
  • The user space features

Kernel boot time parameters are often used to overwrite default values and for setting specific hardware settings.

By default, the kernel command-line parameters for systems using the GRUB bootloader are defined in the kernelopts variable of the /boot/grub2/grubenv file for each kernel boot entry.

For IBM Z, the kernel command-line parameters are stored in the boot entry configuration file because the zipl bootloader does not support environment variables. Thus, the kernelopts environment variable cannot be used.

Additional resources

40.2. What grubby is

grubby is a utility for manipulating boot loader configuration files.

You can also use grubby for changing the default boot entry, and for adding or removing arguments from a GRUB2 menu entry.

Additional resources

40.3. What boot entries are

A boot entry is a collection of options which are stored in a configuration file and tied to a particular kernel version. In practice, you have at least as many boot entries as your system has installed kernels. The boot entry configuration file is located in the /boot/loader/entries/ directory and can look like this:

6f9cc9cb7d7845d49698c9537337cedc-4.18.0-5.el8.x86_64.conf

The file name above consists of a machine ID stored in the /etc/machine-id file, and a kernel version.

The boot entry configuration file contains information about the kernel version, the initial ramdisk image, and the kernelopts environment variable, which contains the kernel command-line parameters. The example contents of a boot entry config can be seen below:

title Red Hat Enterprise Linux (4.18.0-74.el8.x86_64) 8.0 (Ootpa) version 4.18.0-74.el8.x86_64 linux /vmlinuz-4.18.0-74.el8.x86_64 initrd /initramfs-4.18.0-74.el8.x86_64.img $tuned_initrd options $kernelopts $tuned_params id rhel-20190227183418-4.18.0-74.el8.x86_64 grub_users $grub_users grub_arg --unrestricted grub_class kernel

The kernelopts environment variable is defined in the /boot/grub2/grubenv file.

Читайте также:  Linux клиенты удаленного доступа

Additional resources

40.4. Changing kernel command-line parameters for all boot entries

Change kernel command-line parameters for all boot entries on your system.

Prerequisites

  • Verify that the grubby utility is installed on your system.
  • Verify that the zipl utility is installed on your IBM Z system.
# grubby --update-kernel=ALL --args emphasis">NEW_PARAMETER>"

For systems that use the GRUB bootloader, the command updates the /boot/grub2/grubenv file by adding a new kernel parameter to the kernelopts variable in that file.

# grubby --update-kernel=ALL --remove-args emphasis">PARAMETER_TO_REMOVE>"
# grub2-mkconfig -o /etc/grub2.cfg

Newly installed kernels do not inherit the kernel command-line parameters from your previously configured kernels. You must run the grub2-mkconfig command on the newly installed kernel to propagate the needed parameters to your new kernel.

Additional resources

40.5. Changing kernel command-line parameters for a single boot entry

Make changes in kernel command-line parameters for a single boot entry on your system.

Prerequisites

# grubby --update-kernel=/boot/vmlinuz-$(uname -r) --args emphasis">NEW_PARAMETER>"
# grubby --update-kernel=/boot/vmlinuz-$(uname -r) --remove-args emphasis">PARAMETER_TO_REMOVE>"

On systems that use the grub.cfg file, there is, by default, the options parameter for each kernel boot entry, which is set to the kernelopts variable. This variable is defined in the /boot/grub2/grubenv configuration file.

  • If the kernel command-line parameters are modified for all boot entries, the grubby utility updates the kernelopts variable in the /boot/grub2/grubenv file.
  • If kernel command-line parameters are modified for a single boot entry, the kernelopts variable is expanded, the kernel parameters are modified, and the resulting value is stored in the respective boot entry’s /boot/loader/entries/ file.
  • grubby modifies and stores the kernel command-line parameters of an individual kernel boot entry in the /boot/loader/entries/< ENTRY >.conf file.

Additional resources

40.6. Changing kernel command-line parameters temporarily at boot time

Make temporary changes to a Kernel Menu Entry by changing the kernel parameters only during a single boot process.

  1. Select the kernel you want to start when the GRUB 2 boot menu appears and press the e key to edit the kernel parameters.
  2. Find the kernel command line by moving the cursor down. The kernel command line starts with linux on 64-Bit IBM Power Series and x86-64 BIOS-based systems, or linuxefi on UEFI systems.
  3. Move the cursor to the end of the line.

Press Ctrl + a to jump to the start of the line and Ctrl + e to jump to the end of the line. On some systems, Home and End keys might also work.

linux ($root)/vmlinuz-4.18.0-348.12.2.el8_5.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet emergency

Press Esc key to leave command line editing and it will drop all the user made changes.

This procedure applies only for a single boot and does not persistently make the changes.

40.7. Configuring GRUB settings to enable serial console connection

The serial console is beneficial when you need to connect to a headless server or an embedded system and the network is down. Or when you need to avoid security rules and obtain login access on a different system.

You need to configure some default GRUB settings to use the serial console connection.

Prerequisites

    Add the following two lines to the /etc/default/grub file:

GRUB_TERMINAL="serial" GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"
# grub2-mkconfig -o /boot/grub2/grub.cfg
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

Источник

How to tune kernel parameters in Linux

In this article we will be discussing how to set or tune the kernel parameter in any Linux system. There are many ways you can do it like setting them in their configuration files or using a system control command sysctl .

sysctl command is used to configure kernel parameters at runtime. Your current kernel parameters values can be viewed with -a switch.

# sysctl -a abi.vsyscall32 = 1 crypto.fips_enabled = 0 debug.exception-trace = 1 debug.kprobes-optimization = 1 dev.hpet.max-user-freq = 64 dev.mac_hid.mouse_button2_keycode = 97 dev.mac_hid.mouse_button3_keycode = 100 dev.mac_hid.mouse_button_emulation = 0 dev.parport.default.spintime = 500 ----- output clipped -----

In the above output you can see parameters on left and their current value on the right. Parameters are sorted with alphabetical order and both columns in output are delimited with = sign so that you can sort this output easily using this delimiter.

There are a few parameters you can even view using the proc file system. You can cat their respective files and view values.

# cat /proc/sys/kernel/shmmni 2048

In above example we can see shmmni value is set to 2048.

How to tune kernel parameter

To change the kernel parameter you can define it under configuration file /etc/sysctl.conf and it will be applied at the next reboot. You need to define parameter=value format in this file (ex. kernel.shmmni=4096).

Each new line represents a new parameter and value pair. Values in this file will be loaded at the next reboot. If you want to load this file immediately then you can can do it by using sysctl -p command. It will load /etc/sysctl.conf file in kernel. You can even define values with -w switch explained below.

To change the kernel parameter using sysctl , you should use a write switch -w along with parameter and value. In the below example we are changing kernel.shmmni value to 2048.

# sysctl kernel.shmmni kernel.shmmni = 4096 # sysctl -w kernel.shmmni=2048 kernel.shmmni = 2048

You can observe previously kernel.shmmni value was 4096, using -w we changed it to 2048. This change is immediate and does not need a reboot to comes in effect.

Источник

About Kernel Boot Parameters

This document provides simple instructions for adding a Linux kernel boot parameter to an Ubuntu system using GRUB 2.

When advised to try using a particular kernel boot parameter, it is usually a good idea to first add the parameter temporarily for testing. Once you have determined that adding the parameter has the desired effect, you can then add it permanently. Directions for both methods are below.

  • are case-sensitive
  • are sometimes just a simple word («splash» or «noapic«)
  • sometimes have an = sign with various possible values («acpi_backlight=vendor«)
  • sometimes include punctuation («i8042.noloop«)

Always enter kernel boot parameters exactly as advised. Errors in spelling or formatting or invalid values will not result in any error message, they will simply have no effect.

A complete list of parameters supported by the latest mainline kernel is available at The kernel’s command-line parameters.

Temporarily Add a Kernel Boot Parameter for Testing

  1. Restart your system, or shut it down and then power it on again.
  2. As the system starts to boot repeated tap the Esc key in order to force the «GNU GRUB» menu to appear. For BIOS-mode (not UEFI-mode) booting a SHIFT key can be held down continuously until the menu appears. The «GNU GRUB» menu will look something like this:
https://wiki.ubuntu.com/Kernel/KernelBootParameters?action=AttachFile&do=get&target=grub2_default_menu.png
The Grub menu allows for choosing between different boot targets and modes
  • If the system hangs at the initial vendor logo screen when you hold down SHIFT, just release the SHIFT key briefly then hold it down again until the «GNU GRUB» menu appears.
    Once the «GNU GRUB» menu appears highlight the desired entry and press the e key to enter edit mode. The edit mode screen will look something like this:
    https://wiki.ubuntu.com/Kernel/KernelBootParameters?action=AttachFile&do=get&target=grub2_menu_editing.png
    By editing the linux line, kernel and initrd parameters can be modified for just a single boot

    Note: The parameter(s) you’ve added to the linux line are only temporary: They will affect this boot session, but once you restart the system they will no longer be in effect.

    Permanently Add a Kernel Boot Parameter

    1. Log in to the system and start a terminal window (Applications->Accessories->Terminal).
    2. In the terminal window at the $ prompt, enter the command: sudo gedit /etc/default/grub
      • Enter your password when prompted by [sudo].
      • If the file /etc/default/grub appears to be empty or does not exist, see the instructions for earlier releases above).
    3. In the editor window, use the arrow keys to move the cursor to the line beginning with «GRUB_CMDLINE_LINUX_DEFAULT» then edit that line, adding your parameter(s) to the text inside the double-quotes after the words «quiet splash«. (Be sure to add a SPACE after «splash» before adding your new parameter.) Click the Save button, then close the editor window.
    4. In the terminal window at the $ prompt, enter the command: sudo update-grub
    5. Restart the system.

    Note: The parameter(s) you’ve added to the GRUB_CMDLINE_LINUX_DEFAULT line are persistent, and will be in effect for every subsequent boot session (unless you remove them by repeating the procedure above).

    Kernel/KernelBootParameters (последним исправлял пользователь merlijn-sebrechts 2022-12-02 14:25:41)

    The material on this wiki is available under a free license, see Copyright / License for details.

    Источник

Оцените статью
Adblock
detector