[Novalug] change boot menu order in grub2

Derek LaHousse dlahouss@mtu.edu
Mon Nov 17 15:21:32 EST 2014


Ok, this all looks very complicated because Grub2 is poorly documented
and coded, for that matter...  Here's what might help (From a Debian
perspective):

System boot -> Some BIOS execution -> MBR with GRUB2 code.  This code
probably launches the rest of GRUB2, as it's more than 512 bytes.  In
the past, the next 31.5 kB would be enough, but today's GRUB2 can do
RAID, LVM, and even LUKS-format cryptsetup to boot a disk.  To do so,
you need over a meg, maybe more.  So there are options for that.

Anyway, the GRUB bootloader runs by having various modules.  The core
writes modules for the root partition into the unallocated space at
the beginning of the disk (or a BIOS partition), which allows it to
search for and find the actual root disk and understand an ext2/3/4
filesystem.  At which point, it can find /boot/grub/$arch/modules and
/boot/grub/grub.cfg.  This path is configurable when you compile grub
(so your distro picked it).  IF YOU HAVE MULTIPLE ROOT FS, GRUB CAN
GET CONFUSED and find the wrong grub.cfg.

So, how is grub.cfg made?  In Debian, /etc/grub.d contains scripts.
These scripts output text which catenates to the /boot/grub/grub.cfg.
Thus, for example the one you were looking at just outputs everything
after the first three lines.  That's why you can just write directly
to it and have it end up in grub.cfg.  Portions of these scripts are
populated from variables in /etc/defaults/grub

So, the format of grub.cfg:
A bunch of logic gets parsed in this file.  It's very similar to bash
scripting, but it's not bash.  I think you're most interested in
"menuentry", which is much like menu.lst.  I'll copy sections of mine,
and then comment them

menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class
gnu --class os $menuentry_id_option
'gnulinux-simple-4280fa29-f852-4604-b44b-f56fabd22f79' {
- This line starts a stanza which is of various classes (used for
sorting, not described here).  I could set it as default either by its
index or its name, in the keyword.
    load_video
- Bring up console
    insmod gzio
    insmod part_gpt
    insmod cryptodisk
    insmod luks
    insmod gcry_rijndael
    insmod gcry_rijndael
    insmod gcry_sha512
    insmod lvm
    insmod ext2
- Load modules necessary to access the boot partition.  These were
detected during the last run of grub-mkconfig, so they get written
here.  Yes, it really loads AES twice, because GRUB is written kinda
crappy like.
    cryptomount -u 980bb878432b48bc877fe5be66ebe9e2
- This allows GRUB to ask me the password for the FS identified by that GUID.
    set root='lvmid/bYziA4-bz1V-805E-Rt2b-6NlJ-AzZg-BxQcgz/dDSo50-bBgv-Iiun-fMWs-fHyJ-NY96-7OJydJ'
- This changes the GRUB root.  In DOS, it might be "C:", or in linux "chroot"
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root
--hint='lvmid/bYziA4-bz1V-805E-Rt2b-6NlJ-AzZg-BxQcgz/dDSo50-bBgv-Iiun-fMWs-fHyJ-NY96-7OJydJ'
 4280fa29-f852-4604-b44b-f56fabd22f79
    else
      search --no-floppy --fs-uuid --set=root
4280fa29-f852-4604-b44b-f56fabd22f79
    fi
- Search is a keyword that looks for another guid and changes the root
to there.  Why we had to set root a second ago, I have no idea.
    echo    'Loading Linux 3.17.3nodistribute ...'
    linux    /boot/vmlinuz-3.17.3nodistribute
root=/dev/mapper/fermion-deb--root ro quiet
resume=/dev/mapper/fermion-swap reboot=e rootfstype=ext4
    echo    'Loading initial ramdisk ...'
    initrd    /boot/initrd.img-3.17.3nodistribute
- These are the work lines:  From rootfs 4280..., /boot/vmlinux and
/boot/initrd are put into memory, and launched according to the LINUX
convention.  Other versions are multiboot (invented by GRUB?) and
chainload (used for windows?)
}
- Close the stanza


Probably, you don't want to write a block yourself.  Just change the
"default" line in /etc/default/grub to point at the NAME of the block
you care about, to set your default booting OS.


Happy to answer questions!

On Mon, Nov 17, 2014 at 12:39 PM, Bonnie Dalzell via Novalug
<novalug@firemountain.net> wrote:
> On Mon, 17 Nov 2014, pereira via Novalug wrote:
>>>
>>> and look at wot's in that dir.  The entries all have number prefixes, and
>>> my understanding is that I'd need to change the prefix-numbers around
>>> to indicate the order that I really want.  For example, (see list at
>>> bottom),
>>> if I wanted the memtest to list first, I'd change it to:
>>>
>>> 05_memtest86+
>>>
>>>
>>> Ed James
>>>
>>>
>>> edjames@nick:/etc/grub.d$ ls -alt
>>> total 76
>>> drwxr-xr-x 138 root root 12288 Nov 16 19:39 ..
>>> drwxr-xr-x   2 root root  4096 Dec 30  2013 .
>>> -rwxr-xr-x   1 root root  7806 Dec  6  2013 00_header
>>> -rwxr-xr-x   1 root root  7877 Dec  6  2013 10_linux
>>> -rwxr-xr-x   1 root root  6449 Dec  6  2013 20_linux_xen
>>> -rwxr-xr-x   1 root root  6675 Dec  6  2013 30_os-prober
>>> -rwxr-xr-x   1 root root  1388 Dec  6  2013 30_uefi-firmware
>>> -rwxr-xr-x   1 root root   214 Oct  1  2011 40_custom
>>> -rwxr-xr-x   1 root root    95 Oct  1  2011 41_custom
>>> -rw-r--r--   1 root root   483 Oct  1  2011 README
>>> -rwxr-xr-x   1 root root  5522 Oct  1  2011 05_debian_theme
>>> -rwxr-xr-x   1 root root  1588 May  2  2011 20_memtest86+
>>>
>>> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>>> - - - - - - - - - - - - - - - -
>>>
>
> well 10_linux which is 350 lines of script does not seem to specify which
> version of linux it is booting first. It must be choosing them after a
> search of the installed systems and then putting them into
>
> /gboot/grub/grub.cfg
>
> in an order that it determines. Of course grub.cfg is the one that says "DO
> NOT EDIT THIS FILE"
>
> grub.cfg has a section for the results of the 10_linux script and I could
> cut and paste the menu entries into a new order but I think they will revert
> any time update-grub is run.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>                        Bonnie Dalzell, MA
> mail:PO box 9767 Baldwin, MD, USA 21013  |  EMAIL:bdalzell@qis.net
> shipping address:5100 Hydes Rd 21082 (Hydes Post Office closed Jan 2012)
> Freelance anatomist, vertebrate paleontologist, writer, illustrator, dog
> breeder, computer nerd & iconoclast... Borzoi info at www.borzois.com.
> HOME www.batw.net    ART bdalzellart.batw.net  BUSINESS
> www.boardingatwedge.com
>
> **********************************************************************
> The Novalug mailing list is hosted by firemountain.net.
>
> To unsubscribe or change delivery options:
> http://www.firemountain.net/mailman/listinfo/novalug



More information about the Novalug mailing list