3

Just want to know for understanding purpose. What is the relevance of chroot, when you can anyways do --root-directory or --boot-directory or --efi-directory with grub-install at the time of executing grub-install from a recovery CD? Or you can use either or?

  • You want grub to install with your hdd/sdd as the 'boot' device hence chroot. Without the chroot step, your 'live' media (cd/usb-thumb-drive) would be treated as the bootable device with the update-grub (ie. you'd only be able to boot with the live media installed). Yep I think it qualifies as necessary (esp. if CD is read-only!) – guiverc Jan 05 '18 at 10:28
  • @guiverc are you sure? coz, I simply mounted the root parititon and then ran grub-install with --boot-directory=/my_mounted_root_partition/boot and it worked. – infoclogged Jan 05 '18 at 10:35
  • I was told to do it, so I've always done it. It may be related to filesystems, or distro (& chroot works in all), or it was necessary with older versions, but sorry I can't recall the reason for it (I've skipped the step and had it fail, so I always do it) – guiverc Jan 05 '18 at 11:19
  • 1
    I could be wrong but I don't think older versions of grub-install allowed for the specification of the boot directory and hence the need for chroot. I've never used chroot with the newer versions. – Raman Sailopal Jan 05 '18 at 11:20
  • @RamanSailopal I came here to say the same thing, but you are first. Would you please write an answer? – Rui F Ribeiro Jan 05 '18 at 13:19
  • @RuiFRibeiro All versions of grub (for many years) have had the boot directory option.GNU GRUB Manual 0.97 (that's before 0.99 and 2.00) –  Jan 05 '18 at 21:23

2 Answers2

2

I could be wrong but I don't think older versions of grub-install allowed for the specification of the boot directory and hence the need for chroot. I've never used chroot with the newer versions

1

Yes, it is necessary.

The update of grub needs to update both the boot time loaded modules in /boot/grub as the running modules for the grub program itself (to the same version) in /usr/lib/grub/.

Only the boot loaded modules could also be updated via the specification of the boot directory in grub-install, but not the modules in /usr/lib/grub/.

To update /usr/lib/grub/ the correct filesystem needs to be mounted and the chroot allows the correct access to it. Then execute grub-update.


EDIT

Please understand that when a pen-drive system is used (as the system is unbootable), it comes with its own version of grub and modules in /usr/lib/grub/, /etc/grub.d and /etc/default/grub. Those modules are the ones that will be copied to /boot/grub if no chroot is performed. The version of such modules may be out of sync with the grub booting from the MBR (or UEFI).

The only safe way to have all grub parts in sync is to chroot to the system to be booted.

  • interesting. thought grub-mkconfig and grub-install touched only the /boot folder. Do you know, when is it required to update /usr/lib/grub too? If you just want to restore the grub menu during start up, then is it enough to run grub-install with --boot-directory option only? – infoclogged Jan 06 '18 at 09:17
  • @infoclogged Maybe the last edit will help you understand. –  Jan 07 '18 at 03:35