NCM::Component::grub¶
NAME¶
The grub component manages the grub configuration.
DESCRIPTION¶
The grub component manages the configuration of grub.
Most of the configuration is handled via the grubby tool
(which supports grub2).
Some configuration like serial console settings and password however is done by modifying the grub configfile directly, which might not be safe under grub2.
RESOURCES¶
Besides /software/component/grub, following resources are used:
/system/kernel/versionfor setting the default kernel/hardware/console/serialfor serial console configuration
EXAMPLES¶
A standard SL4 kernel with initrd image to be loaded.
"/software/components/grub/kernels/0" = nlist("kernelpath", "/vmlinuz-2.6.9-22.0.1.EL", "kernelargs", "ro root=LABEL=/", "title", "Scientific Linux 4.2 / 2.6.9", "initrd", "/initrd-2.6.9-22.0.1.EL.img" );This configuration produces the following entry in grub.conf (via grubby):
title Scientific Linux 4.2 / 2.6.9 kernel `/vmlinuz`-2.6.9-22.0.1.EL ro root=LABEL=/ initrd `/initrd`-2.6.9-22.0.1.EL.img
A Xen 3 hypervisor with Linux 2.6 domain 0 kernel and initrd (via grubby).
"/software/components/grub/kernels/1" = nlist("multiboot", "/xen-3.0.2-2.gz", "mbargs", "dom0_mem=400000", "title", "Xen 3 / XenLinux 2.6.16", "kernelpath", "/vmlinuz-2.6.16-xen3_86.1_rhel4.1", "kernelargs", "max_loop=128 root=/dev/hda2 ro", "initrd", "/initrd-2.6.16-xen3_86.1_rhel4.1" );Produces the following entry in grub.conf:
title Xen 3 / XenLinux 2.6.16 kernel `/xen`-3.0.2-2.gz dom0_mem=400000 addthis module `/vmlinuz`-2.6.16-xen3_86.1_rhel4.1 max_loop=128 root=/dev/hda2 ro module `/initrd`-2.6.16-xen3_86.1_rhel4.1
Methods¶
convert_grubby_arguments
Given
argsstring or hashref, updateargumentshashref with add/remove hashrefs. Optional serial console kernel commandline optionconsIf
argsis a string, arguments prefixed with ‘-’ are added to the remove hashref.Returns
argumentshashref with add and remove hashrefs.If track is false, the values of add and remove hashrefs are the last encountered value. If track is true, the values of add and remove hashrefs are arraysrefs with all encountered values.
assemble_grubby_options
Given
argumentshashref, return the add and remove option arrayrrefs.
grubby_arguments_options
Given arguments hashref
args, convert into grubby commandline options to add and/or remove the arguments. Ifmultibootis true, generate multiboot commandline optionsReturns a list of options.
password
Configure the grub password by editing the grub conf via filehandle
grub_fh(aCAF::FileEditorinstance, which is not closed in this method).Returns SUCCESS on succes, undef otherwise.
serial_console
Configure the grub serial console settings (
ttySdevices only) by editing the grub conf via filehandlegrub_fh(aCAF::FileEditorinstance, which is not closed in this method).Returns undef on failure, the console kernel commandline option (or empty string if none is to be configured) on success.
main_section_offset
Given a grub config filehandle (a
CAF::FileEditorinstance), return the startposition of the main section i.e. after the header comments (if any).
grub_conf
Edit grub configfile and return serial console kernel commandline option (if any).
grubby
Run
grubbywith arrarefargsviaCAF::Procesusing theoutputmethod and return the output.Has following options
proc: return new
CAF::Processinstance withargs(i.e. without execute/output)success: run execute and return 1 on success, 0 on failure
keeps_state: pass keeps_state flag
current_default
Return current full path of current default kernel.
set_default
Set default kernel to
newkernelpath and verify by (re)checking the default kernel.Returns success on success; on failure, return either
undef: setting default kernel returned non-zero exitcode
0: setting default was succesful, but new default kernel is not expected kernel
No errors are reported.
configure_default
Configure the new default kernel to be
new. If this fails andmbnewexists, try to setmbnewas default.If neither
newnormbneware successful, report an error and revert tooriginal.
kernel
Configure boot entry using
kernelhashref, the kernelprefixand optional serial console kernel commandline optioncons.Any serial console settings in the
kernelargsattribute is replaced bycons(when defined).
get_info
Return info for default kernel as an arrayref of hashref
Same kernel can have multiple entries.
current_arguments
Get the current arguments. Return current arguments as string and as parsed hasref
trackoption is passed toconvert_grubby_arguments.
sanitize_arguments
Sanitize the current arguments
default_options
Configure kernel commandline options of default kernel
pxeboot
Set pxeboot as first bootorder. Returns SUCCESS on success, undef otherwise.
Currently only supported on UEFI systems using
efibootmgr. On other systems, SUCCESS is also returned (but nothing is done).
Configure
Updates the grub.conf configuration file using grubby according to a list of kernels described in the profile.
Sets the default kernel to that specified in
/system/kernel/version.Supports
serial console configuration specified in
/hardware/console/serial.multiboot loaders (most commonly used for configuration of Xen systems).
Returns error in case of failure.