Commit Graph

31 Commits

Author SHA1 Message Date
Javier Martinez Canillas
73b809baaf
Use mountpoint command to check whether /boot is a mount point
Using grep is wrong and fragile, so let's use the mountpoint command
instead to make it more robust.

Resolves: rhbz#1706091

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-05-03 18:21:23 +02:00
Javier Martinez Canillas
dc24f2cedf
grubby-bls: fix --add-kernel not working when using the --args option
The script prints an error if --args option is used without --update-kernel
but it's also valid to use it with the --add-kernel option.

Resolves: rhbz#1691004

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-03-21 11:29:12 +01:00
Javier Martinez Canillas
6abeb6fc77
grubby-bls: make --update-kernel ALL to update kernelopts var in grubenv
Currently there's no way to update the kernelopts variable defined in the
grubenv by using the grubby wrapper. Updating it with grub2-editenv - set
is tedious and error prone so let's use --update-kernel=ALL option for it.

This command currently iterates over all the BLS entries and update them
individually, but makes more sense to update the kernelopts grubenv var
and only update the BLS entries that don't have the $kernelopts var in
their options field.

If after an update one of these BLS entries have exactly the same params
in their options field than the ones set in $kernelopts, set the options
field to $kernelopts again since the parameters have converged again.

That way the modified BLS entries will only have a custom options field
while its value diverged from the $kernelopts defined in grubenv.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-03-01 16:31:28 +01:00
Javier Martinez Canillas
40d73389b4
grubby-bls: error if args or remove-args is used without update-kernel
The --args and --remove-args options can only be used when the kernel to
update is specified using the --update-kernel option. Print an error if
the latter option is not provided.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-02-14 10:57:13 +01:00
Javier Martinez Canillas
a77221432e
grubby-bls: unset default entry if is the one being removed
If the default entry is removed, this can't be set as the default anymore
for zipl. Otherwise the zipl tool will fail since it won't exist an IPL
section for the one set as the default.

For grub2, if the saved_entry doesn't exist it will fallback to the first
entry. But still the correct thing to do is to unset the default there.

Resolves: rhbz#1668329

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-02-02 01:12:28 +01:00
Javier Martinez Canillas
f742fa15b3
grubby-bls: show absolute path when printing error about incorrect param
The error message is not printing the absolute path to the images, fix it.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-02-02 01:12:28 +01:00
Javier Martinez Canillas
290786e606
Correctly set LDFLAGS and make grubby-bls expand all options variables
- Correctly set LDFLAGS to include hardened flags (pjones)
  Related: rhbz#1654936
- grubby-bls: expand all variables in options field when updating it
  Resolves: rhbz#1660700

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2019-01-14 09:56:05 +01:00
Javier Martinez Canillas
6b2ae0e335
grubby-bls: lookup default entry by either id or title on grub2
There is a grub2-set-default script that can be used to set the default
entry. It can take an entry id, title or index as a parameter so grubby
should be able to also lookup a default entry using the title on grub2.

Related: rhbz#1654936

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-12-11 16:24:22 +01:00
Javier Martinez Canillas
f1aafa632f
grubby-bls: always generate the BLS snippets when adding new entries
a BLS file is generated at build time and stored in /lib/modules/$kernel
but this default BLS file assumes that /boot is a mount point and so the
kernel and initrd paths are relative to the root of this boot partition.

This is not the case if /boot is not a mount point or if the bootloader
is zipl, since zipl expects the absolute path to be in the BLS snippet.

The kernel-install scripts takes care of this and modifies the BLS file
if needed, but grubby doesn't do that. So instead just generate the BLS
always even if there is one for the kernel version of the added entry.

Resolves: rhbz#1653365

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-12-01 02:02:16 +01:00
Javier Martinez Canillas
b84a214b99
grubby-bls: expand kernel options if these are environment variables
The grub2 bootloader allows the BLS snippets fields to contain environment
variables instead of constants. This is useful for example to define the
kernel command line parameters only once in the grubenv file and set this
variable in the BLS snippets.

But this can be confusing for users when the information is printed by the
grubby script, so expand the variables if they can be looked up in grubenv.

Resolves: rhbz#1649785

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-12-01 02:01:49 +01:00
Javier Martinez Canillas
4b1d63cacd
grubby-bls: allow to specify the same kernel param multiple times
The kernel command line can contain parameters that are specified multiple
times. This is supported by the old grubby tool but ins't supported by the
grubby BLS wrapper. Allow the grubby wrapper to do the same.

Resolves: rhbz#1652486

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-12-01 02:01:22 +01:00
Javier Martinez Canillas
d1dd184403
grubby-bls: also print the absolute path in the --default-kernel option
The absolute path to the kernel and initramfs images is printed by the
--info option, but it's not printed by the --default-kernel option.

Resolves: rhbz#1649778

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-12-01 01:57:07 +01:00
Javier Martinez Canillas
695377d276
grubby-bls: make info print the root parameter if is present in cmdline
The old grubby tool printed the root parameter separated from the other
kernel command line arguments. Make the wrapper have the same behaviour.

Resolves: rhbz#1649791

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-11-21 10:45:49 +01:00
Javier Martinez Canillas
6cdfe45ece
grubby-bls: print the absolute kernel and initramfs images paths
The BLS file "linux" and "initrd" fields expect a relative paths from the
root of the partition that contains the kernel and initramfs. The grubby
tool was printing the value of thse fields and not their full path.

So if there is a partition and /boot is a mount point, he BLS would have:

linux /vmlinuz-4.18.0-38.el8.x86_64
initrd /initramfs-4.18.0-38.el8.x86_64.img

And grubby would print:

kernel="/vmlinuz-4.18.0-38.el8.x86_64"
initrd="/initramfs-4.18.0-38.el8.x86_64.img"

But the old tool used to print the full paths of the images, so should be:

kernel="/boot/vmlinuz-4.18.0-38.el8.x86_64"
initrd="/boot/initramfs-4.18.0-38.el8.x86_64.img"

Resolves: rhbz#1649778

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-11-21 10:45:26 +01:00
Javier Martinez Canillas
791d55400b
grubby-bls: use title field instead of version for zipl default entry
Most bootloaders use the BootLoaderSpec "title" field to name the entries
in their boot menu. The zipl bootloader used the "version" field instead,
since it was wrongly assumed that the zipl boot menu didn't support names
that contained spaces, which are usually present in a BLS "title" field.

But this is not the case, names with space characters are supported by the
IPL and is just a constraint of the section heading in the zipl.conf file.

To be consistent with all the other bootloaders, zipl now uses the "title"
field to populate the boot menu entries from BLS files. So change grubby
to use the "title" field to set the default entry of the "version" field.

Related: rhbz#1645200

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-11-21 10:44:33 +01:00
Javier Martinez Canillas
7babbb04df
grubby-bls: only compare using relative paths if /boot is a mount point
The grub2 bootloader expects the BLS linux and initrd fields values to be
set to a relative path to the root of the boot partition and the zipl tool
expects these to be an absolute path to the kernel and initramfs images.

So the grubby wrapper was removing the prefixes from the kernel and initrd
paths before doing any comparision with the BLS fields. But this shouldn't
be done if the /boot directory isn't a mount point.

Resolves: rhbz#1642078

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-11-06 11:48:49 +01:00
Javier Martinez Canillas
2ef6823a35
grubby-bls: fix --default-* options for s390x
On s390x the version field is used to set the default BLS entry.

Resolves: rhbz#1644608

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-11-02 00:55:03 +01:00
Javier Martinez Canillas
9a80bb6f8e
grubby-bls: allow to add many BLS entries for the same kernel image
The BLS files name convention used is ${MACHINE_ID}-${KERNEL_VERSION}.conf
but this means that there can only be a single entry for a given kernel.

Allow the grubby wrapper to add many entries for the same kernel image,
since the old grubby tool was able to do that. To differentiate from the
original BLS entry and to specify that it's a customized entry, add a
[[:digit:]]~custom suffix after the kernel version number.

This will also sort the custom entries before the original entry, that's
also what the old grubby tool did.

Resolves: rhbz#1634752

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-11-02 00:55:03 +01:00
Javier Martinez Canillas
1c345197a4
grubby-bls: use ~debug instead of -debug as suffix to sort correctly
For the debug BLS entries a -debug suffix was added so they are sorted after
the kernel entries, but that only works with version sort and not rpm sort.

So instead use ~debug prefix so rpm sort algorithm could sort it correctly.

Related: rhbz#1638103

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:51:23 +02:00
Javier Martinez Canillas
db3ffac800
grubby-bls: use id instead of title to get the default entry
The wrapper is using the title before to store the default entry, but we
are now using the entry id for grub2, so make the wrapper query the id.

Resolves: rhbz#1638103

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:51:16 +02:00
Javier Martinez Canillas
7d53b5e0a6
grubby-bls: escape delimiter character before replacing the options field
The ! character was used as the delimiter, but this doesn't work when the
param uses this character, for example "memmap=1G!1G".

Resolves: rhbz#1640017

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:50:49 +02:00
Javier Martinez Canillas
84881fb396
grubby-bls: make a copy of the cmdline if is modified for an entry
The BLS entries use a global kernel command line parameters that's set as
kernelopts variable in the grubenv file. But users may want to have custom
parameters for some entries, so make a copy of the current kernelopts and
set the "options" field value to the modified parameters.

Resolves: rhbz#1629054

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:49:19 +02:00
Peter Jones
a5e56a6e7d
Make grubby-bls sort everything correctly, including spaces.
Related: rhbz#1638103
2018-10-23 15:49:19 +02:00
Javier Martinez Canillas
b40ea5be18
grubby-bls: check if entry exists before attempting to print its info
The grubby --info option didn't check if an entry existed for a kernel and
printed wrong information about it. Fix this and also for --update-kernel
and --set-default options that have the same issue.

Resolves: rhbz#1634712

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:35:52 +02:00
Javier Martinez Canillas
cf425061aa
grubby-bls: set saved_entry to id instead of title on set-default
The grubby wrapper sets the saved_entry in grubenv to the entry title
field since that's done by grubby. But for BLS the id is the filename
without the .conf extension, this saved_entry is set to this when a
new kernel is installed.

So for consistency also use the entry id for the --set-default option.

Related: rhbz#1638103

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:35:13 +02:00
Peter Jones
4aa091811b
grubby-bls: make "id" be the filename, and include it in --info=ALL
Related: rhbz#1638103
Signed-off-by: Peter Jones <pjones@redhat.com>
2018-10-23 15:08:30 +02:00
Javier Martinez Canillas
33ab171b28
Print information about the entry set as default by grubby-bls script
This information can be useful for users to know what's the BLS entry
that was set as the default.

Resolves: rhbz#1636180

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:06:54 +02:00
Javier Martinez Canillas
28952a66c8
Use ! instead of , as sed delimiter in grubby-bls script
The script uses sed to modify the options field in the BLS entries, but it
is using a ',' character as the sed delimiter. It's total valid to have a
kernel command line parameter that contains that character, for example:

$ grubby --add-kernel=/boot/vmlinuz --args="console=ttyS0,115200n81" \
  --initrd=/boot/initrd.img --make-default --title=install
sed: -e expression #1, char 42: unknown option to `s'

Fix this by using a different delimiter that won't be present in a cmdline.

Resolves: rhbz#1634744

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:06:49 +02:00
Javier Martinez Canillas
f9880644e6
grubby-bls should only check if kernel exists and not if was installed
When a new BLS entry is added, the script checks if the kernel image exists
and also if it was installed from a rpm package. But the latter isn't really
needed, it should be valid to just copy a kernel image and add a BLS entry.

Resolves: rhbz#1634740

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:06:45 +02:00
Javier Martinez Canillas
b8c8cdcf6c
Make grubby-bls execute grub2-mkconfig on ppc64
When booting an ppc64 machine on bare-metal (PowerNV) the OPAL firmware
interface is used. The firmware contains the Petitboot boot-loader that
can be used to parse the BootLoaderSpec (BLS) snippets in a BLS setup.

But machines could have an older version of Petitboot that doesn't have
BLS support, so on ppc64 machines can't be assumed that just modifying
the BLS files is enough for those changes to be reflected in the boot
menu. Instead, grub2-mkconfig is executed so the BLS can be parsed and
produce a grub config file that can be used by any Petitboot version.

Resolves: rhbz#1636039

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-10-23 15:06:40 +02:00
Javier Martinez Canillas
19db5c489a
Add grubby-bls package
Add a grubby wrapper script that allows to manage BootLoaderSpec files by
using the same command line options supported by the grubby tool. This is
provided for backward compatibility for grubby users that swtich to BLS.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2018-07-13 20:05:41 +02:00