0

I'm currently attempting to install GRUB on a disk image, for testing in QEMU. To generate the GRUB configuration file, you need to chroot into /mnt (as per this previous answer) and then run grub-mkconfig, as otherwise the command attempts to read your kernel image and initramfs from your real /boot.

I have attached my FAT32 filesystem to a loop device /dev/loop1, mounted it at /mnt and made the following further mounts:

  • A bind of /dev to /mnt/dev
  • A bind of /usr to /mnt/usr
  • A sysfs at /mnt/sys
  • A procfs at /mnt/proc

all without error. I have also created a directory /mnt/boot and /mnt/boot/grub, containing the kernel image and initramfs, and GRUB device map, respectively. However, when I attempt to run chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg to generate the configuration, it yields the cryptic error:

chroot: failed to run command `grub-mkconfig`: No such file or directory

This also happens when I replace grub-mkconfig with $(which grub-mkconfig), out of the possibility that PATH isn't exported correctly. I have verified that /mnt/usr/bin/grub-mkconfig does exist, due to the aforementioned bind mount.

When I attempt to simply run chroot /mnt, it tells me a similar message, this time with /usr/bin/bash, despite /mnt/usr/bin/bash also existing and /mnt/usr/lib and /mnt/usr/lib64 having the intended contents...

What have I done wrong here? Apologies if it's a trivial oversight.

Caelus
  • 103

1 Answers1

1

You're probably missing the dynamic loader ld.so, which is traditionally in /lib or similar (even on many "merged /usr" distributions). Each dynamically linked binary has its path embedded in the ELF header, and it functions much like the #! of shell scripts – ld.so is the real executable being run, with /usr/bin/bash as argument.

Use file to determine the exact path; for example, binaries compiled on Arch Linux x86-64 (Glibc) expect the loader to be at /lib64/ld-linux-x86-64.so.2.

grawity
  • 501,077