Help to boot a 2nd distro with OpenWrt's grub.cfg

I am running OpenWrt x86_64. I placed another distro on my OpenWrt install's 3rd partition:

# lsblk -f
NAME          FSTYPE FSVER LABEL  UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
nvme0n1                                                                               
├─nvme0n1p1   vfat         kernel 1234-ABCD                              25.5M    20% /boot
│                                                                                     /boot
├─nvme0n1p2   ext4         rootfs ff313567-e9f1-5a5d-9895-3ba130b4a864  325.8M    31% /
├─nvme0n1p3   ext4         arch   06834425-8796-4bfe-b2ec-23d551c8f78d                
├─nvme0n1p4   ext4         data   1420e2de-b1dd-49c6-adf1-79b49c010258    440G     0% /mnt/data
└─nvme0n1p128

Rather than putting the kernel images for the other distro on OW's /boot partition, I would like to have grub use them in the target partition. I know this works, as I triple boot my work station like this (other distros do not write to the primary /boot at all).

I'd like to modify the default grub.cfg generated by the OW image to boot into it. I tried modifying it as follows but it did not work:

serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 --rtscts=off
terminal_input console serial; terminal_output console serial

set default="0"
set timeout="1"
search -l kernel -s root

menuentry "OpenWrt" {
  linux /boot/vmlinuz root=PARTUUID=7fe1d9bc-6bf4-44dc-b869-b213c3af5102 rootwait amd-pstate=passive console=tty0 console=ttyS0,115200n8 noinitrd
}
menuentry "OpenWrt (failsafe)" {
  linux /boot/vmlinuz failsafe=true root=PARTUUID=7fe1d9bc-6bf4-44dc-b869-b213c3af5102 rootwait amd-pstate=passive console=tty0 console=ttyS0,115200n8 noinitrd
}
menuentry "Arch" {
  search --no-floppy --fs-uuid --set=root 06834425-8796-4bfe-b2ec-23d551c8f78d
  echo  'Loading Linux ...'
  linux /boot/vmlinuz-linux root=/dev/nvme0n1p3 rw audit=0
  echo  'Loading initial ramdisk ...'
  initrd  /boot/amd-ucode.img /boot/initramfs-linux.img
}

Can anyone suggest a syntax that will boot it?

Install arch someplace else, see what their default grub conf looks like ?

With the grub installed:

grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
insmod part_gpt
insmod part_msdos
if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod ext2
set root='hd0,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  0abc5c57-d62c-311c-9ad4-2571a788ff95
else
  search --no-floppy --fs-uuid --set=root 0abc5c57-d62c-311c-9ad4-2571a788ff95
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
fi
terminal_input console
terminal_output gfxterm
insmod part_gpt
insmod ext2
set root='hd0,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  0abc5c57-d62c-311c-9ad4-2571a788ff95
else
  search --no-floppy --fs-uuid --set=root 0abc5c57-d62c-311c-9ad4-2571a788ff95
fi
insmod png
background_image -m stretch /boot/grub/arch.png
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=1
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=1
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Arch Linux, with Linux linux' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-advanced-0abc5c57-d62c-311c-9ad4-2571a788ff95' {
  load_video
  set gfxpayload=keep
  insmod gzio
  insmod part_gpt
  insmod ext2
  set root='hd0,gpt3'
  if [ x$feature_platform_search_hint = xy ]; then
    search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  0abc5c57-d62c-311c-9ad4-2571a788ff95
  else
    search --no-floppy --fs-uuid --set=root 0abc5c57-d62c-311c-9ad4-2571a788ff95
  fi
  echo  'Loading Linux linux ...'
  linux /boot/vmlinuz-linux root=UUID=0ebc5c57-0abc5c57-d62c-311c-9ad4-2571a788ff95 rw  audit=0 loglevel=3 quiet
  echo  'Loading initial ramdisk ...'
  initrd  /boot/intel-ucode.img /boot/initramfs-linux.img
}
menuentry 'Arch Linux, with Linux linux (fallback initramfs)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-fallback-0abc5c57-d62c-311c-9ad4-2571a788ff95' {
  load_video
  set gfxpayload=keep
  insmod gzio
  insmod part_gpt
  insmod ext2
  set root='hd0,gpt3'
  if [ x$feature_platform_search_hint = xy ]; then
    search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  0abc5c57-d62c-311c-9ad4-2571a788ff95
  else
    search --no-floppy --fs-uuid --set=root 0abc5c57-d62c-311c-9ad4-2571a788ff95
  fi
  echo  'Loading Linux linux ...'
  linux /boot/vmlinuz-linux root=UUID=0abc5c57-d62c-311c-9ad4-2571a788ff95 rw  audit=0 loglevel=3 quiet
  echo  'Loading initial ramdisk ...'
  initrd  /boot/intel-ucode.img /boot/initramfs-linux-fallback.img
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/25_bli ###
if [ "$grub_platform" = "efi" ]; then
  insmod bli
fi
### END /etc/grub.d/25_bli ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
if [ "$grub_platform" = "efi" ]; then
  fwsetup --is-supported
  if [ "$?" = 0 ]; then
    menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
      fwsetup
    }
  fi
fi
### END /etc/grub.d/30_uefi-firmware ###

EDIT: I figured it out:

  1. Needed some grub modules so I copied /boot/grub/x86_64-efi over to OpenWrt's /boot partition
  2. Used this grub stanza and it booted successfully
menuentry "arch1" {
  set root='hd0,gpt3'
  insmod gzio
  insmod part_gpt
  insmod ext2
  linux /boot/vmlinuz-linux root=UUID=06834425-8796-4bfe-b2ec-23d551c8f78d rw audit=0
  initrd  /boot/amd-ucode.img /boot/initramfs-linux.img
}

hi,

i am not a grub expert, so maybe it is totally wrong, but:

  1. according

it is missing this file, did you copy to owrt /boot next to arch linux kernel?

  1. as far as i understand grub loads the kernel from a location grub can read from, then kernel reads all the other stuff. if your arch kernel is installed to partition which is using a filesystem grub does know it will unable to load it obviously. not sure if owrt grub can read other than fat partition but i think by default /boot is not ext3/4 for a reason.

  2. personally i think uuid partition naming is a confusing overkill in a likely static environment, i.e. it is probably unlikely you are going to change disks very often, so easier to reference to /dev/<partition id> imho.

EDIT: oh, meanwhile you came to the same conclusion, ie. you need extra modules to be able to read from arch partition.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.