Bug 26987

Summary: impossibility to convert a legacy mageia7 to UEFI
Product: Mageia Reporter: peter lawford <petlaw726>
Component: InstallerAssignee: Mageia Bug Squad <bugsquad>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: Normal CC: davidwhodgins, mageia
Version: 7   
Target Milestone: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Source RPM: CVE:
Status comment:

Description peter lawford 2020-07-22 19:21:07 CEST
Description of problem:
I've recently changed my stuff from an old Intel X58 platform to a relatively recent 2011-3 with uefi on the mobo
my mageia7 boots well on the new platform provided the CSM is setted to Enabled > Legacy OPROM and to setup the boot option nokmsboot, since I have a new graphic card
I wanted to switch to uefi and ran the following command:
[root@mga6-64 alain4]# dnf install grub2-efi
the installation was successfully achieved:
[root@localhost alain4]# rpm -q grub2-efi
grub2-efi-2.02.0-15.mga7
I've formatted as vfat /dev/sda2 which is an ESP:
[root@localhost alain4]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.4

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Model: WDC WD5003AZEX-0
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 6B27DF9C-4658-4577-A6B6-9E6DA708DBA6
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            6143   2.0 MiB     EF02  BIOS boot partition
   2            6144         1439743   700.0 MiB   EF00  EFI System
   3         1439744         3897343   1.2 GiB     8300  Linux filesystem
   4         3897344        66811903   30.0 GiB    8200  Linux swap
   5        66811904       150697983   40.0 GiB    8300  Linux filesystem
   6       150697984       184252415   16.0 GiB    8300  Linux filesystem
   7       184252416       393967615   100.0 GiB   8E00  Linux LVM
   8       393967616       976773134   277.9 GiB   8300  Linux filesystem

[root@localhost alain4]# mkfs.vfat /dev/sda2
[root@localhost alain4]# mkdir -p /boot/EFI
[root@localhost alain4]# mount /dev/sda2 /boot/EFI
[root@localhost alain4] mkdir -p /boot/EFI/EFI/mageia


and installed grub2-efi:
[root@localhost alain4]# LANG=C grub2-install --target=x86_64-efi --efi-directory=/boot/EFI --bootloader-id=mageia
Installing for x86_64-efi platform.
File descriptor 4 (/dev/sda2) leaked on vgs invocation. Parent PID 13830: grub2-install
File descriptor 4 (/dev/sda2) leaked on vgs invocation. Parent PID 13830: grub2-install
EFI variables are not supported on this system.
EFI variables are not supported on this system.
Installation finished. No error reported.
checked the existence of the files:
[root@localhost alain4]# ls /boot/EFI/EFI/mageia/
grubx64.efi*
[alain4@localhost ~]$ ls /boot/grub2/
custom.cfg  fonts/  grub.cfg  grub.cfg.old  grubenv  grubenv.old  i386-pc/  install.sh*  install.sh.old*  locale/  themes/  x86_64-efi/

but no efi directory in /sys/firmware:
[root@localhost alain4]# ls /sys/firmware/
acpi/  dmi/  memmap/

rebooted, entered the BIOS again and made the change:
CSM > Enabled > UEFI only

and rebooted: no boot menu appeared and the system automatically entered the BIOS

hence, booting with UEFI is not possible





Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.
Comment 1 Dave Hodgins 2020-07-22 19:44:24 CEST
Installing Mageia on a uefi system requires that the installer has been
booted in uefi mode.

It may be possible to change it after the fact (I've never tried) by
booting a live iso in uefi firmware mode, then grub2-efi in the target
install.

I don't know if it's better to use chroot or systemd-nspawn for this.
 
Boot a live iso in uefi mode, and mount the root partition and then
chroot or systemd-spawn into it.
 
For chroot ...
#!/bin/bash
MountPoint=/targetroot
# mkdir -p $MountPoint

for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
chroot $MountPoint
#killall ssh-agent
for dir in dev proc run sys ; do umount $MountPoint/$dir ; done

For systemd-nspawn, instead of the for/chroot lines ...
systemd-nspawn -D /target


Mount the ESP on /boot/EFI in the target system, and then install grub2-efi
or refind. May be able to use mcc to select re-install boot loader.

Please report back here if it succeeds or not.

CC: (none) => davidwhodgins

Comment 2 peter lawford 2020-07-23 00:08:25 CEST
(In reply to Dave Hodgins from comment #1)
> Installing Mageia on a uefi system requires that the installer has been
> booted in uefi mode.
> 
> It may be possible to change it after the fact (I've never tried) by
> booting a live iso in uefi firmware mode, then grub2-efi in the target
> install.
> 
> I don't know if it's better to use chroot or systemd-nspawn for this.
>  
> Boot a live iso in uefi mode, and mount the root partition and then
> chroot or systemd-spawn into it.
>  
> For chroot ...
> #!/bin/bash
> MountPoint=/targetroot
> # mkdir -p $MountPoint
> 
> for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
> chroot $MountPoint
> #killall ssh-agent
> for dir in dev proc run sys ; do umount $MountPoint/$dir ; done
> 
> For systemd-nspawn, instead of the for/chroot lines ...
> systemd-nspawn -D /target
> 
> 
> Mount the ESP on /boot/EFI in the target system, and then install grub2-efi
> or refind. May be able to use mcc to select re-install boot loader.
> 
> Please report back here if it succeeds or not.

OK, I'll let you inform
Comment 3 peter lawford 2020-07-23 00:31:49 CEST
(In reply to peter lawford from comment #2)
> (In reply to Dave Hodgins from comment #1)
> > Installing Mageia on a uefi system requires that the installer has been
> > booted in uefi mode.
> > 
> > It may be possible to change it after the fact (I've never tried) by
> > booting a live iso in uefi firmware mode, then grub2-efi in the target
> > install.
> > 
> > I don't know if it's better to use chroot or systemd-nspawn for this.
> >  
> > Boot a live iso in uefi mode, and mount the root partition and then
> > chroot or systemd-spawn into it.
> >  
> > For chroot ...
> > #!/bin/bash
> > MountPoint=/targetroot
> > # mkdir -p $MountPoint
> > 
> > for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
> > chroot $MountPoint
> > #killall ssh-agent
> > for dir in dev proc run sys ; do umount $MountPoint/$dir ; done
> > 
> > For systemd-nspawn, instead of the for/chroot lines ...
> > systemd-nspawn -D /target
> > 
> > 
> > Mount the ESP on /boot/EFI in the target system, and then install grub2-efi
> > or refind. May be able to use mcc to select re-install boot loader.
> > 
> > Please report back here if it succeeds or not.
> 
> OK, I'll let you inform

question: for chroot, why to run #killall ssh-agent?
Comment 4 peter lawford 2020-07-23 01:00:23 CEST
(In reply to Dave Hodgins from comment #1)
> Installing Mageia on a uefi system requires that the installer has been
> booted in uefi mode.
> 
> It may be possible to change it after the fact (I've never tried) by
> booting a live iso in uefi firmware mode, then grub2-efi in the target
> install.
> 
> I don't know if it's better to use chroot or systemd-nspawn for this.
>  
> Boot a live iso in uefi mode, and mount the root partition and then
> chroot or systemd-spawn into it.
>  
> For chroot ...
> #!/bin/bash
> MountPoint=/targetroot
> # mkdir -p $MountPoint
> 
> for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
> chroot $MountPoint
> #killall ssh-agent
> for dir in dev proc run sys ; do umount $MountPoint/$dir ; done
> 
> For systemd-nspawn, instead of the for/chroot lines ...
> systemd-nspawn -D /target
> 
> 
> Mount the ESP on /boot/EFI in the target system, and then install grub2-efi
> or refind. May be able to use mcc to select re-install boot loader.
> 
> Please report back here if it succeeds or not.

please tell me if I have well understood what you mean: I am used tu use chroot.
first, in the BIOS, I set CSM > Enabled > UEFI only and boot on the medialive (USB key)
after that:
I'll do the following sequence of commands:

for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
chroot $MountPoint
#here /dev/sda2 is the ESP
mkdir -p /boot/EFI
mount /dev/sda2 /boot/EFI
mkdir -p /boot/EFI/EFI/mageia
grub2-install --target=x86_64-efi --efi-directory=/boot/EFI --bootloader-id=mageia
umount /dev/sda2
exit
for dir in dev proc run sys ; do umount $MountPoint/$dir ; done
umount $MountPoint

I reboot and remove the medialive 

have I well understood? thank you for replying
Comment 5 Dave Hodgins 2020-07-23 01:14:10 CEST
(In reply to peter lawford from comment #3)
> question: for chroot, why to run #killall ssh-agent?

It's commented out. In my system, as I have ssh keys setup ssh-agent is
auto started at login. Unlike most things, it normally continues running
after logout. Stopping it is needed before the file systems used in the
chroot can be unmounted.
Comment 6 Dave Hodgins 2020-07-23 01:18:26 CEST
(In reply to peter lawford from comment #4)
> please tell me if I have well understood what you mean: I am used tu use
> chroot.
> first, in the BIOS, I set CSM > Enabled > UEFI only and boot on the
> medialive (USB key)
> after that:

The exact entries shown by the uefi firmware varies depending on the
manufacturer and version. When enabled, CSM mode is used to emulate bios
firmware mode. It must be disabled to boot in uefi firmware mode.

> I'll do the following sequence of commands:
> for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
> chroot $MountPoint
> #here /dev/sda2 is the ESP
> mkdir -p /boot/EFI
> mount /dev/sda2 /boot/EFI
> mkdir -p /boot/EFI/EFI/mageia
> grub2-install --target=x86_64-efi --efi-directory=/boot/EFI
> --bootloader-id=mageia
> umount /dev/sda2
> exit
> for dir in dev proc run sys ; do umount $MountPoint/$dir ; done
> umount $MountPoint
> 
> I reboot and remove the medialive 
> 
> have I well understood? thank you for replying

I think so. Again, I've never actually tried it.
Comment 7 Martin Whitaker 2020-07-23 11:58:27 CEST
For those not comfortable with the command line, there is an easier way.

1. With the Mageia system booted in legacy mode, in the MCC, got to Local disks / Manage disk partitions. Click on your existing EFI system partition (ESP) on the HDD, and set the mount point to /boot/EFI. Answer yes when asked if you want to save /etc/fstab.

2. Boot the classical installer ISO in UEFI mode, and choose the option to upgrade your system. That should quickly run through to the summary screen, where you can select the bootloader and check that it is configured correctly. Finish the upgrade, and your system should now be bootable in EFI mode.

CC: (none) => mageia

Comment 8 peter lawford 2020-07-23 13:31:14 CEST
(In reply to Dave Hodgins from comment #6)
> (In reply to peter lawford from comment #4)
> > please tell me if I have well understood what you mean: I am used tu use
> > chroot.
> > first, in the BIOS, I set CSM > Enabled > UEFI only and boot on the
> > medialive (USB key)
> > after that:
> 
> The exact entries shown by the uefi firmware varies depending on the
> manufacturer and version. When enabled, CSM mode is used to emulate bios
> firmware mode. It must be disabled to boot in uefi firmware mode.
> 
> > I'll do the following sequence of commands:
> > for dir in dev proc run sys ; do mount --bind /$dir $MountPoint/$dir ; done
> > chroot $MountPoint
> > #here /dev/sda2 is the ESP
> > mkdir -p /boot/EFI
> > mount /dev/sda2 /boot/EFI
> > mkdir -p /boot/EFI/EFI/mageia
> > grub2-install --target=x86_64-efi --efi-directory=/boot/EFI
> > --bootloader-id=mageia
> > umount /dev/sda2
> > exit
> > for dir in dev proc run sys ; do umount $MountPoint/$dir ; done
> > umount $MountPoint
> > 
> > I reboot and remove the medialive 
> > 
> > have I well understood? thank you for replying
> 
> I think so. Again, I've never actually tried it.

question: what fs use to format the ESP? vfat? ext4?
Comment 9 peter lawford 2020-07-23 19:28:48 CEST
Hallo world the problem is now solved:
1-I couldn't boot the system in UEFI mode using the command line method; but I've forced the installer media mageia7.1 iso to boot in uefi by seeting the csm to disabled; after that, I've updated the system with the installer, and now it can boot without problem in uefi mode; in this case /sys/firmware contains the efi directory.
but there is better: if I set the csm to enabled>legacy OPROM, the system boots in legacy mode, but the efi directory vanishes in /sys/firmware
Setting once more the csm to disabled, I can boot in uefi mode, and the efi directory reappears in /sys/firmware 
it means that I can boot in legacy or uefi mode as I want, following that the csm is disabled or enabled.
I think it is due to the fact that on my disk sda1 is a bios boot partition and sda2 an ESP; that proves that the two modes of booting can cohabit on the same disk
Comment 10 Dave Hodgins 2020-07-23 19:36:35 CEST
Thanks for the update. Closing the bug as invalid, since this is not a bug,
but a request for information. In future, please use either the forums or
the discuss mailing list for such requests.

Regarding how to format the esp ...
# blkid /dev/sda1
/dev/sda1: LABEL_FATBOOT="efi" LABEL="efi" UUID="3DAB-4B6E" TYPE="vfat"

As I'm using a dos style mbr partition table format, I don't have or need
a bios boot partition since the mbr holds the bootloader.

Resolution: (none) => INVALID
Status: NEW => RESOLVED

Comment 11 peter lawford 2020-07-23 23:29:14 CEST
(In reply to Dave Hodgins from comment #10)
> Thanks for the update. Closing the bug as invalid, since this is not a bug,
> but a request for information. In future, please use either the forums or
> the discuss mailing list for such requests.
> 
> Regarding how to format the esp ...
> # blkid /dev/sda1
> /dev/sda1: LABEL_FATBOOT="efi" LABEL="efi" UUID="3DAB-4B6E" TYPE="vfat"
> 
> As I'm using a dos style mbr partition table format, I don't have or need
> a bios boot partition since the mbr holds the bootloader.

sorry, but I was convinced it was a bug, since I exactly follow the instructions (in french) given in https://wiki.mageia.org/en/Grub2-efi_et_Mageia-fr, and that unsuccessfully
Comment 12 Dave Hodgins 2020-07-24 02:09:16 CEST
That page discusses using Mageia on a uefi system, where the installer is booted
in uefi mode. It does not discuss converting a bios firmware mode install to an
uefi firmware mode install. While it apparently does work, it's not officially
been supported.

I've added vfat in the description of the esp partition on the wiki, but as the
installer takes care of creating/formatting the partition if it doesn't
already exist, that's not a bug.