1

I have the following variable in a grub.cfg file.

BOOT_PARAMETERS="rootwait rootfstype=ext4 rootimage=$BOOT_ROOT_IMAGE_NAME root=$ROOT_DEVICE console=none intel_idle.max_cstate=1 quiet"
BOOT_ROOT_INITRD=(hd0,gpt2)/boot1/initrd
BOOT_ROOT_KERNEL=(hd0,gpt2)/boot1/bzImage

I want to pass these parameters into a menu entry.

menuentry 'pc'{
linux $BOOT_ROOT_KERNEL $BOOT_PARAMETERS
initrd $BOOT_ROOT_INITRD
}

The BOOT_ROOT_KERNEL and BOOT_ROOT_INITRD works fine, but the parameters doesn't work. I'm not sure how it breaks the boot, but this menu entry will not boot. If I replace $BOOT_PARAMETERS with the actual contents of the variable (without quotes, it works).

Also, the following works as well:

linux $BOOT_ROOT_KERNEL "$BOOT_PARAMETERS"

However, the /proc/cmdline includes those quotes, and I don't want to break applications that are reading this output.

How do I get this to work?

linux $BOOT_ROOT_KERNEL $BOOT_PARAMETERS

Edit: In grub command line, if I do echo $BOOT_PARAMETERS, the machine flash reboots. If I do echo "$BOOT_PARAMETERS", it prints normally.

Edit2: It seems to have to do with large environment variables. Doing set TEST="SFSFESFSEFDFUIHI rg s rjg sreuigsrgi sig isdfjgs dfkgd", followed by an echo $TEST will sometimes cause it. It happens at a certain length/combination, and I can't put my finger on it. If it doesn't happen on first try, keep appending stuff to TEST, then the echo $TEST will eventually cause a flash reboot.

4
  • You do not edit grub.cfg. You edit /etc/default/grub. See this part : GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" help.ubuntu.com/community/Grub2/Setup#Configuring_GRUB_2 You could edit 40_custom, but then would just use the correct boot stanza, no need for variables. Grub is sensitive to boot stanzas that are correct.
    – oldfred
    Nov 17 '17 at 15:29
  • 1
    This is an embedded device, and for reasons, we HAVE to pass dynamically built environment variables to the boot process in grub.
    – Paul Knopf
    Nov 17 '17 at 15:40
  • Also the boot parameters are correct. If I pass values directly (instead of environment variables), it works.
    – Paul Knopf
    Nov 17 '17 at 18:48
  • Could it be just a space at end of first variable or beginning of second?
    – oldfred
    Nov 17 '17 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.