A Guide to Using the kexec Command (with examples)

A Guide to Using the kexec Command (with examples)

Load a new kernel

To load a new kernel using the kexec command, you can use the following code:

kexec -l path/to/kernel --initrd=path/to/initrd --command-line=arguments
  • Motivation: This use case is useful when you want to switch to a new kernel without rebooting the system. It can be handy during kernel development or testing.
  • Explanation:
    • path/to/kernel: Specify the path to the new kernel image that you want to load.
    • --initrd=path/to/initrd: Specify the path to the initial ramdisk (initrd) image that you want to provide to the new kernel.
    • --command-line=arguments: Specify additional command-line arguments for the new kernel (optional).
  • Example Output: None. This command prepares the system to boot into the new kernel.

Load a new kernel with current boot parameters

To load a new kernel using the current boot parameters, you can use the following code:

kexec -l path/to/kernel --initrd=path/to/initrd --reuse-cmdline
  • Motivation: This use case is helpful when you want to load a new kernel using the same command-line arguments as the currently running kernel. It saves you the effort of manually specifying arguments.
  • Explanation:
    • path/to/kernel: Specify the path to the new kernel image that you want to load.
    • --initrd=path/to/initrd: Specify the path to the initial ramdisk (initrd) image that you want to provide to the new kernel.
    • --reuse-cmdline: Reuse the command-line arguments from the currently running kernel.
  • Example Output: None. This command prepares the system to boot into the new kernel using the same command-line arguments.

Execute a currently loaded kernel

To execute the currently loaded kernel, you can use the following code:

kexec -e
  • Motivation: This use case is useful when you have loaded a new kernel using the kexec command and want to immediately execute it without rebooting the system.
  • Explanation: None.
  • Example Output: None. The currently loaded kernel starts executing.

Unload current kexec target kernel

To unload the currently loaded kexec target kernel, you can use the following code:

kexec -u
  • Motivation: This use case is beneficial when you want to unload the previously loaded kernel without rebooting the system, freeing up system resources.
  • Explanation: None.
  • Example Output: None. The currently loaded kexec target kernel is unloaded.

Note: The kexec command has several other use cases which are not covered in the examples above. Please refer to the official documentation for more information.

Related Posts

Using noti for Monitoring and Notifications (with examples)

Using noti for Monitoring and Notifications (with examples)

Use Case 1: Display a notification when tar finishes compressing files The code for this use case is:

Read More
Using the manpath command (with examples)

Using the manpath command (with examples)

The manpath command is used to determine the search path for manual pages on a Unix-like system.

Read More
How to use the command 'gcloud version' (with examples)

How to use the command 'gcloud version' (with examples)

This article will guide you through the different use cases of the ‘gcloud version’ command.

Read More