Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Custom grub.cfg Location
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Sikorsky42
n00b
n00b


Joined: 27 Aug 2020
Posts: 4
Location: USA

PostPosted: Thu Aug 27, 2020 2:17 pm    Post subject: Custom grub.cfg Location Reply with quote

Greetings,

I have a couple questionsa bout GRUB setup.

The grub-mkconfig command allows you to put grub.cfg wherever with the -o option. However, I can't seem to find an option for grub-install that will allow use of a directory other than /boot/grub.
I am installing on a GPT drive with UEFI. My partitioning scheme is as follows:

/dev/sda1 /boot/efi vfat
/dev/sda2 swap
/dev/sda3 / ext4

I would ideally like to be able to have everything grub needs on the /boot/efi partition. So I would like to do "grub-mkconfig -o /boot/efi/grub/grub.cfg", but how do I ensure the grub image created by grub-install knows where to find grub.cfg?


Also, is it possible (and how) to add an efi stub kernel as a grub entry?


Note, I am interested in setting it up like this so taht I can have a more specialized partitioning scheme for the rest of the system (everythign other than /boot/efi).

Thanks all!
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1404
Location: Montréal

PostPosted: Thu Aug 27, 2020 3:28 pm    Post subject: Reply with quote

Hello,

you can use the Grub command configfile to tell Grub where to find it's configuration file. For example
Code:
configfile (hd0,1)/grub/grub.cfg

will tell Grub to look in the grub directory of the root directory of the efi partition to find grub.cfg.

What I do is to remove the right of execution on every Bash script in the /etc/grub.d/ directory except 00_header and 40_custom. This way I can use 40_custom to create my own Grub menu without any other entry created by the scripts in this directory. So, when you do

Code:
grub-install --boot-directory=/boot/efi --efi-directory=/boot/efi /dev/sda

grub-mkconfig -o /boot/efi/grub/grub.cfg

I think Grub remember on which partition to look for it's files at boot time. With the configfile command it know where to find it's configuration file. So, if you tell Grub where to look for it's configuration file in 40_custom you should have the menu of this file at boot time. Note that this file must have the needed entries to be usefull.

I have see no option to tell Grub where to find it's configuration file in grub-install, grub-mkconfig and in the file /etc/default/grub other than the default /boot/grub/grub.cfg. See
Code:
info grub

_________________
Paul


Last edited by Logicien on Thu Aug 27, 2020 4:27 pm; edited 1 time in total
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1404
Location: Montréal

PostPosted: Thu Aug 27, 2020 4:19 pm    Post subject: Reply with quote

To use Linux as a efistub I configure Linux the sources to put everything needed in the Linux image including all the Linux the boot parameters to boot properly. Than you just have to create a directory for this image in /boot/efi/EFI/ and put the image in. After that you can use efibootmgr to add an entry to the Efi menu to boot directly the Linux efistub.
_________________
Paul
Back to top
View user's profile Send private message
Sikorsky42
n00b
n00b


Joined: 27 Aug 2020
Posts: 4
Location: USA

PostPosted: Thu Aug 27, 2020 4:53 pm    Post subject: Reply with quote

Thank you for the explanation of the config file location.

For the efi stub kernel, your method adds the linux efi stub kernel to the motherboard's boot list, right? I want to add the efi stub kernel as a menu entry in grub.
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1404
Location: Montréal

PostPosted: Thu Aug 27, 2020 7:00 pm    Post subject: Reply with quote

I must say that if you use the Fat Efi partition sda1 as the boot partition too, you will advoid to do the trick I have show you in my first message to force Grub to use a specific configuration file and will be able to use Grub normally through the Efi fat partition.

First you must move all the files and directories including hiden ones (except . and .. and /boot/efi) to the /boot/efi directory. Than you umount the /boot/efi directory. You suppress the /boot/efi directory. So, nothing must be in the /boot directory. Do not miss the order.

You edit /etc/fstab and change the /boot/efi mount point for sda1 to /boot. Than you mount the /boot entry in fstab. You go to the /boot directory with the shell. You see everything as before except the efi directory. So you do
Code:
ln -s . efi

Everything must work, Grub as normal and the efibootmgr command.

For efibootmgr suppose you create a new directory call /boot/efi/EFI/Stub and copy your Linux image in as the name of linux.efi. You can create an entry in the Efi menu for it. I give you this link to help you.

EFI stub kernel

Note: it's not necessary to use Grub when you want to make Linux boot as an Efistub. The Efi menu entry load the linux.efi file in the memory and than the Linux image do the rest.
_________________
Paul
Back to top
View user's profile Send private message
Sikorsky42
n00b
n00b


Joined: 27 Aug 2020
Posts: 4
Location: USA

PostPosted: Thu Aug 27, 2020 7:27 pm    Post subject: Reply with quote

That's a neat workaround with the symbolic link from /boot/efi to /boot, thereby (hopefully) tricking any existing mechanisms that rely on the EFI directory to be located at /boot/efi, which also taking care of the firmware expecting to fined the EFI directory at the root of the partition.

However, I am still not clear on how to add the EFI stub kernel to the grub menu. I know I do not need grub if all I want is to boot into linux, but I want to dual boot.
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1404
Location: Montréal

PostPosted: Thu Aug 27, 2020 8:23 pm    Post subject: Reply with quote

Grub is already load as an efi executable. If you have an entry in the Grub menu to load Linux, the only reason why you would like to add an other entry is that if your Efistub Linux image is different then the Linux image of the existing entry. It can go like this

Code:
menuentry "Linux Efistub" {
root (hd0,1)
linux /linux.img root=/dev/sda3
initrd /initramfs.img
}

You can give the title, the linux.img and the initramfs.img names you want and put those lines in /etc/grub.d/40_custom. Be sure that all the scripts in /etc/grub.d/ are executables or not depending on of what you want and do
Code:
grub-mkconfig -o /boot/grub/grub.cfg

Than if /etc/grub.d/40_custom was executable you should have a new entry in the Grub menu for the Linux Efistub.

Note that in Gentoo the defaut directory and/or configuration file name(s) for Grub may be grub2. You have to check. I am not on Gentoo. If you do not have any initramfs do not declare the line starting with initrd.

Note that when the /boot directory is a separate partition (sda1) of the Gentoo root partition (sda3) you must not say /boot/linux.img in the Grub menu entries but only /linux.img unless you do
Code:
cd /boot
ln -s . boot

It's better to do it before doing grub-mkconfig because grub-mkconfig menu entries use /boot/linux.img. Mount a separate boot partition in /boot make things more tricky. If you add the fact that sda1 is also an Efi partition it become tricky tricky.
_________________
Paul
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1404
Location: Montréal

PostPosted: Thu Aug 27, 2020 9:02 pm    Post subject: Reply with quote

Sorry, I just come to realise that with a Fat filesystem Linux symbolic links do not work. It work if the /boot directory is mount as a Linux extended filesystem but it's not possible to use this filesystem for an Efi filesystem. Only Fat is allowed.

So you cannot use boot and efi symbolic links in /boot like I told before as a workaround. grub-mkconfig may create automatic unbootable entries in the Grub menu when the /boot directory is mount as a separate partition specilly in Fat filesystem. Check by yourself.

All my Grub menu entries are made by hands in /etc/grub.d/40_custom. As a Grub alternative for Efi boot you can use rEFInd.
_________________
Paul
Back to top
View user's profile Send private message
GDH-gentoo
Guru
Guru


Joined: 20 Jul 2019
Posts: 483
Location: South America

PostPosted: Thu Aug 27, 2020 10:23 pm    Post subject: Reply with quote

Sikorsky42 wrote:
I want to add the efi stub kernel as a menu entry in grub.

To the UEFI firmware, an EFI stub kernel is just an EFI executable. Given that, you could see if GRUB's chainloader command (to run a different EFI executable) instead of the linux command in a menu entry works for this. I have never tested that. Use the insmod chain command to make GRUB load the module that implements chainloader.

I don't know why you would use EFI stub kernels if you are already using GRUB, though. GRUB doesn't need them.

Also, passing --boot-directory=/boot/efi to grub-install should already make GRUB look for grub.cfg in /boot/efi/grub, I don't think you need a configfile command.
Back to top
View user's profile Send private message
pietinger
Guru
Guru


Joined: 17 Oct 2006
Posts: 337
Location: Bavaria

PostPosted: Thu Aug 27, 2020 11:01 pm    Post subject: Re: Custom grub.cfg Location Reply with quote

Sikorsky42 wrote:
Also, is it possible (and how) to add an efi stub kernel as a grub entry?

Yes ! You treat the kernel like a kernel which isnt a stub kernel. Grub starts an efi kernel like every kernel also. I do the the same for backup reasons:

I have a stub kernel for SecureBoot. When I update the kernel to a new version, I have to sign and copy the new kernel to my ESP-partition. When my new kernel boots without problems, I do a grub install for backup reasons. See more here in my documentation (read the last part of post 2 = cheat sheet):
https://forums.gentoo.org/viewtopic-t-1112966.html
Back to top
View user's profile Send private message
GDH-gentoo
Guru
Guru


Joined: 20 Jul 2019
Posts: 483
Location: South America

PostPosted: Fri Aug 28, 2020 10:38 pm    Post subject: Reply with quote

It turns out that yes, GRUB's linux command works with both EFI stub kernels and 'regular' bzImages. One more thing I learned about GRUB.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum