How to update /etc/default/grub and /boot/grub/grub.cfg ?

Asked by Cubic PPA

---------------------------------------------------------------------
How to update /etc/default/grub and /boot/grub/grub.cfg ?
---------------------------------------------------------------------

To modify the Grub menu of an existing installed OS, you would simply change the parameters in /etc/default/grub, and execute `sudo update-grub`.

Unfortunately, this approach does not work when customizing the Ubuntu ISO.

This is because when an OS is first installed from a Live ISO, the contents of /etc/default/grub are overwritten with default values.

If you had made changes to /etc/default/grub in Cubic's Terminal environment, your changes will be lost. Consequently, /boot/grub/grub.cfg can not be updated with your custom values, and the Grub menu will frustratingly not reflect your modifications.

How to update Grub with custom values?

Question information

Language:
English Edit question
Status:
Solved
For:
Cubic Edit question
Assignee:
No assignee Edit question
Solved by:
Cubic PPA
Solved:
Last query:
Last reply:
Revision history for this message
Cubic PPA (cubic-wizard) said (last edit ):
#1

---------------------------------------------------------------------
INSTRUCTIONS
---------------------------------------------------------------------

We can use preseeding to resolve this problem.

(1)

In Cubic's Terminal environment, make your changes to /etc/default/grub.

For example, change...

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

To...

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi=force modprobe.blacklist=nouveau"

Then backup this file to /usr/share/grub/default/grub...

    cp /etc/default/grub /usr/share/grub/default/grub

(The file /usr/share/grub/default/grub will be used as a backup to restore /etc/default/grub when it gets over written during installation).

(2)

Do not execute `update-grub`. (It won't work anyway).

Finish making your other customizations in Cubic's Terminal environment.

(3)

On Cubic's Options page, click on the Boot tab.

Select the preseed file (ubuntu.seed, xubuntu.seed, etc.).

Add the following at the *bottom* of this file:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (a) Generate /boot/grub/grub.cfg using the customized version of /etc/default/grub.
# (b) Revert the customized version of /etc/default/grub after it has been overwritten.
ubiquity ubiquity/success_command string \
    in-target bash -c 'update-grub'; \
    in-target bash -c 'cp /usr/share/grub/default/grub /etc/default/grub';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Revision history for this message
Cubic PPA (cubic-wizard) said :
#2

---------------------------------------------------------------------
EXPLANATION
---------------------------------------------------------------------

(a) The first command (`...bash -c 'update-grub'`) updates Grub in the installed OS using the values you had supplied in your /etc/default/grub file in step (1) above.

(b) Since /etc/default/grub is overwritten after Grub is updated, the second command (`... bash -c 'cp ...`) reverts this file to your customized version. Therefore, the next time you manually execute `sudo update-grub` in your installed OS, your customized values will be used.