Editing the GRUB entries the right way

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
saltpepperpot
Level 1
Level 1
Posts: 3
Joined: Thu Dec 15, 2022 9:58 am

Editing the GRUB entries the right way

Post by saltpepperpot »

I'm running various OSes with Mint as my default, and this question is a general query as the the best practice for changing Grub boot menu entries in Mint 21 going forward, and yes, I am aware that there are various Q&As already around this topic so feel free to point me to something if the answer is already out there, but most of the discussions around this topic I can find are out of date now. ps, I don't want to use Grub Customizer so please don't recommend that :-)

Right now I want to remove an entry that grub has auto added when I dropped in a drive with a Windows installation on it. I'm always messing with drives and OSes so this is just an example.

In /boot/grub/grub.cfg I have 2 Windows entries as follows, and I wish to remove the 2nd entry however I note the warning in the header hence this query. When I look at the files in /etc/default/grub and /etc/grub.d nothing there seems to refer to any boot options.

cat /etc/grub/grub.cgf

Code: Select all

#
# 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/30_os-prober ###
menuentry 'Windows Boot Manager (on /dev/nvme0n1p1)' --class windows --class os>
        savedefault
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root 0C87-504F
        chainloader /efi/Microsoft/Boot/bootmgfw.efi
}
menuentry 'Windows Boot Manager (on /dev/nvme1n1p1)' --class windows --class os>
        savedefault
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root F654-C732
        chainloader /EFI/Microsoft/Boot/bootmgfw.efi
Thanks
Last edited by LockBot on Thu Jun 22, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: Editing the GRUB entries the right way

Post by karlchen »

Hello, saltpepperpot.
saltpepperpot wrote: Thu Dec 22, 2022 3:34 pm Right now I want to remove an entry that grub has auto added when I dropped in a drive with a Windows installation on it.
Grub does not automatically change its boot menu, unless the terminal command sudo update-grub is executed.

Conclusion:
You have executed sudo update-grub while the drive with the Windows OS on it was connected to your machine.

Solution:
Make sure that no bootable drive is connected to your machine, which you do not want to boot through your Grub.
Then execute the terminal command sudo update-grub again.

Quick check of the list of Grub boot menu items:
Execute the terminal command grep menu /boot/grub/grub.cfg | awk -F"'" '{ print $2 }'
The output is not formatted too nicely, but it is good enough for me. :wink:

HTH,
Karl
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
linux-rox
Level 10
Level 10
Posts: 3334
Joined: Sun Jul 19, 2020 9:17 pm

Re: Editing the GRUB entries the right way

Post by linux-rox »

Not entirely certain I understand the objective, but I think the skip list parameter is what you're looking for.

Alternatively, you could disable 30_os-prober altogether, then bring in only the systems you want with 40_custom. See, e.g., Arch Wiki.

Which strategy makes sense depends, in part, on whether you generally want the "guest" drives included in Grub (or not).
User avatar
all41
Level 19
Level 19
Posts: 9520
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Editing the GRUB entries the right way

Post by all41 »

grub also gets updated with new kernels in Update Manager
But to address the topic's question--I use nano for editing.
sudo nano /etc/default/grub

Not uncommon to have more than one grub on multi-boot systems.

Find your grubs with this set of chicken scratchings(it's a long set so be sure to Select all and copy/paste):

Code: Select all

sudo fdisk -l 2>/dev/null | egrep "Disk /|/dev/" | sed "s#^/dev/#Part /dev/#" | awk '{print $2}' | sed 's/://' | xargs -n1 -IX sudo sh -c "hexdump -v -s 0x80 -n  2 -e '2/1 \"%x\" \"\\n\"' X | xargs -n1 -IY sh -c \"case  \"Y\" in '48b4') echo X: GRUB 2 v1.96 ;; 'aa75' | '5272') echo X: GRUB Legacy ;; '7c3c') echo X: GRUB 2 v1.97 or v1.98 ;; '020') echo X: GRUB 2 v1.99 ;; *) echo X: No GRUB Y ;; esac\""
I prefer my grub on a stationary drive drive independant of my multiple os drives.
So no matter how I change the os partitions around I can:

Code: Select all

sudo grub-install /dev/sda 
This drive is omni-present
Everything in life was difficult before it became easy.
bendipa
Level 5
Level 5
Posts: 581
Joined: Sat Jan 04, 2020 8:02 pm
Location: NW London. UK

Re: Editing the GRUB entries the right way

Post by bendipa »

Looks like you have installed Windows twice on 2 different M.2 disks. All you need to do is remove one of them, ie the partitions appertaining to Windows. But without seeing your partitions I can't tell you which one to remove as there are 2 ESPs involved. First I need to see the output of sudo parted -l and cat /etc/fstab.
Computer: Dell Vostro 470
Systems: Linux Mint 21.2 Xfce (Victoria), Manjaro 23.1 Xfce (Vulcan), Windows 10 (22H2) Pro.
mintinator14
Level 1
Level 1
Posts: 40
Joined: Wed Jan 04, 2023 3:02 pm
Location: Lincolnshire..UK.

Re: Editing the GRUB entries the right way

Post by mintinator14 »

If the windows drive is to be used again then i personally see no reason to continually edit the grub file unless windows is being dismissed permanently.
Dell Latitude 64 bit with Intel© Core™ i5-6300U CPU @ 2.40GHz × 2.
Linux mint 21.
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Editing the GRUB entries the right way

Post by zcot »

To add further depth as well, see here with the installation guide example of troubleshooting the efi entries: https://linuxmint-installation-guide.re ... boot-order

You wouldn't need to boot the live session you can just do it from your system. Alternately you can boot into your pc's uefi system and possibly have a nice management interface there.

If you use this efibootmgr option then just run efibootmgr --help and you will get the idea. You will need to be very sure of what entries are what, and you delete the dead one(s). You should pay attention to see what is marked as default, see if you should change the order or something. When you're done then you can update grub and it would no longer pick up the bogus entrie(s).
saltpepperpot
Level 1
Level 1
Posts: 3
Joined: Thu Dec 15, 2022 9:58 am

Re: Editing the GRUB entries the right way

Post by saltpepperpot »

Thanks @bendipa and correct. Windows is installed twice and both are required. It's 0n1 that has the additional unwanted entries.
bendipa wrote: Fri Dec 23, 2022 9:51 am Looks like you have installed Windows twice on 2 different M.2 disks. All you need to do is remove one of them, ie the partitions appertaining to Windows. But without seeing your partitions I can't tell you which one to remove as there are 2 ESPs involved. First I need to see the output of sudo parted -l and cat /etc/fstab.
cat /etc/fstab

Code: Select all

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=b10baf33-cf69-4bb5-b692-a977325351ed /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=F654-C732  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
sudo parted -l

Code: Select all

Model: ATA Samsung SSD 840 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name                  Flags
 1      1049kB  250GB  250GB  ext4         Basic data partition  msftdata

Model: ATA CT1000MX500SSD1 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  1000GB  1000GB  ntfs         Basic data partition  msftdata

Model: ATA CT1000MX500SSD1 (scsi)
Disk /dev/sdc: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  1000GB  1000GB  ntfs         Basic data partition  msftdata

Model: ATA WDC WDS200T2B0A (scsi)
Disk /dev/sdd: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  2000GB  2000GB  ntfs         Basic data partition  msftdata

Model:  USB DISK 2.0 (scsi)
Disk /dev/sde: 2004MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      65.5kB  2004MB  2004MB  primary  fat32        boot, lba

Model: ATA Crucial_CT525MX3 (scsi)
Disk /dev/sdf: 525GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name                  Flags
 1      1049kB  538MB  537MB  fat32        EFI System Partition  boot, esp
 2      538MB   525GB  525GB  ext4

Model: Sabrent Rocket 4.0 500GB (nvme)
Disk /dev/nvme0n1: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size    File system  Name  Flags
 1      1049kB  106MB  105MB   fat32              boot, esp
 2      106MB   123MB  16.8MB                     msftres
 3      123MB   499GB  499GB   ntfs               msftdata
 4      499GB   500GB  674MB   ntfs               diag

Model: Seagate FireCuda SE SSD ZP1000GM30033 (nvme)
Disk /dev/nvme1n1: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name                          Flags
 1      1049kB  106MB   105MB   fat32        EFI system partition          boot, esp
 2      106MB   123MB   16.8MB               Microsoft reserved partition  msftres
 3      123MB   1000GB  999GB   ntfs         Basic data partition          msftdata
 4      1000GB  1000GB  673MB   ntfs                                       hidden, diag
User avatar
Jo-con-Ël
Level 11
Level 11
Posts: 3576
Joined: Sun Jun 20, 2021 12:41 pm
Location: donde habita el olvido

Re: Editing the GRUB entries the right way

Post by Jo-con-Ël »

The most logical way to proceed if you are not going to keep that/those disks with other systems attached is what karlchen said (no need to modify GRUB at all) also rEFInd is a good option not to mess with grub.

In other case, the answer to your question is on linux-rox post
saltpepperpot wrote: Thu Dec 22, 2022 3:34 pm Right now I want to remove an entry that grub has auto added when I dropped in a drive with a Windows installation on it. I'm always messing with drives and OSes so this is just an example.

In /boot/grub/grub.cfg I have 2 Windows entries as follows, and I wish to remove the 2nd entry
You have two options:
1)You can try excluding certain devices when running os-prober, by example that second Windows entry from GRUB menu as follows:
-edit /etc/default/grub (you will be asked for your password twice before you can see file content on editor).

Code: Select all

xed admin:///etc/default/grub
-add following line
GRUB_OS_PROBER_SKIP_LIST="F654-C732@/EFI/Microsoft/Boot/bootmgfw.efi"
-save changes, close editor and run

Code: Select all

sudo update-grub
Ignore warning about os-prober and that menu entry was skipped and reboot.
2)Or you can disable os-prober completely and create custom entries only for ones you want.
That is, on LM 21.X edit /etc/default/grub.d/50_linuxmint.cfg

Code: Select all

xed admin:///etc/default/grub.d/50_linuxmint.cfg
-Change last line to GRUB_DISABLE_OS_PROBER=true

-Save changes and close editor.

-Create a custom entry for first Windows

Code: Select all

xed admin:///etc/grub.d/40_custom 
Add following lines (in green)
#!/bin/sh
exec tail -n +3 $0
# 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.
menuentry 'Windows Boot Manager (on /dev/nvme0n1p1)' --class windows --class os>
savedefault
insmod part_gpt
insmod fat
search --no-floppy --fs-uuid --set=root 0C87-504F
chainloader /efi/Microsoft/Boot/bootmgfw.efi
-Save change, close editor and run

Code: Select all

sudo update-grub
Last edited by Jo-con-Ël on Mon Apr 17, 2023 10:27 am, edited 5 times in total.
Arrieritos semos y en el camino nos encontraremos.
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Editing the GRUB entries the right way

Post by zcot »

there are the 2 paths dealing with this situation.

checking:

Code: Select all

efibootmgr -v
on one of the lines you look for that reference to the second entry you are concerned about: F654-C732

you see on efibootmgr --help:

Code: Select all

-B | --delete-bootnum XXXX
so if you see the reference to your second entry for example at Boot0006:

Code: Select all

sudo efibootmgr -B -b 0006
then you go to your sudo update-grub on mint, reboot, it should be gone.

So you can disable the prober as previously mentioned or just be sure not to either take updates, install a kernel(or actually any software that would trigger a kernel / initramfs / grub rebuild) when you have some other random, temporary, system plugged in, and it wouldn't get inadvertently picked up into the grub menu.
Last edited by zcot on Mon Apr 17, 2023 9:06 am, edited 1 time in total.
User avatar
Jo-con-Ël
Level 11
Level 11
Posts: 3576
Joined: Sun Jun 20, 2021 12:41 pm
Location: donde habita el olvido

Re: Editing the GRUB entries the right way

Post by Jo-con-Ël »

zcot wrote: Sun Apr 16, 2023 10:37 am there are the 2 paths dealing with this situation....
What you are proposing wont have efect on GRUB menu entries as efibootmgr is not taken into account when updating grub (nor firmware's boot manager) but Windows efi loaders it finds on EFI partition/s and they will be still there. It is nice you mentioned it in any case as there is something still not commented.

If Windows boot option on GRUB menu is removed as indicated on my previus post, OP will need another way to boot second Windows installation....It can be done from computer's boot manger/boot menu or on first Windows OS Boot Manager menu if that second Windows is included as an option.
It will depend on firmware but doing as you said, i.e. removing second Windows UEFI boot options with efibootmgr would also remove that option from computer's boot manager/boot menu, at least on next reboot. Unless second Windows was included on first Windows OS boot manager, OP would have no way to boot second Windows and would need to get into computer Setup and re-order/re-create that boot option. :(
@saltpepperpot

See above. Also I forgot to mention the better choice to keep custom entries (so no afected by grub packages update/upgrade) is creating a new XX_custom file when saving (click on File>Save as.. /etc/grub.d/XX_custom) and/or make a backup copy to use just in case, by example

Code: Select all

sudo mkdir /etc/grub.d.bkp
sudo cp /etc/grub.d/40_custom /etc/grub.d.bkp/
Last edited by Jo-con-Ël on Mon Apr 17, 2023 11:16 am, edited 2 times in total.
Arrieritos semos y en el camino nos encontraremos.
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Editing the GRUB entries the right way

Post by zcot »

Jo-con-Ël wrote: Mon Apr 17, 2023 3:01 am
zcot wrote: Sun Apr 16, 2023 10:37 am there are the 2 paths dealing with this situation....
What you are proposing
Wow! I never even realized it. I've been using a multiboot system for a year, with multiple disk, uefi setup, and I did this setup, and it appeared to work like this! But I have checked it now, and obviously it did not work that way, even though it had seemed to be that the osprober was reading the uefi table, I was sure of that! lol :shock: It had to do with the release of Ubuntu 22.04 and all the buzz about "os-prober has been disabled". I had an entry that was persistent in my setup, similar to this, even though it was not present anymore. In retrospect, I realize my main problem was that I have both disks with each containing esp. I have the prevailing grub and it was showing the not existing system(from secondary disk), and I was sure this worked, and did clear the entry forever. ha! But if I troubleshoot that now, it must be that I had never re-updated grub on the secondary system until that exact time that I made that uefi table modification. It was haunting me for 2 months with this ghost entry, and then I thought I finally fixed it! -well, I see I didn't fix it with the uefi entries though :oops:

But for this topic, I think saltpepperpot is saying that the second entry it completely irrelevant, probably will never exist on the system again, it was some test at one point. So then, removing it, from the uefi table, seems like it is not relevant. Differently, after any update-grub had been run that second entry would not be contained on the grub menu any longer. So, there is another grub holding this entry, -the chainloading situation?(as was my case) -because if that system is not even there, and we run update-grub then it would be impossible that the second, extra, Windows entry is shown.

Don't let me get on a tangent though. Maybe I am missing an important piece there.
saltpepperpot
Level 1
Level 1
Posts: 3
Joined: Thu Dec 15, 2022 9:58 am

Re: Editing the GRUB entries the right way

Post by saltpepperpot »

OK guys many thanks for taking the time to assist with this :)

For now I have taken karlchen/Jo-con-El's advice and excluded that particular drive from being probed

Code: Select all

xed admin:///etc/default/grub
2 lines added

Code: Select all

# added so that os-prober excludes nvme0n1p1
GRUB_OS_PROBER_SKIP_LIST="0C87-504F@/EFI/Microsoft/Boot/bootmgfw.efi"
Output

Code: Select all

sudo update-grub
[sudo] password for xxx:         
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50_linuxmint.cfg'
Sourcing file `/etc/default/grub.d/60_mint-theme.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found theme: /boot/grub/themes/linuxmint/theme.txt
Found linux image: /boot/vmlinuz-5.15.0-70-generic
Found initrd image: /boot/initrd.img-5.15.0-70-generic
Found linux image: /boot/vmlinuz-5.15.0-69-generic
Found initrd image: /boot/initrd.img-5.15.0-69-generic
Found linux image: /boot/vmlinuz-5.15.0-67-generic
Found initrd image: /boot/initrd.img-5.15.0-67-generic
Found linux image: /boot/vmlinuz-5.15.0-41-generic
Found initrd image: /boot/initrd.img-5.15.0-41-generic
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Skipped Windows Boot Manager on /dev/nvme0n1p1@/efi/Microsoft/Boot/bootmgfw.efi by user request.
Found Windows Boot Manager on /dev/nvme1n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
done

Code: Select all

sudo update-grub
On reboot that particular drive no longer appears as a boot option, exactly what I wanted.

I should point out that I still have the option to access Windows on the excluded drive, because after selecting the Windows boot option usiing GRUB on nvme1n1, the Windows Boot Loader then appears which allows me to chose between Windows Install 1 (nvme1n1) or Windows Install 0 (nvme0n1). This may not be the most elegant way to do things but it works and I'm not messing with it from here on.

@all41 I like the idea of installing grub on an independent drive very much and will take a look at that the next time I blat and re-build my system.

@zcot I have used the BIOS boot selection as my OS menu in the past, just a bit slow. Plus I find the 'reboot to last OS selected' feature of grub to be very useful.
Locked

Return to “Installation & Boot”