Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Installing a pseudo-independent GRUB 2 bootloader.

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Installing a pseudo-independent GRUB 2 bootloader.

#1 Post by edbarx »

Warning: This is an unconventional customization of GRUB 2, use at your very own risk.

With the advent of UEFI and secure boot, dissecting grub 2 has become more of a risk, rather than a challenge alone. To workaround the new situation, I install a skeletal base system in a dedicated 1 GB partition. I do this by using debootstrap and chroot. However, it can be done using a normal installation CD/DVD with the condition that a GUI is not installed. Such a barebone installation will in the end ask to install GRUB 2 at the end which makes it bootable.

My setup ONLY makes sense in a multiboot system. Currently, I have five working installations on the same machine! :P So, it makes more sense to issue the update-grub command whenever a new installation is added to the stack. :shock: This is done by booting the installation in control of grub2 and by issuing the update-grub command as root. GRUB 2 is NOT installed in all other installations excluding the one in control of the bootloader.

To make all your installations bootable following kernel updates, you will need to edit the grub.cfg file. The linux line should use /vmlinuz and the initrd line, /initrd.img. All the rest of the respective lines is required unless you know what you are doing. You can make a backup of grub.cfg to avoid your edited versions from being overwritten.

Now, if the format of GRUB 2's menu entries doesn't appeal to your likes you can edit the grub.cfg file. However, you have to strickly observe some rules as syntax errors can easily result in an unbootable system. If you have never written programming code in an advanced programming language, I strongly tell you: YOU MUST KNOW WHAT YOU ARE DOING!

Syntax Rules:
  1. Lines starting with echo can be deleted. Text between the single quotation marks can be edited but don't use multiple lines of text.
  2. Similarly text enclosed between the single quotation marks in the line starting with menuentry can be edited.
  3. Lines starting with linux can be edited to use the symlinks in / instead of the precise kernel file name. This also applies to the line starting with initrd.
  4. The partition UUID and the partition number can be replaced with those of another partition. This is useful to add bootability to another partition without using the update-grub command.
An Example:

Code: Select all

menuentry '1:  Debian 7 on /dev/sda3' --class debian --class gnu-linux --class gnu --class os {
        load_video
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='(hd0,gpt3)'
        search --no-floppy --fs-uuid --set=root 12345678-a888-55a0-b8ee-cc9b2187dabc
        echo    'Loading Debian 7 from /dev/sda3...'
        linux   /vmlinuz root=UUID=12345678-a888-55a0-b8ee-cc9b2187dabc ro  quiet acpi_backlight=vendor
        initrd  /initrd.img
}
Note how linux and initrd only use the symlinks at the / directory. This is required so that whenever a kernel is updated to a different name, its corresponding installation still remains bootable.

Also note that edititing the menuentry line helps unclatter your grub menu. You can also include more meaningful menu entry names like:

Code: Select all

1. Squeeze LTS
2. Wheezy
3. Jessie
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

dzz
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

Re: Installing a pseudo-independent GRUB 2 bootloader.

#2 Post by dzz »

9 working systems here, plus numerous partition-resident, menu-bootable ISO's (my main OS is always current Debian Stable)

I would not be without a minimal "service" partition which controls the bootloader, similar to how you describe. I use a simple custom script which calls update-grub, in a chroot from any other system.

What I have so far failed to get working properly in grub2 is submenus, to better organise the out-of-order long menu list.

User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Re: Installing a pseudo-independent GRUB 2 bootloader.

#3 Post by edbarx »

dzz wrote:What I have so far failed to get working properly in grub2 is submenus, to better organise the out-of-order long menu list.
For that purpose you can use chainloading in which you create a master bootloader with a main meny and slave bootloaders to handle the submenus.

OR

Better still, you can try to implement sub menus within grub itself. However, this requires editing grub's source code.

Added Later:
I had a look at grub-pc's source. Have a look at menu.c, it may prove interesting for you. If I am not mistaken it is the code which displays and handles the menu.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

User avatar
jsalpha2
Posts: 25
Joined: 2013-06-17 12:19

Re: Installing a pseudo-independent GRUB 2 bootloader.

#4 Post by jsalpha2 »

GRUB 2 is NOT installed in all other installations excluding the one in control of the bootloader.
I like to install a lot of distros. I currently have about a dozen installs (all Xfce). Maybe I should use a VM, but I think real installs are better to test on. Some just don't give you the option to not install a bootloader. They may give you the option to install to a partition instead of sda.
I use GrubCustomizer (installed only on the first distro), and it is good, but can get confused if you have several similar distros. (Jessie, SolydX, Siduction and even Wakawa). They all identify themselves as Debian jessie/sid (going from memory may be a little off). When you get several distros installed GrubCustomizer gets very slow. The newest version seems even slower.
On a somewhat off subject remark, I still prefer the older version of Grub2. The advanced options folders drive me nuts. I found about 8 copies of the same entry in one folder. Would it be safe to re-install the older version (1.99?)?


Not in any special order. Jessie...SolydX...Salix...Sabayon...MX-14...Korora...Xubuntu...Manjaro...Mageia...OpenSuse...Mint...Wakawa

dzz
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

Re: Installing a pseudo-independent GRUB 2 bootloader.

#5 Post by dzz »

GRUB 2 is NOT installed in all other installations excluding the one in control of the bootloader
If installed to partition elsewhere and (in the "master" system) osprober is disabled in /etc/default/grub, only what is manually added to /etc/grub.d/40_custom (and the entry for the "master" system) will appear in the menu after update-grub. This sorts the confusing "duplicates". Chainloader entries are convenient as they still work after reformat and uuid change.

I finally got submenus (nested ones also) working with grub-pc from jessie, which installed to wheezy with only grub-common and grub-pc-bin as deps (don't try this if you don't know how to recover an unbootable system)

Dan158
Posts: 56
Joined: 2011-03-20 02:34

Re: Installing a pseudo-independent GRUB 2 bootloader.

#6 Post by Dan158 »

dzz wrote:
..... (don't try this if you don't know how to recover an unbootable system)
tl:dr ; Super GRUB2 Disk

long version;
I reciently had my grubCustomizer (I think thats what it was, it came on AVLinux) start messing up anything that was 4th in my list. AVLinux started to lose my mouse icon (but the invisible mouse would still work. lol) so I tried to change it out for a Deb-Stable distro. I still have the personal live CD of AVLinux so I'm not out any of the midi or audio stuff.
To make this short...er; I got GRUB screwed up and was being sent to a GRUB Repair shell so I found
this;

Code: Select all

http://www.supergrubdisk.org/
"Super Grub2 Disk" finds all my disrto's, including windows, and lets me boot them. Eventualy I'll repair GRUB (the OP's instructions will certainly help me with that. Thank You much edbarx ), however this works good for me right now. I can't comment on the other things there; havn't tried them.
I hope it helps a few of you searching for answers in this post.
'Help-Fascists';
Slanderers of the poor, frustrated & comp ignorant as "help-vampires"
who seek to ostracize the victim. As IRL; 'Vamps' Are increadibly rare.
Fascists though ... well, They're a dime a dozen.

Post Reply