1

I have an odd experience. Scenario: I am writing a Linux installer (based on OpenSUSE 12.2) that runs in an initrd (actually initramfs), and I'm trying to update the bootloader. A copy of the freshly-installed filesystem is mounted on /root.

So I run this command and get this output:

+ echo 'Installing boot loader'
Installing boot loader
+ chroot /root bash -c '(ls -l /lib/modules/*/modules.dep; grub2-install /dev/sda)'
-rw-r--r-- 1 root root 45590 Apr 24 15:32 /lib/modules/3.4.47-default/modules.dep
modprobe: FATAL: Could not load /lib/modules/3.4.47-default/modules.dep: No such file or directory

The error is repeated several times, followed by an "Installation finished. No error reported." message.

If I put this code just before the command though:

mkdir -p /lib/modules/
ln -s ../../root/lib/modules/3.4.47-default/ /lib/modules

it works just fine!

Installing boot loader
Installation finished. No error reported.

Can anyone explain this?

  • Are you sure that it's the command in the chroot that's calling modprobe? Make that strace -o /tmp/chroot.strace -f chroot /root bash -c … and look at the trace to see what's going on. – Gilles Apr 25 '15 at 12:48
  • Good suggestion. Yes, I had verified it using strace, but as it turns out that's not necessary -- grub2-install is a shell script. You inspired me to search the grub2 source (I had it ready) and discovered this. The comment says "On Linux, we need the efivars kernel modules. If no EFI is available this module just does nothing besides a small hello and if we detect efi we'll load it anyway later. So it should be safe to try to load it here." The line itself is modprobe -q efivars 2>/dev/null || true ;; . – eewanco Apr 26 '15 at 18:49
  • But that line executed from grub2-install is executed in the chroot, so changing /lib/modules outside the chroot shouldn't have any effect. – Gilles Apr 26 '15 at 19:04
  • Ah, @Gilles, so you understand my point and my question. I ran modprobe using the same parameters by itself in the same environment and it works without error. But I can't imagine anything in the grub2-install shell script that would cause us to escape from the chroot jail before invoking modprobe. I am truly stymied. – eewanco Apr 27 '15 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.