Score:0

debian 12 live grub-install:error:/boot/efi doesn't look like an EFI partition

hu flag

I have now installed the Debian 12 live environment on the USB drive and installed my own assembled Linux system (root file system compiled through busybox, grub.cfg created by myself, and Linux kernel compiled by myself) on the hard drive /dev/sda using the live environment. I encountered a problem when executing:grub-install --target=x86_64-efi --root-directory=/mnt --boot-directory=/mnt/boot /dev/sda --force --efi-directory=/boot/efi --recheck, the following message is reported:`

I found a similar problem(https://unix.stackexchange.com/questions/405472/cannot-find-efi-directory-issue-with-grub-install), but following the above steps did not solve my problem. I am a beginner and I am not sure where I wrote the problem.

1#,Divided the hard drive /dev/sda into three partitions:

/dev/sda1  
/dev/sda2 
/dev/sda3 

2#,Set sda1 as efi partition at the same time:

   $sudo  fdisk /dev/sda -l
   ...
   Device Start  End  Sectors Size    Type 
   /dev/sda1   .....                  EFI System
   /dev/sda2   .....                  Linux System
   /dev/sda3   .....                  Linux System
     

3#,Format these 3 partitions:

/sbin/mkfs.fat -F32 /dev/sda1
/sbin/mkfs.ext4 /dev/sda2
/sbin/mkfs.ext4 /dev/sda3

4#, Mount them separately in different paths:

 mount /dev/sda1 /mnt/boot/efi
 mount /dev/sda2 /mnt/boot
 mount /dev/sda3 /mnt

5#,chroot and enter a new bash

sudo chroot /mnt/
bash-5.2# grub-install --target=x86_64-efi --root-directory=/mnt --boot-directory=/mnt/boot /dev/sda --force --efi-directory=/boot/efi --recheck  
Installing for x86_64-efi platform.
grub-install:error:/boot/efi does't look like an EFI partition.
Score:0
cl flag
A.B

Step 4:

4#, Mount them separately in different paths:

mount /dev/sda1 /mnt/boot/efi
mount /dev/sda2 /mnt/boot
mount /dev/sda3 /mnt

is done in the wrong order. Each mount is overlayed by the next mount leaving only the last filesystem visible in the end. The order should be reversed (and possible missing directories created):

mount /dev/sda3 /mnt
mkdir -p /mnt/boot
mount /dev/sda2 /mnt/boot
mkdir -p /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi

While at it, for proper UEFI handling (writing what to boot in the UEFI firmware), note that at some step before grub-install, in the target result (in the /mnt chroot) these pseudo-filesystems should also be mounted:

  • sysfs on /sys
  • efivarfs on /sys/firmware/efi/efivars
ABeginner avatar
hu flag
Can executing three lines of command solve the second point you mentioned? "sudo mount --rbind /dev /mnt/dev""sudo mount --rbind /proc /mnt/proc""sudo mount --rbind /sys /mnt/sys"
A.B avatar
cl flag
A.B
Probably, but if it's about going to this level of details, can you explain how you get a bash shell between steps 3+4 (/sbin/mkfs.ext4 /dev/sda3 + mount /dev/sda3 /mnt) and step 5? Obviously there are other commands involved not provided. I'm just describing something that might not have been obvious rather than everything.
ABeginner avatar
hu flag
There are no other commands. I have solved the problem now. I have performed grub install both outside and inside of chroot, which is fine. However, I am not sure why grub install needs to be performed outside of chroot.
ABeginner avatar
hu flag
The order of the mounts you mentioned is crucial.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.