Merge ~mfo/charm-sysconfig:fix-grub-cmdline-linux-default into charm-sysconfig:master

Proposed by Mauricio Faria de Oliveira
Status: Merged
Approved by: Xav Paice
Approved revision: 0d9a37e6508e4c7744505ec443397efe8f9e32fd
Merged at revision: 237ca16bb97e18334d02b13814e1a512732f4a8b
Proposed branch: ~mfo/charm-sysconfig:fix-grub-cmdline-linux-default
Merge into: charm-sysconfig:master
Diff against target: 35 lines (+12/-8)
1 file modified
src/templates/grub.j2 (+12/-8)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Adam Dyess (community) Approve
Zachary Zehring (community) Approve
Review via email: mp+386280@code.launchpad.net

Commit message

grub.j2: fix grub-config-flags that use $GRUB_CMDLINE_LINUX_DEFAULT

Description of the change

The sysconfig charm's README.md says:

 """
 To add or keep kernel parameters you had previously configured see the grub-config-flags option below.

 ...

 For instance, if you need to set the kernel parameter "nvme_core.multipath=0" you would add:

 juju config sysconfig grub-config-flags='GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT nvme_core.multipath=0"
 """

But it does not work.

Without the charm:

 $ cat /etc/default/grub
 GRUB_CMDLINE_LINUX_DEFAULT="important=option"

 $ sudo update-grub

 $ grep -w -m1 ' linux' /boot/grub/grub.cfg
         linux /vmlinuz-4.15.0-106-generic root=... ro important=option

Now with the charm, but grub-config-flags option unset: (overrides it, as documented.)

 $ grep -w -m1 ' linux' /boot/grub/grub.cfg
         linux /vmlinuz-4.15.0-106-generic root=... ro console=tty0 console=ttyS0,115200 console=ttyS1,115200 pti=off

Now with the charm, AND grub-config-flags option set as suggested:

 $ juju config sysconfig-ubuntu grub-config-flags='GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT something=else"'

 $ grep -w -m1 ' linux' /boot/grub/grub.cfg
         linux /vmlinuz-4.15.0-106-generic root=... ro console=tty0 console=ttyS0,115200 console=ttyS1,115200 pti=off something=else

Note that the 'important=option' is lost.

With this fix:

 $ juju upgrade-charm --path .../sysconfig sysconfig-ubuntu

 $ grep -w -m1 ' linux' /boot/grub/grub.cfg
  linux /vmlinuz-4.15.0-106-generic root=... ro important=option something=else console=tty0 console=ttyS0,115200 console=ttyS1,115200 pti=off

Now all options are there:
- previously configured 'important=option'
- newly configured 'something=else'
- charm configured options.

And if we reset the option (keep current behavior)

 $ juju config sysconfig-ubuntu --reset grub-config-flags

 $ grep -w -m1 ' linux' /boot/grub/grub.cfg
  linux /vmlinuz-4.15.0-106-generic root=... ro console=tty0 console=ttyS0,115200 console=ttyS1,115200 pti=off

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Zachary Zehring (zzehring) wrote :

Looks good to me. I'll ask for an approval from an approved Bootstack Reviewer.

review: Approve
Revision history for this message
Mauricio Faria de Oliveira (mfo) wrote :

Hi Zachary,

Thanks for reviewing.

Friendly reminder for review from an approved Bootstack Reviewer, per your comment.

cheers,
Mauricio

Revision history for this message
Arif Ali (arif-ali) wrote :

Hey all, we're keen to get this reviewed and checked. We would greatly appreciate someone looking at this, so that we can move with the customer

Thanks,
Arif

Revision history for this message
Adam Dyess (addyess) wrote :

LGTM

review: Approve
Revision history for this message
Xav Paice (xavpaice) wrote :

lgtm

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 237ca16bb97e18334d02b13814e1a512732f4a8b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/templates/grub.j2 b/src/templates/grub.j2
2index f29ed5c..756025e 100644
3--- a/src/templates/grub.j2
4+++ b/src/templates/grub.j2
5@@ -5,7 +5,18 @@
6 # For full documentation of the options in this file, see:
7 # info -f grub -n 'Simple configuration'
8
9-GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200 console=ttyS1,115200"
10+# Evaluate grub-config-flags first, in case it uses $GRUB_CMDLINE_LINUX_DEFAULT.
11+# However, if grub-config-flags is not specified, ignore that (current behavior.)
12+{% if grub_config_flags is defined and grub_config_flags -%}
13+# config-flags
14+{% for key, value in grub_config_flags.items() -%}
15+{{ key }}={{ value }}
16+{% endfor -%}
17+{% else -%}
18+GRUB_CMDLINE_LINUX_DEFAULT=""
19+{% endif -%}
20+
21+GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT console=tty0 console=ttyS0,115200 console=ttyS1,115200"
22 {% if cpu_range is defined and cpu_range -%}
23 GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT isolcpus={{ cpu_range }}"
24 {% endif -%}
25@@ -33,10 +44,3 @@ GRUB_CMDLINE_LINUX=""
26 # Uncomment to disable graphical terminal (grub-pc only)
27 #GRUB_TERMINAL=console
28 GRUB_TERMINAL=serial
29-
30-{% if grub_config_flags is defined and grub_config_flags -%}
31-# config-flags
32-{% for key, value in grub_config_flags.items() -%}
33-{{ key }}={{ value }}
34-{% endfor -%}
35-{% endif -%}

Subscribers

People subscribed via source and target branches

to all changes: