avoiding quotes in kernel cmdline
With code like this, the resulting kernel cmdline has backslashes before either ' or ". I think var="\"str\"" or var="'str'" has to be used to place either " or ' into the variable. How can I avoid the backslash in the kernel cmdline?
udev_rule="udev.rule=\"mac=${net_default_mac},name=uplink\"" udev_rule="udev.rule='mac=${net_default_mac},name=uplink'" cmdline="${udev_rule} install=${install} start_shell linemode=1 console=ttyS0,115200" menuentry "boot" {
linux (http,${ip})/path/to/linux ${cmdline}
initrd (http,${ip})/path/to/initrd
}
Olaf
Quoted 11 lines · Olaf Hering
With code like this, the resulting kernel cmdline has backslashes before either ' or ". I think var="\"str\"" or var="'str'" has to be used to place either " or ' into the variable. How can I avoid the backslash in the kernel cmdline?
udev_rule="udev.rule=\"mac=${net_default_mac},name=uplink\"" udev_rule="udev.rule='mac=${net_default_mac},name=uplink'" cmdline="${udev_rule} install=${install}
start_shelllinemode=1 console=ttyS0,115200" menuentry "boot" {
linux (http,${ip})/path/to/linux ${cmdline}
initrd (http,${ip})/path/to/initrd
}
Both var="\"str\"" and var="'str'" should work. Does not they? Do you still get backslashes in ${cmdline}?
Daniel
Am Fri, 13 Mar 2020 12:59:32 +0100
schrieb Daniel Kiper <[email protected]>:
Quoted 2 lines
Both var="\"str\"" and var="'str'" should work. Does not they? Do you still get backslashes in ${cmdline}?
Yes. I think the issue might be the "final expansion" in the menuentry and/or linux command?
# grub.cfg insmod part_msdos insmod ext2 serial --unit=0 --speed=115200 terminal_input serial terminal_output serial
var="\"str\""
cmdline="${var} console=ttyS0,115200 quiet"
menuentry 'ROOT' {
search --no-floppy --label --set=root ROOT
linux ($root)/boot/vmlinuz ${cmdline}
initrd ($root)/boot/initrd
}
BOOT_IMAGE=(hd0,msdos2)/boot/vmlinuz \"str\" console=ttyS0,115200 quiet
Olaf
Quoted 23 lines · Olaf Hering
Am Fri, 13 Mar 2020 12:59:32 +0100
schrieb Daniel Kiper <[email protected]>:Quoted 2 lines
Both var="\"str\"" and var="'str'" should work. Does not they? Do you still get backslashes in ${cmdline}?
Yes. I think the issue might be the "final expansion" in the menuentry and/or linux command?
# grub.cfg insmod part_msdos insmod ext2 serial --unit=0 --speed=115200 terminal_input serial terminal_output serialvar="\"str\""
cmdline="${var} console=ttyS0,115200 quiet"
menuentry 'ROOT' {
search --no-floppy --label --set=root ROOT
linux ($root)/boot/vmlinuz ${cmdline}
initrd ($root)/boot/initrd
}
Quoted 1 line
BOOT_IMAGE=(hd0,msdos2)/boot/vmlinuz \"str\" console=ttyS0,115200 quiet
Hmmm... Strange... When I was testing similar thing some time ago it worked without any issue. However, IIRC, I was just testing how it works with the echo command. Anyway, could you check what is going on and prepare a patch if needed?
Daniel
Am Fri, 13 Mar 2020 15:07:57 +0100
schrieb Daniel Kiper <[email protected]>:
Quoted 1 line
Anyway, could you check what is going on and prepare a patch if needed?
Sure I can wipe the offending lines from grub_create_loader_cmdline(). The question is rather what the purpose of the new code added in 25953e10553dad2e378541a68686fc094603ec54 is.
Olaf
Quoted 8 lines · Olaf Hering
Am Fri, 13 Mar 2020 15:07:57 +0100
schrieb Daniel Kiper <[email protected]>:Quoted 1 line
Anyway, could you check what is going on and prepare a patch if needed?
Sure I can wipe the offending lines from
grub_create_loader_cmdline(). The question is rather what the purpose of the new code added in25953e10553dad2e378541a68686fc094603ec54is.
Adding Vladimir. There is a chance that he knows why it was added...
Daniel
Am Fri, 13 Mar 2020 15:26:33 +0100
schrieb Daniel Kiper <[email protected]>:
Quoted 1 line
Adding Vladimir. There is a chance that he knows why it was added...
I just checked why this did not show up earlier.
With 20190718T143316.4e75b2ae3 and command "linux ($root)/file var='str'" nothing is escaped.
The command "linux ($root)/boot/vmlinuz ${cmdline} var="str" var='str'" from my earlier example results in this cmdline:
BOOT_IMAGE=(hd0,msdos2)/boot/vmlinuz \"str1\" \'str2\' console=ttyS0,115200 quiet var=str var=str
I just noticed now that in the production code I use since months the single quotes disappeared, and the consumers of /proc/cmdline do not care about this detail.
So in the end I may just remove the existing single quote from my code any everything should work fine for the consumers of /proc/cmdline.
Olaf
Am Fri, 13 Mar 2020 15:26:33 +0100
schrieb Daniel Kiper <[email protected]>:
Quoted 1 line
Adding Vladimir. There is a chance that he knows why it was added...
In the end this knowledge does not matter much I think. I sent a patch to fix the bug.
Olaf