-1

As we know, EFI boot is not limited to GPT partition table, and MBR is ok.

I've a legacy disk with msdos partition table, and I'd like to reinstall it into archlinux.

In wiki:

https://wiki.archlinux.org/index.php/GRUB#UEFI_systems

it also said that GPT is not necessary.

GPT is not strictly necessary, but it is highly recommended and is the only method currently supported in this article.

What is the way to install grub EFI boot to my hard drive with MBR partition table? Thx.

Adam
  • 1,684
  • 1
  • 19
  • 39
  • UEFI use a esp-flagged partition. Check if you have one. [Related](https://unix.stackexchange.com/questions/382372/reinstall-grub-on-a-different-drive). – Random Coder 99 Aug 04 '17 at 20:28
  • Yep, one with esp and boot flag. – Adam Aug 07 '17 at 08:19
  • Then use my guide. sdb2 is supposed to be your esp partition, and sda4 your root one – Random Coder 99 Aug 07 '17 at 09:09
  • But I have only one drive, with MBR partition table. I formated a useless drive to make it esp and boot (fat32, 256MB) – Adam Aug 07 '17 at 14:27
  • Yes, you have to replace those partitions to fit your drive layout. Give me your partition layout – Random Coder 99 Aug 07 '17 at 15:08
  • `0-256MB fat32 boot,esp /boot; 50GB-100GB ext4 /root; 100GB-500GB ext4 /home`. I don't think it's related to the drive layout. The `# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=archlinux` works fine with the layout, but has the warning: `GUID Partition Table Header signature is wrong`. Does this simply imply that `grub-install` supports only EFI with GPT partition table only? – Adam Aug 07 '17 at 16:10
  • Shouldn't your efi/esp partition be /boot/efi ? Give me the content of /boot. Also, I assume /root mean / ? – Random Coder 99 Aug 07 '17 at 19:31
  • Arch said that `While some distributions require a /boot/efi or /boot/EFI directory, Arch does not.` in https://wiki.archlinux.org/index.php/GRUB . I actually did both, and it worked out the same. – Adam Aug 10 '17 at 07:20
  • I bought another disk and transferred my data there, so now it is GPT partition table and works fine. (But the question is still not solved, and I'm still very interested in it) – Adam Aug 10 '17 at 07:21
  • Arch does not need /boot/efi but your bootloader doesn't want /boot... It is not the same. – Random Coder 99 Aug 10 '17 at 08:12
  • I know it. You're right, but the directory will be created after `grub-install` command (by specifying `--efi-directory=/boot`). If I'd create my esp partition as `/boot/efi`, `grub-install` will not help me do so. – Adam Aug 10 '17 at 10:02
  • No directory will be created, and /boot isn't /boot/efi. Still waiting for the content of /boot, before and after mounting /dev/sda1 to it – Random Coder 99 Aug 10 '17 at 13:35
  • After I did `grub-install`, if I remembered it right, there're `efi/archlinux/bootx64.efi, grub/*, initrd, vmlinuz`. The names might have some suffixes. – Adam Aug 12 '17 at 02:56
  • The grub install probably didn't detect your linux since you've mounted sda1 to /boot – Random Coder 99 Aug 12 '17 at 09:02

1 Answers1

2

Assuming:

  • /dev/sda1 is your efi partition
  • /dev/sda2 is your root partition (containing /boot too)
  • Your linux kernel file is /boot/vmlinuz-linux
  • Your initrd file is /boot/initrd.img

Burn a live usb of ubuntu 16.04 with amd64 architecture, boot on it and paste these commands:

sudo os-prober
efibootmgr

Install os-prober or efibootmgr if it isn't installed yet:

sudo apt-get install os-prober
sudo apt-get install efibootmgr

Grub in efi mode is probably not installed, install it too

sudo apt-get install grub-efi-amd64-signed

Then, install grub:

sudo mount -t ext4 /dev/sda2 /mnt
sudo mount -t vfat /dev/sda1 /mnt/boot/efi
grub-install --target=x86_64-efi --efi-directory=/mnt/boot/efi --boot-directory=/mnt/boot --bootloader-id=grub

Don't try to use grub-mkconfig, it will not work. Instead, boot from your newly grub bootloader, you will have a grub shell, paste these commands:

set root=(hd0,2)
linux /boot/vmlinuz-linux root=/dev/sda2
initrd /boot/initrd.img
boot

After that, you should be on linux, mount your efi partition (to /boot/efi !) if it's not already, install grub/os-prober/efibootmgr, and run these:

sudo os-prober
grub-install --target=x86_64-efi --efi-directory=/boot/efi --boot-directory=/boot --bootloader-id=grub
grub-mkconfig -o /boot/grub/grub.cfg

Reboot, and grub is back and working

Random Coder 99
  • 376
  • 1
  • 15
  • Probably it is that I did not add `--boot-directory` to `grub-install` – Adam Aug 13 '17 at 04:40
  • In addition, if you hope to use `grub-mkconfig`, you can use `chroot`. (e.g. `chroot /mnt`, and then you can use `grub-mkconfig` safely) – Adam Aug 13 '17 at 04:42
  • I tried that, but if you chroot you have to bind some systems directories. Did that, wrecked everything. Also, if you use grub mkconfig in ubuntu it won't work (grub prefix) – Random Coder 99 Aug 13 '17 at 08:35
  • And you mounted sda1 in /boot, should have been /boot/efi. – Random Coder 99 Aug 13 '17 at 08:37
  • Oh, yep, needs binding. Wonder why ubuntu does not work. Mainly in archlinux, it would work fine. – Adam Aug 13 '17 at 09:14
  • Not sure of what I'm saying, but the problem is not with ubuntu. I saw two problems when trying to repair my grub: The real one, in the grub.cfg which is located next to the bootx64.efi. The script searched for a partition using UUID, and obviously, I was on a usb key so it was wrong. The second one is the "ubuntu" prefix, it should be "grub" or "arch_grub" for me. And the only way to fix these issues were to use grub-install in an OS you have installed, not a live USB. – Random Coder 99 Aug 13 '17 at 09:19
  • if you have mounted the disk correctly, it should get the correct UUID by `lsblk`. I don't know about the `ubuntu` prefix stuffs. (In addition, the `--bootloader-id` in `grub-install` can be named anything, so `ubuntu` should be fine) – Adam Aug 13 '17 at 09:29