Unable to modify current generating grub.cfg
Hello,
Since our bug was closed and we were asked to submit it here to upstream, here we are :
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/2052381
When you want to "alterate" current generating grub.cfg.new in /etc/grub.d/* scripts, you cant sed -i in /boot/grub/grub.cfg.new due to the used method for generating grub.cfg.new 'exec redirection'
I propose a more 'common' method, wich permit, for example, alterating grub.cfg.new content, generated from /etc/grub.d/30_linux, in a /etc/grub.d/90_custom script.
Diff file :
19a20,22
Quoted 3 lines
# [grub-mkconfig] Problem with generation method in grub-mkconfig # Patch submitted to [email protected]
39c42
< grub_cfg=""
---
Quoted 1 line
grub_cfg="/boot/grub/grub.cfg"
271a275
Quoted 1 line
NEW_GRUBCFG="${grub_cfg}.new"
273c277
< rm -f "${grub_cfg}.new"
---
Quoted 1 line
rm -f "${NEW_GRUBCFG}"
275c279
< exec > "${grub_cfg}.new"
---
Quoted 1 line
printf "" > "${NEW_GRUBCFG}"
281,282c285
< cat << EOF
< #
---
Quoted 1 line
DISCLAIMER="#
288c291,292
< EOF
---
Quoted 2 lines
"
printf "%s\n" "${DISCLAIMER}" >> "${NEW_GRUBCFG}"
299,302c303,309
< echo
< echo "### BEGIN $i ###"
< "$i"
< echo "### END $i ###"
---
Quoted 7 lines
echo "" >> "${NEW_GRUBCFG}"
echo "### BEGIN $i ###" >> "${NEW_GRUBCFG}" if ! "$i" >> "${NEW_GRUBCFG}";then echo "[ERROR] '$i' failed !" >&2 exit 99
fi
echo "### END $i ###" >> "${NEW_GRUBCFG}"
308,311d314
< if [ "x${grub_cfg}" != "x" ] && ! grep "^password" ${grub_cfg}.new >/dev/null; then < chmod 444 ${grub_cfg}.new || true
< fi
<
318c321
< %s file attached." "${grub_cfg}.new" >&2
---
Quoted 1 line
%s file attached." "${NEW_GRUBCFG}" >&2
See the attached patch.
Regards,
Signature · 1 line
Guillaume Hilt
util/grub-mkconfig.in +14 -10
@@ -257,23 +257,24 @@ export GRUB_DEFAULT \ GRUB_OS_PROBER_SKIP_LIST \ GRUB_DISABLE_SUBMENU +NEW_GRUBCFG="${grub_cfg}.new" if test "x${grub_cfg}" != "x"; then - rm -f "${grub_cfg}.new" + rm -f "${NEW_GRUBCFG}" oldumask=$(umask); umask 077 - exec > "${grub_cfg}.new" + printf "" > "${NEW_GRUBCFG}" umask $oldumask fi gettext "Generating grub configuration file ..." >&2 echo >&2 -cat << EOF -# +DISCLAIMER="# # DO NOT EDIT THIS FILE # # It is automatically generated by $self using templates # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub # -EOF +" +printf "%s\n" "${DISCLAIMER}" >> "${NEW_GRUBCFG}" for i in "${grub_mkconfig_dir}"/* ; do
@@ -284,10 +285,13 @@ for i in "${grub_mkconfig_dir}"/* ; do */\#*\#) ;; *) if grub_file_is_not_garbage "$i" && test -x "$i" ; then - echo - echo "### BEGIN $i ###" - "$i" - echo "### END $i ###" + echo "" >> "${NEW_GRUBCFG}" + echo "### BEGIN $i ###" >> "${NEW_GRUBCFG}" + if ! "$i" >> "${NEW_GRUBCFG}";then + echo "[ERROR] '$i' failed !" >&2 + exit 99 + fi + echo "### END $i ###" >> "${NEW_GRUBCFG}" fi ;; esac
@@ -299,7 +303,7 @@ if test "x${grub_cfg}" != "x" ; then gettext_printf "Syntax errors are detected in generated GRUB config file. Ensure that there are no errors in /etc/default/grub and /etc/grub.d/* files or please file a bug report with -%s file attached." "${grub_cfg}.new" >&2 +%s file attached." "${NEW_GRUBCFG}" >&2 echo >&2 exit 1 else
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel