0

I had almost finished Linux From Scratch ; However, when I tried to started the new LFS system. GRUB couldn't launch the system:

error: disk `(hd0,)' not found.

Then I used grub> ls
Output: (hd0) (hd0, gpt4) (hd0, gpt3) (hd0, gpt2) (hd0, gpt1)
I followed the instructions without anything too special, except for that I used GRUB with UEFI because my host system had been using UEFI and GPT.
Here's the partition table:

  • /dev/sda GPT
  • /dev/sda1: 512MB in size. EFI system partition. FAT32
  • /dev/sda2: 16GB in size. Linux swap. [SWAP]
  • /dev/sda3: 64GB in size. Linux x86_64 root. ext4. Host system.
  • /dev/sda4: 32GB in size. Linux x86_64 root. ext4. LFS system. I install grub in sda1. The file tree in sda1 is like:
.
├── config-5.16.9
├── EFI
│   └── LFS
│       └── grubx64.efi
├── grub
│   ├── fonts
│   ├── grub.cfg
│   ├── grubenv
│   ├── i386-pc
│   ├── locale
│   │   ├── ast.mo
│   │   ├── ca.mo
│   │   ├── ...
│   │   └── zh_TW.mo
│   └── x86_64-efi
│       ├── acpi.mod
│       ├── ...
│       └── zstd.mod
├── System.map-5.16.9
└── vmlinuz-5.16.9-lfs-11.1-systemd

And the content of grub.cfg:

set default=0
set timeout=5
insmod part_gpt
insmod vfat # I've tried fat here.  
set root=(hd0) #I've tried (hd0,gpt1), (hd0,gpt4), (hd0,1) .etc here.  

if loadfont /boot/grub/fonts/unicode.pf2; then
        set gfxmode=auto
        insmod all_video
        terminal_output gfxterm
fi

menuentry "GNU/Linux, Linux 5.16.9-lfs-11.1"{
        linux /boot/vmlinuz-5.16.9-lfs-11.1 root=/dev/sda4 ro
}

menuentry "Firmware Setup"{
        fwsetup
}

I mainly followed these references:

Also, I had set to use UEFI without CSM support or legacy.
More details:

  • GRUB version 2.06
  • LFS version 11.1-systemd
  • Linux kernel version 5.16.9
  • Secure boot disabled

1 Answer 1

0

Initially, GRUB relies on UEFI services to access the ESP, so unless you have firmware support for ext4, GRUB will only be able to read FAT32. It would be able to read ext4 after insmod ext2, but to do that, it needs to read ext2.mod first.

To gain more functionality, GRUB needs to be able to load its modules, which are apparently located in the /grub/x86_64-efi directory on /dev/sda1. But to do that, GRUB needs two important variables set correctly: root and prefix.

In your case, you want set root=(hd0,gpt1), assuming that you have only one disk. If you have multiple disks, predicting the correct hdN number can be tricky, and that's why modern distributions usually prefer to use the search --fs-uuid --set=root <UUID-of-the-filesystem> syntax instead of a direct set root=.

The prefix should be set to (hd0,gpt1)/grub. Use the set command with no parameters in the GRUB prompt to view the current state of the GRUB variables.

GRUB can only focus on one filesystem at a time, so if you are mounting /dev/sda1 as /boot, then while GRUB has root set to (hd0,gpt1), it will see /boot as /. So you should omit /boot from all paths that refer to sda1.

If you need to load something from the ext4 filesystem on /dev/sda4, you would do it as a three-step operation:

  1. insmod ext2 while root and prefix are still set as described above
  2. set root=(hd0,gpt4) to switch GRUB focus to the LFS root filesystem
  3. Load whatever you have to, keeping in mind that /boot is just an empty directory on sda4. The Linux kernel will use it later as a mount point for /dev/sda1, but that does not help GRUB at all.

So the lines you need to correct in your grub.cfg are:

...
#set root=(hd0)    # not just the disk, but the partition/filesystem GRUB will focus on
set root=(hd0,gpt1)
...
#if loadfont /boot/grub/fonts/unicode.pf2; then   # GRUB will see /boot as /
if loadfont /grub/fonts/unicode.pf2; then
...
#       linux /boot/vmlinuz-5.16.9-lfs-11.1 root=/dev/sda4 ro  # same here, also fix the kernel filename
        linux /vmlinuz-5.16.9-lfs-11.1-systemd root=/dev/sda4 ro
...

The /boot/grub/i386-pc directory is going to be utterly useless on a UEFI system; feel free to remove it.

The /boot/grub/fonts/unicode.pf2 file doesn't seem to currently exist on sda1. But since you can apparently get GRUB in text mode without it, you can live without it.

You must log in to answer this question.