Remove legacy grub, switch to UEFI (with grub or refind)

Here is my problem in short: after two days of fight, despite seemingly doing everything as recommended in different forums, I cannot remove legacy GRUB2 and force my machine to load EFI GRUB2 (or refind) boot manager.

Now, the long description.

I have an ASUS r556L laptop, in which I had installed linux OpenSuse Leap 42.1 and windows 10. Linux grub2 was installed in legacy mode, as for windows - I am not sure, but my grub2 manager loaded Windows boot manager (i vaguely remember i called the relevant entry “boot windows mbr manager”) and everything was just fine. My family was using windows, while I was working on linux.

Two days ago someone from my family have upgraded Windows 10. After the upgrade, obviously the machine could not load neither linux nor windows.

After two hours of googling I find out what happened, burned my old install iso on dvd and I was able to get back the linux system. Now, grub2 was in legacy mode, and after much brooding I decided that maybe the reason I can’t load Windows is that maybe windows was in EFI mode, and, besides, I should use grub2 in EFI mode on EFI machine, right?

So here is what I did
Boot from DVD
(1) /sys/firmware/efi exists; efibootmgr gives the proper entries, so definetely I have booted in EFI mode
(2) /dev/sda2 is EFI; /dev/sda8 is my linux partition.
(3) I had /dev/sda6 as grub_bios. I have made a backup copy using dd, then I have destroyed the partition and just to be sure, before that i have filled it with zeroes using dd if=/dev/zero of=/dev/sda6 count=XXXX

(4) I have removed /dev/sda2; then I have recreated it again using gdisk, setting is as EFI partition (ef00), and
formatted using mkfs.vfat /dev/sda2

mount /dev/sda8 /mnt

mount /dev/sda2 /mnt/boot/efi

for i in /dev/ /dev/pts /proc /sys; do mount $i /mnt/$i -B; done

modprobe efivars # just to be sure

chroot /mnt

efibootmgr

BootCurrent: 0004
Timeout: 1 seconds
BootOrder: 0004,0001,0002,0003
Boot0001* CD/DVD Drive
Boot0002* Hard Drive
Boot0003* Network Card
Boot0004* UEFI: HL-DT-ST DVDRAM GUC0N

grub2-install --target x86_64-efi /dev/sda

Installing for x86_64-efi platform.
Installation finished. No error reported.

grub2-mkconfig -o /boot/grub2/grub.cfg

efibootmgr -b 0002 -B # removing non-uefi hard drive option, just to be sure

efibootmgr -o 0003,0001 # setting opensuse, then efi dvd

Just to be sure, efibootmgr now sees everything just fine: that efi opensuse should be loaded first.

efibootmgr -v

BootCurrent: 0004
Timeout: 1 seconds
BootOrder: 0000,0004,0001,0003
Boot0000* opensuse HD(2,e1800,32000,aab2a73b-d4b9-4dce-bbfd-f00e41d393c9)File(\EFI\opensuse\grubx64.efi)
Boot0001* CD/DVD Drive BIOS(3,0,00)…GO…NO…o.H.L.-.D.T.-.S.T. .D.V.D.R.A.M. .G.U.C.0.N…^?..A…^?..>…Gd-.;.A…MQ…L.W.K.F.5.A.4.2.9.1.0. .6. . . . . . . . …^?..BO
Boot0003* Network Card BIOS(6,0,00)…GO…NO…k.R.e.a.l.t.e.k. .P.X.E. .B.0.2. .D.0.0…^?..rN.D+…,…^?..<…Gd-.;.A…MQ…L.R.e.a.l.t.e.k. .P.X.E. .B.0.2. .D.0.0…^?..BO
Boot0004* UEFI: HL-DT-ST DVDRAM GUC0N ACPI(a0341d0,0)PCI(1f,2)03120a000100ffff0000CD-ROM(1,3b1,229c60)…BO

gdisk -l /dev/sda

GPT fdisk (gdisk) version 0.8.8

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

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): EB75204E-7462-4BA9-A901-83746823FA22
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 234025 sectors (114.3 MiB)

Number Start (sector) End (sector) Size Code Name
1 2048 923647 450.0 MiB 2700 Basic data partition
2 923648 1128447 100.0 MiB EF00 EFI System
3 1128448 1161215 16.0 MiB 0C01 Microsoft reserved part
4 1161216 1542056771 734.8 GiB 0700 Basic data partition
5 1542057984 1543921663 910.0 MiB 2700
7 1543942144 1547943935 1.9 GiB 0700 primary
8 1548152832 1953523711 193.3 GiB 0700 primary

According to everything I have read this should be enough and everything should work.

REBOOT

(1) What appears is just “GRUB” and nothing else (computer hangs; no grub prompt or anything)
(2) Before I have removed /dev/sda6, it seems it had been loading legacy grub instead of efi (because after choosing
menu entries it was complaining about initrdefi and linuxefi commands)
(3) In BIOS, in boot section only non-EFI options appeared + EFI DVD
(4) after rebooting into rescue mode using EFI DVD, efibootmgr does not see opensuse (which I have set previously). Everything looks as before I had done.

Now, in BIOS I have no “enable EFI” option. I have option “Launch CSM”, which I have enabled; without this option NOTHING could be booted, with this option EFI DVD is booted just fine (it looks like in this image I have googled:
https://www.google.pl/search?q=asus+r556l+bios+options&client=firefox-b-ab&dcr=0&source=lnms&tbm=isch&sa=X&ved=0ahUKEwj0-4b-wp_XAhWMHxoKHWa_Do4Q_AUICygC&biw=1366&bih=613#imgrc=m4OVpmargw_qgM:)

In BIOS, the same options as before are available for boot: non-EFI DVD and HDD, and EFI DVD.

I tried downloading refind and using both automatic and manual installation, and the result was all the same (i.e. seems like legacy GRUB boot manager is still chosen, presenting me with “GRUB” and then hangs).

I don’t want to remove all the partitions and reinstall everything. This is basically out of option. I can fall back to legacy grub, which would mean I would have access to linux, but no access to windoze.

here is output of parted -l:

Model: ATA ST1000LM024 HN-M (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: pmbr_boot

Number Start End Size File system Name Flags
1 1049kB 473MB 472MB ntfs Basic data partition hidden, diag
2 473MB 578MB 105MB fat16 EFI System boot
3 578MB 595MB 16.8MB Microsoft reserved partition msftres
4 595MB 790GB 789GB ntfs Basic data partition
5 790GB 790GB 954MB ntfs hidden, diag
7 790GB 793GB 2049MB linux-swap(v1) primary
8 793GB 1000GB 208GB xfs primary

Le 02/11/2017 à 10:26, szopen76 a écrit :
> and, besides, I should use grub2 in EFI mode on EFI machine, right?

wrong

as far as I know you can’t change simply a legacy install for an efi one
(neither in Windows than Linux).

I don’t say it can’t be done, but not by changing grub.

EFI boot needs an EFI partition. Windows needs also a GPT disk. Opensuse
accommodate what you have

so apart if you did a full windows reinstall, with disk reformatting,
it’s very unlikely that the boot system was changed

jdd

What do you mean by that? I have /dev/sda2 EFI System partition; do you mean that I should remove /dev/sda8 (currently containing ext4 filesystem) and create new, 200GB partition with type of EFI?!? DOes that mean that data partitions (containing linux system) differ in type depending on whether you chose booting by EFI or legacy?!

If really data partitions created by non-EFI installation cannot be booted from EFI bootloader, then I guess I would have to go back to legacy grub; however, how can I then boot windows 10? With legacy grub all I got was “invalid signature” (secure boot is disabled in BIOS and in grub).

Le 02/11/2017 à 11:06, szopen76 a écrit :
>
> What do you mean by that? I have /dev/sda2 EFI System partition;

what do you see in /boot/EFI ? do you see windows (or microsoft)

do you
> mean that I should remove /dev/sda8 (currently containing ext4
> filesystem) and create new, 200GB partition with type of EFI?!? DOes
> that mean that data partitions (containing linux system) differ in type
> depending on whether you chose booting by EFI or legacy?!

no

>
> If really data partitions created by non-EFI installation cannot be
> booted from EFI bootloader, then I guess I would have to go back to
> legacy grub; however, how can I then boot windows 10? With legacy grub
> all I got was “invalid signature” (secure boot is disabled in BIOS and
> in grub).
>
>
if YaST installed legacy grub it’s most certainly because the install
was done in legacy mode. Linux can manage any variation of EFI/legacy +
MSDOS/GPT partition, but Windows can’t and if so openSUSE can’t boot
windows.

I have this on one of my computers, I can boot legacy openSUSE fro an
other EFI install (on other disk), but not Windows. I could manage the
problem with the EFI boot manager, asking to boot the legacy first disk
with Windows.

A copy of sudo fdisk -l could be a good clue (http://susepaste.org/ or
in the post)

you can have an EFI partition and a legacy install, but not an EFI
install without EFI partition

jdd

I have efi partition. I see the usual /boot/efi/EFI with Boot, Microsoft and opensuse. In opensuse I have removed all the previous files and right now I have only grubx64.efi.

But at this point I would like just to boot Linux in EFI mode.

AS for fdisk -l:
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: EB75204E-7462-4BA9-A901-83746823FA22

Device Start End Sectors Size Type
/dev/sda1 2048 923647 921600 450M Windows recovery environment
/dev/sda2 923648 1128447 204800 100M EFI System
/dev/sda3 1128448 1161215 32768 16M Microsoft reserved
/dev/sda4 1161216 1542056771 1540895556 734.8G Microsoft basic data
/dev/sda5 1542057984 1543921663 1863680 910M Windows recovery environment
/dev/sda7 1543942144 1547943935 4001792 1.9G Microsoft basic data
/dev/sda8 1548152832 1953523711 405370880 193.3G Microsoft basic data

Here are the contents of /boot/efi/EFI:

total 0
drwxr-xr-x 2 root root 25 Dec 2 08:42 Boot
drwxr-xr-x 4 root root 34 Dec 2 08:42 Microsoft
drwxr-xr-x 2 root root 25 Dec 2 08:42 opensuse

sda8/backup_EFI/EFI/Boot:
total 120
-rwxr-xr-x 1 root root 122368 Dec 2 08:42 bootx64.efi

sda8/backup_EFI/EFI/Microsoft:
total 4
drwxr-xr-x 42 root root 4096 Dec 2 08:42 Boot
drwxr-xr-x 2 root root 64 Dec 2 08:42 Recovery

sda8/backup_EFI/EFI/Microsoft/Boot:
total 4776
-rwxr-xr-x 1 root root 49152 Dec 2 08:42 BCD
-rwxr-xr-x 1 root root 65536 Dec 2 08:42 BCD.LOG
-rwxr-xr-x 1 root root 0 Dec 2 08:42 BCD.LOG1
-rwxr-xr-x 1 root root 0 Dec 2 08:42 BCD.LOG2
-rwxr-xr-x 1 root root 65536 Dec 2 08:42 BOOTSTAT.DAT
drwxr-xr-x 2 root root 4096 Dec 2 08:42 Fonts
drwxr-xr-x 3 root root 38 Dec 2 08:42 Resources
drwxr-xr-x 2 root root 53 Dec 2 08:42 bg-BG
-rwxr-xr-x 1 root root 4669 Dec 2 08:42 boot.stl
-rwxr-xr-x 1 root root 1224600 Dec 2 08:42 bootmgfw.efi
-rwxr-xr-x 1 root root 1209760 Dec 2 08:42 bootmgr.efi
-rwxr-xr-x 1 root root 115616 Dec 2 08:42 bootspaces.dll
[CUT the rest, as there are several dozen files there]

Currently I tried to remove all the files in /boot/efi/ and went with the all the procedure again, until there is only /boot/efi/EFI/opensuse/grubx64.efi, and it has not changed anything.

I don’t know why it keeps loading old grub. Also, I presume I should see EFI entries in BIOS, but I keep seeing there only “EFI DVD” and two non-efi options (non-efi dvd and hard drive). Moreover, why after every reboot all the changes i have done using efibootmgr are gone?

Le 02/11/2017 à 11:36, szopen76 a écrit :
>
> I have efi partition. I see the usual /boot/efi/EFI with Boot, Microsoft
> and opensuse. In opensuse I have removed all the previous files and
> right now I have only grubx64.efi.

seems good

>
> But at this point I would like just to boot Linux in EFI mode.

should be done through Firmware/BIOS or boot menu

> Disklabel type: gpt

so combination UEFI/GPT, good

> /dev/sda2 923648 1128447 204800 100M EFI System

good

> /dev/sda7 1543942144 1547943935 4001792 1.9G Microsoft basic data
> /dev/sda8 1548152832 1953523711 405370880 193.3G Microsoft basic data

I guess these last two are your linux swap and /. Could be better with
linux partition type, but I don’t think it’s really important

> Currently I tried to remove all the files in /boot/efi/ and went with
> the all the procedure again, until there is only
> /boot/efi/EFI/opensuse/grubx64.efi,

not a good idea, may prevent Windows booting

and it has not changed anything.

the data may be saved in nvram
>
> I don’t know why it keeps loading old grub.

may be there are several successive installs, one previous in efi mode
and the last in legacy mode?? just a wild guess :frowning:

Also, I presume I should see
> EFI entries in BIOS, but I keep seeing there only “EFI DVD” and two
> non-efi options (non-efi dvd and hard drive). Moreover, why after every
> reboot all the changes i have done using efibootmgr are gone?
>
>
arch wiki is known to be good for efi

https://wiki.archlinux.fr/EFI_Boot_Stub

but efibootmgr is tricky, I always managed to make the boot config with Yast

jdd

Thank, jdd. Even if it does not help, I appreciate that you have committed your time trying to find a solution.

Right now I gave up and installed legacy grub. At least I can boot linux, even if windows is unavailable.

Maybe someone else will know what to do. The key questions are:
(1) Why even after installing grub-efi (grub2-install --target x86_64-efi, with no errors) the systems starts legacy grub ?
(2) Why, despite everything being seemingly ok (efibootmgr showing right thing, gdisk showing the right thing, no errors) after a reboot EFI is not seen in BIOS and all the changes seem to disappear (i.e. after reboot efibootmgr sees no previous changes).

Le 02/11/2017 à 13:36, szopen76 a écrit :
>
> Thank, jdd. Even if it does not help, I appreciate that you have
> committed your time trying to find a solution.
>
> Right now I gave up and installed legacy grub. At least I can boot
> linux, even if windows is unavailable.

did you try yast? (for boot manager)

jdd

yes, I did. The first thing I tried, actually; I have moved to more manual methods once yast failed.

Le 02/11/2017 à 15:16, szopen76 a écrit :
>
> yes, I did. The first thing I tried, actually; I have moved to more
> manual methods once yast failed.
>
>
:slight_smile:

I will have to test moving from grub2 to grub2-efi and vice-versa. When
I find time :frowning:

fact is uefi firmware is so buggy that it’s difficult to port experience
from a computer to an other

jdd

I read this thread but are not quite sure, what you already tried so far. So i will just describe how i would proceed. Maybe it is of some help to you:

Make sure

  • UEFI is up-to-date
  • UEFI is set to UEFI-boot (i.e. no CSM or legacy boot)
  • the hard drive (which carries openSUSE and Windows) has a valid GPT partition scheme (protected MBR, …)
  • there is only one EFI-partition (Type 0xEF00) on the hard drive (which carries openSUSE and Windows)
  • the grub2-installation of the openSUSE system on the hard drive (which carries openSUSE and Windows) is up-to-date
  • that the file “/etc/default/grub/” (in the openSUSE root partition of the hard drive which carries openSUSE and Windows) contains the lines
    >GRUB_USE_LINUXEFI=“true”<
    >GRUB_DISABLE_OS_PROBER=“false”<
    (no “><” needed !)
  • the directory “/boot/grub2” (in the openSUSE root partition of the hard drive which carries openSUSE and Windows) exists and contains all the neccessary information (like directory “x86_64-efi”)

Boot the system using the rescue option from the openSUSE 42.3 Installation DVD (or use any other appropriate rescue media that will boot in UEFI-mode) and become “root”. Then do

# mount /dev/sdxy /mnt(/dev/sdxy is the openSUSE root partition off the hard drive which carries openSUSE and Windows)
# mount /dev/sdxz /mnt/boot/efi(/dev/sdxz is the EFI partition off the hard drive which carries openSUSE and Windows)
# mount -o bind /dev /mnt/dev
# mount -o bind /run /mnt/run
# mount -o bind /sys /mnt/sys
# mount -o bind /proc /mnt/proc
# chroot /mnt
# grub2-install --recheck --nobootsector --target=x86_64-efi
# grub2-mkconfig -o /boot/grub2/grub.cfg
# exit

Reboot the system.

Good luck!

Regards

susejunky

Up to this point, most of what you did sounded about right.

However, booting is handled by your firmware (sometimes called BIOS). You have to set your BIOS to boot in UEFI mode.

I can’t tell you how to do that, because it varies between computers. Some computers can boot either way. On one of my computers, I can set it to “prefer UEFI” or “prefer CSM”. If there is a setting to disable CSM, try that.

Note that CSM is short for “compatibility support module” and is what you use for legacy booting. I have CSM disable on both of my UEFI boxes.

The initial legacy GRUB bootsector gets loaded, then it reads core.img from the disk location where /dev/sda6 was and jumps to it. I doubt sequence of zero bytes will do anything useful to boot your system.

Either find out how to enable EFI boot or recover legacy grub2.

That’s the problem. I have only one option in BIOS which could be related to UEFI, called “Launch CSM”. As I have written in my first post, if I had it disabled, nothing gets loaded. After a reboot, machine immediately comes back to BIOS.

If it is enabled, it does load DVD in UEFI mode (confirmed by the fact that when I boot rescue DVD by choosing “UEFI DVD” in Bios (option called “override boot sequence” or something like that), there is /sys/firmware/efi, that efibootmgr works).

That would indicate to me that “Launch CSM” does not prevent system from loading EFI.

On the other hand, Should the correct EFI partition should be visible in BIOS as one of the choices to boot from? If BIOS sees only DVD as “UEFI” while not seeing any other options, and if disabling “Launch CSM” prevents booting at all, this could indicate that maybe something is wrong with EFI system partition.

But what?

I had done pretty much everything from googled step-by-step guides, including found in this forum (and even in this thread). I wiped the partition clean, created it anew with gdisk with type EF00 (d(elete), n(ew partition), w(rite and exit)), mkfs.vfat it, and then made grub2-install /dev/sda (and once I even tried grub2-install /dev/sda2). I tried both with only opensuse on it, and with windows files on it. I tried copying grubx64 as bootx64 on /boot/efi/EFI

The flags for /dev/sda2 are only “boot” and nothing else.

The only thing I had not tried is downloading new firmware for ASUS.

Right now I have reverted to legacy grub2. I guess I will try creating EFI partition in a new place, maybe using different tool (gparted?) instead of gdisk. The only other option is to backup everything to an external drive, install both systems anew (first windows, then linux) and see whether it helps. That is however a nuclear option and I would like to avoid it, as I spent quite a lot of time downloading additional packages; I could simply clone everything and only recreate the partition tables, but that, on the other hand, would require me to find a lot of free disk space.

Le 03/11/2017 à 10:06, szopen76 a écrit :

> If it is enabled, it does load DVD in UEFI mode (confirmed by the fact
> that when I boot rescue DVD by choosing “UEFI DVD” in Bios (option
> called “override boot sequence” or something like that), there is
> /sys/firmware/efi, that efibootmgr works).

can’t you do the same with install dvd? It wouldn’t be necessary to make
a real install, but only go up to the software choice and check if it’s
really grub-efi that is loaded?

> On the other hand, Should the correct EFI partition should be visible in
> BIOS as one of the choices to boot from? If BIOS sees only DVD as “UEFI”
> while not seeing any other options, and if disabling “Launch CSM”
> prevents booting at all, this could indicate that maybe something is
> wrong with EFI system partition.

IMHO something is wrong with uefi firmware :frowning:

> The flags for /dev/sda2 are only “boot” and nothing else.

this is no more relevant for efi

>
> The only thing I had not tried is downloading new firmware for ASUS.

if there is one, it could be a good idea

eventually you could use an other disk for test purpose (if you don’t
use too much this compute right now)

can you recall me what asus computer you have (I have one also myself
and had an other also some weeks ago - sold now)

jdd

Not necessarily. EFI boot does not work this way. The worst thing is, EFI is API between firmware and program, as for end-user behavior, it does not not mandate anything, so vendors are free to do whatever they want without risking to become non-compliant.

this could indicate that maybe something is wrong with EFI system partition.

Try to make sure it is FAT32; I know some vendors do have problems with it.

Although firmware is still expected to at least show boot menu even if it will later fail to actually boot. But again - vendors are free to filter offered choices based on what they think they can do.

Sorry, but that is nothing that can be solved from openSUSE side. You may have better luck with vendor’s forum.

The reason i put it on the first place in my checklist (#11) is: i got my first UEFI two years ago and most of the problems i had could be solved by installing the latest firmware.

Regards

susejunky

So… I made sure the /dev/sda2 is fat32. I have deleted it, recreated it, double-checked the type, formatted, double-checked it is fat32, I installed only opensuse and nothing else. Nothing. Then I copied the backup EFI files; nothing.
I’ve checked the BIOS version, it’s up to date.

It’s ASUS r556L.

Anyways, seems nothing worked, so I got back to legacy grub. I will try reinstall everything some time in the future.

Thanks everyone for your help!

If no EFI boot is present the installer will create it also the EFI boot must beside being FAT be of EF00 type.

If you boot the installer in EFI mode the defaults should be right. You know it is booted in legacy if you see options along the bottom of the menu screen. EFI mode does not have those options

Le 03/11/2017 à 13:56, szopen76 a écrit :

> It’s ASUS r556L.

I have a 550, probably not so different, but asus do so many computers :frowning:
>
> Anyways, seems nothing worked, so I got back to legacy grub. I will try
> reinstall everything some time in the future.
>

you don’t need uefi. I don’t use it because my disk come from an other
older computer

jdd