How to generate grub.cfg for different disk?

5,682

Can you elaborate on what your end goal is? It seems like you have an odd need and an even more curious need of a "widescale solution." Perhaps you're trying to streamline some mini-PC installation process?

Can you chroot into your sdb OS (maybe with qemu if a different architecture)? If so, that would be the best option. Otherwise, you can look at the source of the grub-mkconfig script and customize it for your needs. I see some relevant code that shouldn't be too hard to tweak.

Share:
5,682

Related videos on Youtube

user1709408
Author by

user1709408

Updated on September 18, 2022

Comments

  • user1709408
    user1709408 over 1 year

    I have 2 disks:
    1-st disk contains base operating system (/dev/sda with many partitions and OSes)
    2-nd disc should be setup (/dev/sdb1=/boot,/dev/sdb2=/)

    I have grub2 package installed in the base operating system. I want to create grub.config file for the operating systems on the second disk (without installing grub2 package in chroot on second disk, because this disk is for different architecture. I just want to regenerate config)

    if I use

    mkdir -p /mnt/gentoo
    mount /dev/sdb2 /mnt/gentoo
    mount /dev/sdb1 /mnt/gentoo/boot
    grub-mkconfig -o /mnt/gentoo/boot/grub/grub.cfg
    

    then there is no way to specify /dev/sdb as a base disk for enumerating installed OSes for grub-mkconfig

    If disk /dev/sda contains N partitions, then grub-mkconfig creates ~ N * number_of_kernels menu entries. But I want make it creating entries for partitions of disk /dev/sdb (which have one partition /dev/sdb2 with one installed OS).

    I also tried grub-customizer utility, because it have disk selection in parameters dialog. But looks like grub-customizer uses all utilities and files which are relative to the choosen disk, and I don't have grub2 on /dev/sdb installed (see note above about different architecture)

    Someone told me that it is possible to do this by temporary correcting fstab of base system, but I doubt this will help.

    So, how to generate grub.conf for different disk? (without writing it by hands with texteditor)

    UPD: feature request - https://savannah.gnu.org/bugs/index.php?44129

    • Admin
      Admin over 9 years
      just use sudo vim /mnt/gentoo/boot/grub/grub.cfg and delete the unused entrys. And DO NOT PLAY AROUND WITH FSTAB!
    • Admin
      Admin over 9 years
      that is not widescale solution. Proper solution should add a new command line argument for grub-mkconfig i think. I just want a confirmation that there is no some tricks or other workarounds before filling feature request in bugtracker
    • Admin
      Admin over 9 years
      I always install GRUB to the other disk (grub-install /dev/sdb) then unplug it (the pc must run during the complete process) and reinstall GRUB on the onboard device (grub-install /dev/sda)
  • user1709408
    user1709408 over 9 years