From 86b1955bd02d629d6033639bf98083a5f1bc60d7 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Thu, 30 Aug 2018 08:26:35 +0200 Subject: [PATCH 1/7] mxgrub: Add `is_uefi_booted()` for checking if booted from UEFI [1]: https://askubuntu.com/questions/162564/how-can-i-tell-if-my-system-was-booted-as-efi-uefi-or-bios --- mxgrub/mxgrub | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index e69f049..723cf61 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -149,6 +149,13 @@ sub is_VX50 { return $data=~/VX50/; } +sub is_uefi_booted { + # If Linux is built with `CONFIG_EFI=y`, and it detects an UEFI + # installation, then it’ll create the directory `/sys/firmware/efi`. + # So, depend on Linux and check for the existence of the directory. + return -d '/sys/firmware/efi'; +} + our $submenu="all-other-kernel"; sub get_chosen { @@ -353,6 +360,11 @@ if ($opt_list) { } else { print "XV50: no\n"; } + if (is_uefi_booted) { + print "System booted using UEFI: yes\n"; + } else { + print "System booted using UEFI: no\n"; + } } else { @ARGV==1 or die USAGE; cmd_install($ARGV[0]); From d037f924834e8104c1f0aed561d0f718b658ef39 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Thu, 6 Sep 2018 10:46:24 +0200 Subject: [PATCH 2/7] mxgrub: Add `has_esp()` to check if EFI System Partition exists --- mxgrub/mxgrub | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index 723cf61..c4eff6d 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -156,6 +156,11 @@ sub is_uefi_booted { return -d '/sys/firmware/efi'; } +# Check if system has an EFI System Partition (ESP) +sub has_esp { + return !system('blkid -L ESP>/dev/null'); +} + our $submenu="all-other-kernel"; sub get_chosen { @@ -360,6 +365,11 @@ if ($opt_list) { } else { print "XV50: no\n"; } + if (has_esp) { + print "System has an ESP: yes\n"; + } else { + print "System has an ESP: no\n"; + } if (is_uefi_booted) { print "System booted using UEFI: yes\n"; } else { From befaa508206dbb70e45456f94af423d544cae62e Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Thu, 30 Aug 2018 08:45:48 +0200 Subject: [PATCH 3/7] mxgrub: Support UEFI systems Instead of always mounting the EFI System Partition (ESP), only mount it when checking if GRUB is installed. The mount point `/boot/efi` was created on the distmaster. --- mxgrub/mxgrub | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index c4eff6d..90a39c3 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -315,7 +315,13 @@ sub cmd_install { update_grub_cfg(); - if ($mbr_type ne 'GRUB') { + if (has_esp) { + sys 'mount','-L','ESP','/boot/efi' and exit 1; + if !(-d '/boot/efi/EFI/grub/grubx64.efi') { + sys 'grub-install','--target=x86_64-efi',$root_disk and exit 1; + } + sys 'umount','/boot/efi' and exit 1; + } elsif ($mbr_type ne 'GRUB') { sys 'grub-install',$root_disk and exit 1; } From 2e4563434acb79dcf425716c330b645c686e21a7 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Thu, 30 Aug 2018 08:45:48 +0200 Subject: [PATCH 4/7] mxgrub: Output if GRUB is already installed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As that’s the common case, maybe it’s just spam, and should be a verbose option. --- mxgrub/mxgrub | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index 90a39c3..b30cb91 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -317,12 +317,19 @@ sub cmd_install { if (has_esp) { sys 'mount','-L','ESP','/boot/efi' and exit 1; - if !(-d '/boot/efi/EFI/grub/grubx64.efi') { + if (-d '/boot/efi/EFI/grub/grubx64.efi') { + print "GRUB is already installed.\n"; + } + else { sys 'grub-install','--target=x86_64-efi',$root_disk and exit 1; } sys 'umount','/boot/efi' and exit 1; - } elsif ($mbr_type ne 'GRUB') { - sys 'grub-install',$root_disk and exit 1; + } else { + if ($mbr_type ne 'GRUB') { + sys 'grub-install',$root_disk and exit 1; + } else { + print "GRUB is already installed.\n"; + } } if ($label eq 'default') { From 3c6c69566ba1805bb1919f69e2380db34469ac5b Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Mon, 3 Sep 2018 08:54:03 +0200 Subject: [PATCH 5/7] mxgrub: Always install GRUB in MBR Contradicting the documentation, that `i386-pc` is the default target, on UEFI systems it is not. $ sudo grub-install --boot-directory=/boot /dev/nvme0n1 Installing for x86_64-efi platform. grub-install: error: cannot find EFI directory. So, pass `--target=i386-pc` to install GRUB in the MBR. $ sudo grub-install --target=i386-pc --boot-directory=/boot /dev/nvme0n1 Installing for i386-pc platform. Installation finished. No error reported. --- mxgrub/mxgrub | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index b30cb91..ac8e71e 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -318,18 +318,18 @@ sub cmd_install { if (has_esp) { sys 'mount','-L','ESP','/boot/efi' and exit 1; if (-d '/boot/efi/EFI/grub/grubx64.efi') { - print "GRUB is already installed.\n"; + print "GRUB for UEFI is already installed.\n"; } else { sys 'grub-install','--target=x86_64-efi',$root_disk and exit 1; } sys 'umount','/boot/efi' and exit 1; + } + + if ($mbr_type ne 'GRUB') { + sys 'grub-install','--target=i386-pc',$root_disk and exit 1; } else { - if ($mbr_type ne 'GRUB') { - sys 'grub-install',$root_disk and exit 1; - } else { - print "GRUB is already installed.\n"; - } + print "GRUB is already installed in MBR.\n"; } if ($label eq 'default') { From f1ad4d3de9990c96de726b057dd37ba5b296f329 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Thu, 6 Sep 2018 16:06:41 +0200 Subject: [PATCH 6/7] mxgrub: Add switch `no-nvram` to `grub-install` for UEFI In case a drive with an EFI System Partition (ESP) is put into a system that boots in legacy mode, running `grub-install --target=x86_64-efi` will fail, as `efibootmgr` fails to update the NVRAM. Therefore, pass `--no-nvram` to `grub-install`, which skip running efibootmgr. --no-nvram don't update the `boot-device'/`Boot*' NVRAM variables. This option is only available on EFI and IEEE1275 targets. As a downside, the administrator needs to go int the firmware menu, and add the entry in the boot manager manually. --- mxgrub/mxgrub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index ac8e71e..b2a5178 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -321,7 +321,7 @@ sub cmd_install { print "GRUB for UEFI is already installed.\n"; } else { - sys 'grub-install','--target=x86_64-efi',$root_disk and exit 1; + sys 'grub-install','--target=x86_64-efi','--no-nvram',$root_disk and exit 1; } sys 'umount','/boot/efi' and exit 1; } From e78c67f13f5215740c75ef4ec2b8ff0e9a8bd434 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Thu, 30 Aug 2018 19:57:02 +0200 Subject: [PATCH 7/7] mxgrub/mxgrub: Insert module *all_video* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With a system booted from UEFI, starting the Linux kernel from GRUB, GRUB outputs error: not suitable video mode found booting in blind mode and no Linux messages can be seen. Jordan_U’s answer from #grub@irc.freenode.net: > Are you using a manually written grub.cfg or one made by > grub-mkconfig? > > If the former, add "insmod all_video" to your grub.cfg. That will > allow grub to set up a video mode to then pass on to linux. IIRC, the > text mode for UEFI is only intended for use by bootloaders, and thus > should not be used by linux. I think that means that if grub doesn't > pass a video mode to linux (which it needs video modules to be able to > do) then you won't get early printk from the kernel, messages will > only be displayed once native graphics drivers and KMS kicks in. --- mxgrub/mxgrub | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index b2a5178..c41660a 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -257,6 +257,9 @@ password_pbkdf2 root grub.pbkdf2.sha512.10000.A1168F03CC3CD47F79848E949584EA624F set default="$MARIUX_DEFAULT" load_env + +insmod all_video + if [ -e /etc/local/USB.usb ]; then set default="mariuxUSB" menuentry "mariuxUSB" --unrestricted { save_env chosen ; linux /boot/bzImage.x86_64 crashkernel=256M root=LABEL=rootusb ro init=/bin/systemd audit=0 ; initrd /boot/grub/initramfs.igz }