Skip to content

Add support for UEFI installations #53

Merged
merged 7 commits into from
Sep 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion mxgrub/mxgrub
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ 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';
}

# 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 {
Expand Down Expand Up @@ -245,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 }
Expand Down Expand Up @@ -303,8 +318,21 @@ sub cmd_install {

update_grub_cfg();

if (has_esp) {
sys 'mount','-L','ESP','/boot/efi' and exit 1;
if (-d '/boot/efi/EFI/grub/grubx64.efi') {
print "GRUB for UEFI is already installed.\n";
}
else {
sys 'grub-install','--target=x86_64-efi','--no-nvram',$root_disk and exit 1;
}
sys 'umount','/boot/efi' and exit 1;
}

if ($mbr_type ne 'GRUB') {
sys 'grub-install',$root_disk and exit 1;
sys 'grub-install','--target=i386-pc',$root_disk and exit 1;
} else {
print "GRUB is already installed in MBR.\n";
}

if ($label eq 'default') {
Expand Down Expand Up @@ -353,6 +381,16 @@ 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 {
print "System booted using UEFI: no\n";
}
} else {
@ARGV==1 or die USAGE;
cmd_install($ARGV[0]);
Expand Down