You are not logged in.

#1 2018-11-03 22:27:29

skynet
Member
Registered: 2018-11-03
Posts: 9

Grub Chainloading

Hi. I've been torturing myself for the last 3 days and I am currently at a point where my mind is farting constantly. What I want to do is "simply" this :

  • Install GRUB in a dedicated partition

  • Make GRUB capable of indirect booting - chainloading - each OS boot loader

Fart #1: How come I don't have any boot flag on any partition? Proceeds to enable boot flag on /dev/sda1 and voila! Till now I was only getting a grub prompt and nothing else. I was only able to boot Arch using this :

grub> set root=(hd0,6) 
grub> linux /boot/vmlinuz-linux root=/dev/sda6 rw
grub> initrd /boot/amd-ucode.img /boot/initramfs-linux.img
grub> boot

Is the use of amd-ucode only because it's Arch x64?
After the flag change, I get grub with one Archlinux entry (must be the custom Arch entry from main GRUB(?) ) which redirects me to a grub menu with 2 Arch menu entries (must be the grub.cfg from /dev/sda6(?) ).

General Information:

        Partition Tables

Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2e7aaf97

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048    227327    225280   110M  6 FAT16
/dev/sda2          227328  63141887  62914560    30G  7 HPFS/NTFS/exFAT
/dev/sda3        63141888 976773167 913631280 435.7G  5 Extended
/dev/sda5        63143936  67338239   4194304     2G 82 Linux swap / Solaris
/dev/sda6        67340288 109283327  41943040    20G 83 Linux
/dev/sda7       109285376 151228415  41943040    20G 83 Linux
/dev/sda8       151230464 172201983  20971520    10G 83 Linux
/dev/sda9       172204032 976773167 804569136 383.7G  7 HPFS/NTFS/exFAT
  • /dev/sda1: GRUB only

  • /dev/sda2: Windows 7 (not installed)

  • /dev/sda5: Swap to be shared

  • /dev/sda6 : Arch (installed)

  • /dev/sda7: Kali (not installed --currently redownloading img)

  • /dev/sda8: Bunsenlabs (not installed)

  • /dev/sda9: Data for everyone!

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_msdos
insmod ext2
set root='hd0,msdos6'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos6' --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6  98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
else
  search --no-floppy --fs-uuid --set=root 98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_input console
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

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

menuentry 'Arch Linux' {
	insmod part_msdos
	insmod ext4
	search --no-floppy --fs-uuid --set=root 98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
	configfile /boot/grub/grub.cfg
}


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

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

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

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

Arch 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_msdos
insmod ext2
set root='hd0,msdos6'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos6' --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6  98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
else
  search --no-floppy --fs-uuid --set=root 98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_input console
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Arch Linux' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-98d05dfa-db15-4f1d-aaa9-f7d391ab89c2' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos6'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos6' --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6  98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
	else
	  search --no-floppy --fs-uuid --set=root 98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
	fi
	echo	'Loading Linux linux ...'
	linux	/boot/vmlinuz-linux root=UUID=98d05dfa-db15-4f1d-aaa9-f7d391ab89c2 rw  quiet
	echo	'Loading initial ramdisk ...'
	initrd	/boot/amd-ucode.img /boot/initramfs-linux.img
}
submenu 'Advanced options for Arch Linux' $menuentry_id_option 'gnulinux-advanced-98d05dfa-db15-4f1d-aaa9-f7d391ab89c2' {
	menuentry 'Arch Linux, with Linux linux' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-advanced-98d05dfa-db15-4f1d-aaa9-f7d391ab89c2' {
		load_video
		set gfxpayload=keep
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos6'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos6' --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6  98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
		else
		  search --no-floppy --fs-uuid --set=root 98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
		fi
		echo	'Loading Linux linux ...'
		linux	/boot/vmlinuz-linux root=UUID=98d05dfa-db15-4f1d-aaa9-f7d391ab89c2 rw  quiet
		echo	'Loading initial ramdisk ...'
		initrd	/boot/amd-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-98d05dfa-db15-4f1d-aaa9-f7d391ab89c2' {
		load_video
		set gfxpayload=keep
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos6'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos6' --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6  98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
		else
		  search --no-floppy --fs-uuid --set=root 98d05dfa-db15-4f1d-aaa9-f7d391ab89c2
		fi
		echo	'Loading Linux linux ...'
		linux	/boot/vmlinuz-linux root=UUID=98d05dfa-db15-4f1d-aaa9-f7d391ab89c2 rw  quiet
		echo	'Loading initial ramdisk ...'
		initrd	/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/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

Question #1: How can I determine at any time the contents of MBR? If I am not mistaken, with the procedure I followed the result here is : BIOS boots into MBR, MBR searches for /dev/sda1, boots GRUB.
Question #2: In my custom entry I use 'insmod ext4' and I just discovered that the Arch grub.cfg uses 'insmod ext2'. Does that mean that the ext2 module support ext4 as well? Is 'insmod ext4' wrong?
Question #3: I currently use configfile to point the grub.cfg I want to load from Arch as you've already noticed. What I want to use is chainloader +1 but when I try, I get an "invalid signature" error. Why? I installed grub in /dev/sda1 using Arch chroot.

So, having done even more research I came across a bootinfo script and I ran it. To my surprise, there is no boot sector type and info inside Arch. This has to mean that Arch has no boot loader code, right? I don't know how I achieved this but in the end doesn't this mean that I have to reinstall grub inside Arch? If so, what is the correct way of doing it without furthermore mess? Here is the boot info script:

                  Boot Info Script 0.61      [1 April 2012]


============================= Boot Info Summary: ===============================

 => Grub2 (v1.99) is installed in the MBR of /dev/sda and looks at sector 1 of 
    the same hard drive for core.img. core.img is at this location and looks 
    in partition 80 for .
    
sda1: __________________________________________________________________________

    File system:       vfat
    Boot sector type:  Grub2 (v1.99)
    Boot sector info:  Grub2 (v1.99) is installed in the boot sector of sda1 
                       and looks at sector 80227016 of the same hard drive 
                       for core.img. core.img is at this location and looks 
                       in partition 80 for . No errors found in the Boot 
                       Parameter Block.
    Operating System:  
    Boot files:        /boot/grub/grub.cfg

sda2: __________________________________________________________________________

    File system:       ntfs
    Boot sector type:  Unknown
    Boot sector info:  No errors found in the Boot Parameter Block.
    Operating System:  
    Boot files:        

sda3: __________________________________________________________________________

    File system:       Extended Partition
    Boot sector type:  -
    Boot sector info: 

sda5: __________________________________________________________________________

    File system:       swap
    Boot sector type:  -
    Boot sector info: 

sda6: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  Arch Linux ()
    Boot files:        /boot/grub/grub.cfg /etc/fstab

sda7: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        

sda8: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        

sda9: __________________________________________________________________________

    File system:       ntfs
    Boot sector type:  Unknown
    Boot sector info:  No errors found in the Boot Parameter Block.
    Operating System:  
    Boot files:        

--------------------------------------------------------------------------------
# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sda6
UUID=98d05dfa-db15-4f1d-aaa9-f7d391ab89c2	/         	ext4      	rw,relatime	0 1

--------------------------------------------------------------------------------
Unknown BootLoader on sda2

00000000  eb 52 90 4e 54 46 53 20  20 20 20 00 02 08 00 00  |.R.NTFS    .....|
00000010  00 00 00 00 00 f8 00 00  3f 00 ff 00 00 78 03 00  |........?....x..|
00000020  00 00 00 00 80 00 80 00  ff ff bf 03 00 00 00 00  |................|
00000030  04 00 00 00 00 00 00 00  ff ff 3b 00 00 00 00 00  |..........;.....|
00000040  f6 00 00 00 01 00 00 00  2f ec 1a 68 1e a3 32 38  |......../..h..28|
00000050  00 00 00 00 0e 1f be 71  7c ac 22 c0 74 0b 56 b4  |.......q|.".t.V.|
00000060  0e bb 07 00 cd 10 5e eb  f0 32 e4 cd 16 cd 19 eb  |......^..2......|
00000070  fe 54 68 69 73 20 69 73  20 6e 6f 74 20 61 20 62  |.This is not a b|
00000080  6f 6f 74 61 62 6c 65 20  64 69 73 6b 2e 20 50 6c  |ootable disk. Pl|
00000090  65 61 73 65 20 69 6e 73  65 72 74 20 61 20 62 6f  |ease insert a bo|
000000a0  6f 74 61 62 6c 65 20 66  6c 6f 70 70 79 20 61 6e  |otable floppy an|
000000b0  64 0d 0a 70 72 65 73 73  20 61 6e 79 20 6b 65 79  |d..press any key|
000000c0  20 74 6f 20 74 72 79 20  61 67 61 69 6e 20 2e 2e  | to try again ..|
000000d0  2e 20 0d 0a 00 00 00 00  00 00 00 00 00 00 00 00  |. ..............|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

Unknown BootLoader on sda9

00000000  eb 52 90 4e 54 46 53 20  20 20 20 00 02 08 00 00  |.R.NTFS    .....|
00000010  00 00 00 00 00 f8 00 00  3f 00 ff 00 00 a0 43 0a  |........?.....C.|
00000020  00 00 00 00 80 00 80 00  2f c0 f4 2f 00 00 00 00  |......../../....|
00000030  04 00 00 00 00 00 00 00  02 4c ff 02 00 00 00 00  |.........L......|
00000040  f6 00 00 00 01 00 00 00  0a b2 27 0b 7b cb 57 5a  |..........'.{.WZ|
00000050  00 00 00 00 0e 1f be 71  7c ac 22 c0 74 0b 56 b4  |.......q|.".t.V.|
00000060  0e bb 07 00 cd 10 5e eb  f0 32 e4 cd 16 cd 19 eb  |......^..2......|
00000070  fe 54 68 69 73 20 69 73  20 6e 6f 74 20 61 20 62  |.This is not a b|
00000080  6f 6f 74 61 62 6c 65 20  64 69 73 6b 2e 20 50 6c  |ootable disk. Pl|
00000090  65 61 73 65 20 69 6e 73  65 72 74 20 61 20 62 6f  |ease insert a bo|
000000a0  6f 74 61 62 6c 65 20 66  6c 6f 70 70 79 20 61 6e  |otable floppy an|
000000b0  64 0d 0a 70 72 65 73 73  20 61 6e 79 20 6b 65 79  |d..press any key|
000000c0  20 74 6f 20 74 72 79 20  61 67 61 69 6e 20 2e 2e  | to try again ..|
000000d0  2e 20 0d 0a 00 00 00 00  00 00 00 00 00 00 00 00  |. ..............|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

I omitted some stuff that are not of importance and also to make it shorter.. Why does it report that it's searching in partition 80?  I also tested a custom chainloading grub.cfg[1] - which was similar to what my goal is and the reason asking for help -  to see what I would get and I managed to reproduce the same "invalid signature" error. Is this only happening due to Arch's boot sector stuff missing? Thank you in advance and sorry for the long post, I'm trying to be as much thorough as I can..

[1]

# Config file for GRUB2 - The GNU GRand Unified Bootloader

# DEVICE NAME CONVERSIONS
#
# Linux		GRUB
#-------------------------------
# /dev/fd0	(fd0)
# /dev/sda	(hd0)
# /dev/sdb2	(hd1,2)
# /dev/sda3	(hd0,3)

# Timeout for menu (in seconds)
set timeout=60

# Default option to boot (number starts from 0)
set default=1

# Menu color options
set menu_color_normal=white/black
set menu_color_highlight=black/white
set gfxpayload=1366x768

# Menu Entry Number ---> 0
menuentry "Windows" 	{
	set root=(hd0,2)
	chainloader (hd0,2)+1
}

# Menu Entry Number ---> 1
menuentry "Arch" 	{
	set root=(hd0,6)
	chainloader (hd0,6)+1
}

# Menu Entry Number ---> 2
menuentry "Kali"	{
	set root=(hd0,7)
	chainloader (hd0,7)+1
}

# Menu Entry Number ---> 3
menuentry "Bunsenlabs"	{
	set root=(hd0,8)
	chainloader (hd0,8)+1
}

Last edited by skynet (2018-11-03 22:32:21)

Offline

#2 2018-11-06 09:55:44

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,449

Re: Grub Chainloading

Because there was no answer I try to give some hints but I have not fully troubleshooted your problem. From your post, I assume you boot in legacy BIOS mode (not UEFI), is that right?

When you install grub, it installs by default a special MBR that looks for itself and this is it. It does not look at /dev/sda1 or whatever, it only looks at the installed grub in a way that is proper to grub. After that grub itself manage the booting. With this configuration the Linux partitions are not "bootable" in the traditional sense; you cannot chainload them.

You can force grub to install itself in a partition instead of the MBR and then use a traditional MBR. With that configuration you could chainload other Linux partitions.

Note that if you want a custom configuration of grub you would have to write the entire configuration yourself and not relying on grub-mkconfig or possibly even grub-install (you have a lower level grub-setup instead). I do not remember the details on how to do this; you will have to find documentation.

Personally I find grub too complicated for its purpose. If you are on a legacy BIOS system; you can use syslinux instead which behave more traditionally (using a standard MBR) and is much easier to manage. syslinux does not behave very well on UEFI system for which I recommend rEFInd instead.

Offline

#3 2018-11-06 17:32:11

skynet
Member
Registered: 2018-11-03
Posts: 9

Re: Grub Chainloading

Thank you for your answer. Yes, it's a legacy BIOS setup. I understand the procedure in which the system boots, what I didn't comprehend was what is needed to chainload. I figured that out already, one method is the configfile and the other I'm trying to implement makes use of installed grub inside the volume's boot record. So, to sum things up, BIOS boots, reads MBR bootstrap, reads /dev/sda1's boot sector and the boot sector loads grub bootloader from its filesystem.
Since I made this post, I installed Kali and figured things out even more:

Question #1:Messed up question. If someone wants to read the contents of the MBR though, this is a way to do it.
Question #2:Grub2 (1.9x, more precisely since 1.97) supports ext2, ext3 and ext4, with the same module 'ext2.mod'.
Question #3:The invalid signature error was produced because there is nothing in Arch's boot sector to chainload from thus the only way I'm still able to boot it, is the configfile method. I have to install grub inside Arch and then chainload it from grub master. I know this works because that's how I now boot Kali and write this post.

Yes, that's the biggest wall here, this scheme being low level. I'm working on it and I still can't find a place where GRUB keys on which grub-mkconfig depends, are translated into shell scripting commands. For example 'GRUB_TIMEOUT' is translated to 'set timeout=x'. Here is an alpha version of my custom grub.cfg:

#### ========== MASTER GRUB CFG ========== ####

### DEVICE NAME CONVERSIONS ###
#
# Linux		GRUB
#------------------------------
# /dev/fd0	(fd0)
# /dev/sda	(hd0)
# /dev/sdb2	(hd1,2)

### MENU TIMEOUT ###
set timeout=60

### DEFAULT BOOT ENTRY ###
set default=1

### BEGIN MENU SETUP ###

set root=(hd0,1)
insmod font

if loadfont /boot/grub/fonts/unicode.pf2 ; then
  insmod gfxterm
  set gfxmode=1366x768
  terminal_input console
  terminal_output gfxterm
  insmod gfxmenu
  insmod png
  background_image /boot/images/image.png
  set menu_color_normal=white/black
  set menu_color_highlight=black/white
fi

### END MENU SETUP ###

### ENTRY LIST ###

# Menu Entry Number ---> 0
menuentry "Windows" 	{
	insmod ntfs
	insmod chain
	set root=(hd0,2)
	chainloader +1
}

# Menu Entry Number ---> 1
menuentry "Arch" 	{
	insmod ext2
	insmod chain
	set root=(hd0,6)
	chainloader +1
}

# Menu Entry Number ---> 2
menuentry "Kali"	{
	insmod ext2
	insmod chain
	set gfxpayload="keep"
	set root=(hd0,7)
	chainloader +1
}

# Menu Entry Number ---> 3
menuentry "Bunsenlabs" {
	insmod ext2
	insmod chain
	set root=(hd0,8)
	chainloader +1
}

As you see, I already try to prepare the background image scenario and the menu graphics. I have no clue what works and what doesn't in there as I hesitate to test it yet. All this code is accomplished reading tons of cfgs, comparing, trying to understand modules, shell code, etc. I still haven't found either documentation on manually creating a cfg without depending on mkconfig, or what code I can omit from grub without breaking it. The custom cfg has to implement stuff from what ##00_header uses to make it functional.
Is it possible to theme this low level setup using themes.txt and its images? For example.
Returning to an unanswered question, why do I have amducode when my CPU is 'Intel(R) Core(TM) i3 CPU       M 330  @ 2.13GHz' ?

Last edited by skynet (2018-11-06 17:47:02)

Offline

#4 2018-11-06 19:37:13

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,449

Re: Grub Chainloading

When I said that grub was too complicated for its purpose, I really man it and I am not the only one. There is no clear documentation on how the auto generation of the configuration file work. It is auto generated by shell scripts. You can read the grub-mkconfig script (not very long by itself but it includes other scripts).

The alternative if to try to write the configuration by hand. This is documented here but it's huge.

By default every Linux distribution that I know install grub in the MBR, which as I said does not look at /dev/sda1 or anywhere else than the installed grub (of the specific distribution). In order to chainload other Linux distributions in a classical way as you try, you need:

1) Install grub (or another boot loader) in the volume boot record for every Linux distribution. This is not the default, you may even need a "--force" option.
2) Install a classical MBR that looks at the first bootable partition and boot it (i.e. execute the volume boot record). That cannot be done with grub; it can be done with syslinux (or Windows).

If you have still questions, please tell us exactly the command you have typed (and the possible error message) and exactly what happens when you try to boot and, of course, the last version of your grub.cfg file. You will not get help for something you didn't try first.

Offline

#5 2018-11-08 02:06:23

petsam
Member
Registered: 2016-02-18
Posts: 3

Re: Grub Chainloading

>Part #1: How come I don't have any boot flag on any partition?

Because someone has to mark the partition with the boot flag. During partition creation with the used utility.
AFAIK for Linux, the boot flag is normally not needed (I maybe wrong), but I know for sure, that some problematic HW need the boot flag on MBR disks, in order to boot.

>Is the use of amd-ucode only because it's Arch x64?

For Intel CPUs you need intel-ucode, while for AMD CPUs you need amd-ucode, unless those are embedded in the kernel.

>Question #1: How can I determine at any time the contents of MBR?

For the moment, I understand that you haven't installed grub to MBR (this is when you install to /dev/sda, the drive, not the partition). If it is so, the MBR is empty.

>If I am not mistaken, with the procedure I followed the result here is : BIOS boots into MBR, MBR searches for /dev/sda1, boots GRUB.

AFAIK this is not correct. :
BIOS boots and tries to find a bootloader, starting from MBR.
If MBR is empty, it looks for a BOOT flag on any partition and if found, looks at the partition pseudo-MBR-header for a bootloader. This may defer depending HW/BIOS manufacturer, in that it may also look on all partitions for a bootloader until it finds one.
When a bootloader is found and is invalid/incomplete ( the config is missing, wrong drive entries etc) it gives an error.

>Question #3:The invalid signature error was produced because there is nothing in Arch's boot sector to chainload from thus the only way I'm still able to boot it, is the configfile method.

Correct, but
> I have to install grub inside Arch and then chainload it from grub master.

AFAIK, chainload uses individual partition's info to boot an OS on this partition. You usually boot Win with chainloading. I have not experience on booting Linux with Grub2 chainloading, so it maybe possible IF you install Grub "From this partition's OS to the same/running partition", not to MBR.

--------
If you have not realized till now that you have a mixed understanding of what is the best way to setup your partitioning/booting, I can tell you. IMHO you have to explain what result do you want, instead of asking how to do something that you don't need... wink LoL
--------
My suggestion (since you want to boot Arch first):
* Boot to Arch and install Grub to MBR.
* Disable OS prober in grub and generate grub.cfg.
* Create a custom.cfg at /boot/grub/ and insert manual menu entries for each of your installed systems, preferably with configfile, to adapt independent OS's kernel options.
* Do NOT install grub (to MBR) from any other OS, or uninstall grub package on them.
* Read some Grub guides: http://wiki.rosalab.ru/en/index.php/Gru … on_options
* Read some theming guide https://doc-0s-10-docs.googleuserconten … 6mkgm5e6mn
* Create your grub theme..

Have fun!!

Offline

#6 2018-11-09 00:58:06

skynet
Member
Registered: 2018-11-03
Posts: 9

Re: Grub Chainloading

petsam wrote:

>Part #1: How come I don't have any boot flag on any partition?

Rhetorical question to myself that was, just forgot to do it, thus labeling the whole thing as a brain fart. Then I was able to boot grub successfully. (until then I was only getting a prompt)

petsam wrote:

For Intel CPUs you need intel-ucode, while for AMD CPUs you need amd-ucode, unless those are embedded in the kernel.

Figured that out later stumbling upon the Microcode section of the wiki but unfortunately I got amd-ucode when I pacstrapped. Now it's a known bug. Instructions on uninstalling unclear.

petsam wrote:

For the moment, I understand that you haven't installed grub to MBR (this is when you install to /dev/sda, the drive, not the partition). If it is so, the MBR is empty.

skynet wrote:
============================= Boot Info Summary: ===============================

 => Grub2 (v1.99) is installed in the MBR of /dev/sda and looks at sector 1 of 
    the same hard drive for core.img. core.img is at this location and looks 
    in partition 80 for .
    
sda1: __________________________________________________________________________

    File system:       vfat
    Boot sector type:  Grub2 (v1.99)
    Boot sector info:  Grub2 (v1.99) is installed in the boot sector of sda1 
                       and looks at sector 80227016 of the same hard drive 
                       for core.img. core.img is at this location and looks 
                       in partition 80 for . No errors found in the Boot 
                       Parameter Block.
    Operating System:  
    Boot files:        /boot/grub/grub.cfg
...

So, the MBR is not empty.

petsam wrote:

AFAIK, chainload uses individual partition's info to boot an OS on this partition. You usually boot Win with chainloading. I have not experience on booting Linux with Grub2 chainloading, so it maybe possible IF you install Grub "From this partition's OS to the same/running partition", not to MBR.

That partition's info is what you get when you install grub inside Arch or any linux. (volume boot sector) The error I was getting was due to the lack of it. Once grub was installed, I had that info to tell master 'hey, chainload Arch's bootloader now!'
I explained how further I got since the 1st post, and I specifically and kindly requested any info/help on Grub's keys which are being used by grub-mkconfig to generate grub.cfg. Grub keys are variables like GRUB_DEFAULT, GRUB_THEME and so on. All these are equal to some code. [set default=x, set theme=x]
Once again, I figured that on my own. Right now, I have themed the GRUB Master and it succesfully chainloads a themed Arch grub and Kali's grub. And all that with NO dependency on grub-mkconfig. 


petsam wrote:

If you have not realized till now that you have a mixed understanding of what is the best way to setup your partitioning/booting, I can tell you. IMHO you have to explain what result do you want, instead of asking how to do something that you don't need... wink LoL

I had realized from the start my partitioning and booting scheme. The scenario was "simple" : create a dedicated partition for grub (no OS involved), install grub, point to the right direction, chainload the rest bootloaders. Made that clear since the 1st post and wrote everything down as I was still in progress of doing AND trying to figure out things.
Sure, I don't need to chainload anything. I can install grub and let it do all things alone with os-prober or customize it a little bit ( even more simply using grub customizer GUI) and leave it be. But doing things you don't need make you gain knowledge. If my grub breaks, I can still load any linux since they maintain their own bootloader. And all this procedure was just a small adventure. Now I have a proper understanding of grub2 ( when I first saw it I didn't like it - yes, call me grub legacy on ancient ubuntu x.xx), chainloading, coding a grub.cfg. One day maybe I can say I mastered it and this will be where all started. If not, what I learned will still be helpful somehow. What would I get if I let it do everything on its own?  In a future where stuff are too automated, ppl will be more stupid.  Linux is not supposed to have standards. Every user has his/her own needs, ideas, ways to do things. And that's what it makes it so great and powerful. My only disappointment in this topic is the lack of interest, and the peculiar fact that I till now haven't found anything special on manual grub configuration coding. Anyways, thanks for your reply and if I sound aggressive, trust me, I have no intention of that kind at all. I just got a little carried away and shared some thoughts.

Offline

#7 2018-11-10 17:03:59

cirrus
Member
From: Glasgow Scotland
Registered: 2012-08-24
Posts: 227
Website

Re: Grub Chainloading

Im assuming the lack of interest is due to the fact that the fine wiki
answers most of, if not all of your queries.


Registered Linux User #544546
   Time you enjoyed wasting was not wasted. --John Lennon.

Offline

#8 2018-11-11 03:53:01

petsam
Member
Registered: 2016-02-18
Posts: 3

Re: Grub Chainloading

I still believe you have some misunderstanding. I hope you answer all your questions:

https://www.gnu.org/software/grub/manual/grub/grub.html Grub2-manual

Last edited by petsam (2018-11-11 03:57:05)

Offline

Board footer

Powered by FluxBB