Pick which grub controls start-up

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post please read how to get help
Post Reply
bwg
Level 1
Level 1
Posts: 33
Joined: Sat Jun 02, 2007 8:54 pm

Pick which grub controls start-up

Post by bwg »

I have been fooling around with dual booting (actually tri booting because I still have windows 10 on the disk even though its never used).
After a short time I usually return to my original distro. The issue is that the latest installation takes over the boot process and its version of grub is the one that controls the boot process.
Seems to me that grub should be all alone on the hard drive and not in each individual distro. That way grub would always be independent of whichever distro installed it.
Is there a way to manage this. I dont really understand the grub process well enough to mess with it without I leaving a path of Irrepairable damage in the wake.
Cant there just be partition with grub or maybe another booting proc that is independent of installed distros.
rene
Level 17
Level 17
Posts: 7751
Joined: Sun Mar 27, 2016 6:58 pm

Re: Pick which grub controls start-up

Post by rene »

It is the last distribution from which grub-install was run that controls Grub and as such, the answer's basically to not run such from any distribution that you do not want to control grub. Grub is I believe on at least Mint only ever reinstalled automatically when it is in fact updated so on it, blacklisting Grub from updating would be functional.

In any case, with e.g. /dev/sda or /dev/nvme0n1 your /-partition device, sudo grub-install /dev/sda or same with latter device specifier from the distribution that you want to control Grub should be all you need.

"Better independence" is not really generically possible, since Grub at install time needs access to /boot (and /boot/efi on UEFI-boot systems) from the distribution that it aims to boot. In theory you can share /boot over distributions by splitting it of as a partition but that actually gets even messier what with e.g. different versions of Grub from different distributions. Above is as about as good as it gets, therefore.
Last edited by rene on Tue Apr 27, 2021 10:21 am, edited 1 time in total.
bwg
Level 1
Level 1
Posts: 33
Joined: Sat Jun 02, 2007 8:54 pm

Re: Pick which grub controls start-up

Post by bwg »

So then is it possible to run grub-install from the distro that I prefer to control booting?
rene
Level 17
Level 17
Posts: 7751
Joined: Sun Mar 27, 2016 6:58 pm

Re: Pick which grub controls start-up

Post by rene »

Yes. As mentioned, with its / on /dev/foo, you run sudo grub-install /dev/foo from said distribution, with said situation disturbed later only if an automatic Grub install from another one happens to reinstall Grub automatically.
User avatar
Flemur
Level 19
Level 19
Posts: 9754
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Pick which grub controls start-up

Post by Flemur »

bwg wrote:
Tue Apr 27, 2021 6:27 am
Cant there just be partition with grub or maybe another booting proc that is independent of installed distros.
I sort-of do that, with a multi-Linux-boot installation, and one linux has the grub menu and doesn't do much except boot itself or the other linuxes.

As far as that goes, there's at least one way of preventing the Ubuntu/Mint installers from making the new installation control booting...though I forget exactly what I did, it was messing around until the installer got confused finally gave the option of not installing grub. But even if the new install wants to control boot, that's easy to fix, as per rene's post right above.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
Larry78723
Level 12
Level 12
Posts: 4370
Joined: Wed Jan 09, 2019 7:01 pm
Location: Jasper County, SC, USA

Re: Pick which grub controls start-up

Post by Larry78723 »

If the distro you're adding uses Ubiquity as the installer, it can be installed from the command line using ubiquity -b which will install the distro without installing grub.
Image
bwg
Level 1
Level 1
Posts: 33
Joined: Sat Jun 02, 2007 8:54 pm

Re: Pick which grub controls start-up

Post by bwg »

An interesting aside (at least to me) is that I installed ubuntu's boot-repair. I was hesitant to use it so i just ran it without sudo priviledges just to take a look. I tried to look and see what it suggested without running repair.
Prior to this my computer had been controlled by the grub in the latest distro I installed but after reboot it was back to using the linuxmint grub. I dont know how that happened (sheesh!) Usually those kind of unexpected occurences result in a negative result, not a positive one like this.
Anyway I want to thank everyone for the good info and help. It is appreciated.
User avatar
manyroads
Level 3
Level 3
Posts: 186
Joined: Wed Mar 30, 2011 11:14 am
Location: just around the corner
Contact:

Re: Pick which grub controls start-up

Post by manyroads »

I believe you can install grub-customizer and alter the sequence.
Be advised:
This gets more complex if you use distros from different installers like Ubiquity, calamres, Debian, etc.
Pax vobiscum,
...mark
dwm, i3wm
Professional Genealogist & Technologist (http://eirenicon.org & http://many-roads.com)
bodge99

Re: Pick which grub controls start-up

Post by bodge99 »

Hi,

You can easily install Grub to your EFI partition and link to any OS (including Windows) from there.

There are several ways of doing this (each works slightly differently). I prefer my method which leaves each installation totally "stock".
I use this particular method on every computer here that multiboots.. or with any external device that I use for maintenance (bootable OS) or installation purposes.

There are further advantages.. You can add or remove any OS without disrupting any other installed OS. By this I mean that no installed OS has "lead grub".
All you need is the location of the OS's 'grub.cfg' and the file system's UUID ('blkid' is your friend here). Every installation is totally standard and it doesn't matter which device it is installed to.

If you want any help with this, just ask here..

Bodge99
bwg
Level 1
Level 1
Posts: 33
Joined: Sat Jun 02, 2007 8:54 pm

Re: Pick which grub controls start-up

Post by bwg »

I would really be interested in finding out the steps involved in installing grub on the efi parttition. Although I plan on sticking with my present distro, I really do like the freedom to experiment :)
bodge99

Re: Pick which grub controls start-up

Post by bodge99 »

Hi,

This method will work with just one distro installed... I'll post something later today.. things to do, for an hour or so.

More later.

Bodege99
User avatar
Flemur
Level 19
Level 19
Posts: 9754
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Pick which grub controls start-up

Post by Flemur »

Larry78723 wrote:
Tue Apr 27, 2021 9:35 am
If the distro you're adding uses Ubiquity as the installer, it can be installed from the command line using ubiquity -b which will install the distro without installing grub.
Yes, thanks, that's something I always forget. I tried to "install" Mint 20.0 just now to see how I tricked it into not taking control of booting, but the installer kept hanging before it got that far.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
bodge99

Re: Pick which grub controls start-up

Post by bodge99 »

Install Grub To EFI Partition:

It takes longer to read this post than it does to "do the job".
This work can be performed from a Linux Live flashdrive, if required.

If there is **anything** that you don't understand here, or if you have **any** questions at all, then please ask here **before** proceeding.

Identify your EFI partition:

Either run 'gparted' or

Code: Select all

sudo fdisk -l
Typical output (shortened for clarity):

Code: Select all

Device         Start        End   Sectors   Size Type
/dev/sda1       4096     618495    614400   300M EFI System
/dev/sda2     618496  512618495 512000000 244.1G Linux filesystem
/dev/sda3 1881857369 1953520064  71662696  34.2G Linux swap
Your Device's may show as '/dev/sda1', /dev/mmcblk0p1', '/dev/nvme0n1p1' etc.
Identify your EFI partition. I'll use '/dev/sda1' for simplicity. Adjust to suit yours.

Required EFI partition size: A minimum of 50MB. I do "other things.." here, so I need 300MB.

Note: If you wish to use a GUI text editor as Root, use 'sudo'. e.g. for 'Xed' use 'sudo xed'.

Create a text file containing the following. Save it as 'grub.cfg' somewhere safe.

Sample 'grub.cfg'. This will be edited and copied to its proper location later.

Code: Select all

menuentry "My Installed Linux" {
    search --set=root --fs-uuid UUID-here
    set prefix=($root)/boot/grub
    configfile $prefix/grub.cfg
}

Comments are within braces and are not to be entered. (Does not apply to the contents of any 'grub.cfg')

Backup existing EFI partition contents:
If performing this from a flashdrive, create a mountpoint (e.g. /mnt1) and mount your system partition to '/mnt1'.
From a terminal:

Code: Select all

sudo su {Become Root}
mkdir /EFI-Original {Create an EFI backup directory}
mount /dev/sda1 /mnt {mount EFI partition to /mnt}
cp -R /mnt/* /EFI-Original
ls -R /mnt          {Both listings should be identical}
ls -R /EFI-Original {Just look for "lots of files..."}
rm -rf /mnt/*  {Delete everything in the EFI partition}

{This installs Grub to /mnt (the EFI partition)                                             ***ADJUST THIS*** }
grub-install --recheck --boot-directory=/mnt/EFI/BOOT --efi-directory=/mnt --target=x86_64-efi /dev/sda
Find the UUID for your system partition's filesystem:

If you know that your system is on sda2 then:

Code: Select all

blkid | grep sda2 > myUUID.txt {Create a text file containing your UUID} 
For all UUID's:

Code: Select all

blkid > allUUID.txt
Typical output of 'allUUID.txt'

Code: Select all

/dev/sda1: UUID="077C-A8CF" TYPE="vfat" PARTUUID="5cad599b-7902-ed47-abb7-47578ea6671f"
/dev/sda2: LABEL="Mint" UUID="c6c46625-b726-4656-bbba-cf85c35add35" TYPE="ext4" PARTLABEL="Mint" PARTUUID="fb00a7ab-255f-f248-96a3-a4c6ec631051"
/dev/sda3: UUID="840c0a0c-982d-4bb4-b831-df2f7492985d" TYPE="swap" PARTUUID="d455cf7f-c164-a343-a655-f5fa2d41e331"

Ignore 'LABEL','PARTLABEL' and 'PARTUUID'. You want the UUID of your system partition's filesystem. Here, it is 'c6c46625-b726-4656-bbba-cf85c35add35'.
Edit your 'grub.cfg' that you created earlier. Replace 'UUID-here' with your UUID.
Using this UUID, the file would be:

Code: Select all

menuentry "My Installed Linux" {
    search --set=root --fs-uuid c6c46625-b726-4656-bbba-cf85c35add35
    set prefix=($root)/boot/grub
    configfile $prefix/grub.cfg
}
Now copy this file to its proper location.

Code: Select all

cp /path-to-file/grub.cfg /mnt/EFI/BOOT/grub {Copy your new 'grub.cfg' to its correct location}
Finally, make a backup of the EFI directory.

Code: Select all

mkdir /mnt/EFI-backup
cp -R /mnt/EFI/* /mnt/EFI-backup
umount /mnt
Done
Reboot and test.


EFI partition layout, ignoring the backup directory.

Code: Select all

"EFI Partition Root"
└── EFI
    ├── BOOT
    │   ├── BOOTX64.EFI
    │   ├── fbx64.efi
    │   ├── grub
    │   │   ├── fonts
    │   │   │   └── unicode.pf2
    │   │   ├── grub.cfg {2}
    │   │   ├── grubenv
    │   │   └── x86_64-efi
    │   │       ├── acpi.mod
    │   │       ├── adler32.mod
    :   :       :
    │   │       ├── zfs.mod
    │   │       └── zstd.mod
    │   └── mmx64.efi
    └── ubuntu
        ├── BOOTX64.CSV
        ├── grub.cfg {1}
        ├── grubx64.efi
        ├── mmx64.efi
        └── shimx64.efi
{1} Initial 'grub.cfg'. This sets the Grub prefix properly. This is required with most UEFI hardware. It then calls the '/EFI/BOOT/grub/grub.cfg'
{2} Manually created. This has simple menuentries.. These search for filesystems (by UUID) and then point to the individual systems 'grub.cfg' etc.

Initial 'grub.cfg' file contents. File {1} above.

Code: Select all

search.fs_uuid 077C-A8CF root 
set prefix=($root)'/EFI/BOOT/grub'
configfile $prefix/grub.cfg
The UUID here is that of the EFI partition's 'fat32' filesystem.

Maintenance:

Any Grub updates will add files here that will alter boot behaviour (i.e. the computer will boot to the OS that installed the Grub update.).
These changes are trivial to undo, but it is easier to delete the contents of the 'EFI' directory and copy the contents the 'EFI-backup' over.

Code: Select all

sudo su
mount /dev/sda1 /mnt
rm -rf /mnt/EFI/*  {Delete everything in the EFI directory}
cp -R /mnt/EFI-backup/* /mnt/EFI
umount /mnt
Adding a second OS:
Install as normal. This installation will alter the EFI directory contents, so fix this by copying back (as above).
Edit the 'grub.cfg' (/EFI/BOOT/grub/grub.cfg'). Add the following:

Code: Select all

menuentry "New Linux" {
    search --set=root --fs-uuid UUID-here
    set prefix=($root)/boot/grub
    configfile $prefix/grub.cfg
}
Adjust the menuentry title and add the required filesystem UUID. Most system's have their 'grub.cfg' in '/boot/grub/grub.cfg'.
Others use a different location. e.g. OpenSuse uses '/boot/grub2/grub.cfg'. You would need to adjust the prefix setting here (e.g. change from 'set prefix=($root)/boot/grub' to 'set prefix=($root)/boot/grub2'.

Any questions.. just ask here.

Bodge99
Post Reply