Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to make GRUB pass PARTUUID to the kernel
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
AaylaSecura
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jun 2011
Posts: 122

PostPosted: Tue Aug 09, 2016 12:11 pm    Post subject: How to make GRUB pass PARTUUID to the kernel Reply with quote

Greetings! I'm using GRUB2 to boot into Gentoo, no initram, and I can't figure out how to make GRUB use the fs UUID (or partition UUID, I don't mind) instead of the device name, like sda3. Everytime I plug in a flash drive, this one gets assigned to the sda disk and I get a kernel panic. In /etc/default/grub I have:

Code:
GRUB_DISABLE_LINUX_UUID=false


and I tried enabling device-mapper support (I'm not sure if that's needed)... no difference. I see the menu that's generated contains:

Code:
   set root='hd0,msdos3'
   if [ x$feature_platform_search_hint = xy ]; then
     search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos3 --hint-efi=hd0,msdos3 --hint-baremetal=ahci0,msdos3  5094d9fa-c4f0-452b-94db-760d2789d247
   else
     search --no-floppy --fs-uuid --set=root 5094d9fa-c4f0-452b-94db-760d2789d247
   fi


as far as I know the --set=root 5094d9fa-c4f0-452b-94db-760d2789d247 should override the previously set root (hd0,msdos3) unless the search fails. What I don't understand is what the feature_platform_search_hint is and how to disable that hint to make it only use UUIDs...


Last edited by AaylaSecura on Wed Aug 10, 2016 3:26 am; edited 1 time in total
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2971
Location: Germany

PostPosted: Tue Aug 09, 2016 12:38 pm    Post subject: Reply with quote

A hint should just tell Grub which device is the most likely candidate so it spends less time searching all other devices for this UUID. Flash drives and such don't affect GRUB.

It sounds like your problem is not GRUB at all but your initramfs or kernel parameters.

If GRUB managed to load your kernel then GRUB is done and over and didn't have a problem.

If your kernel messes up the boot process then your kernel/initramfs/fstab/... has a problem or it got the wrong parameters.
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


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

PostPosted: Tue Aug 09, 2016 12:41 pm    Post subject: Reply with quote

Hello,

If the Grub2 /etc/grub.d/ scripts do not allow you to boot by the filesystem UUID, you have to create you own entries in /etc/grub.d/40_custom. This is what I do. I disable execution rights on all scripts in /etc/grub.d/ except 00_header and 40_custom. Than I create all the Grub2 entries my my own. This entry should work for you

Code:
menuentry "Gentoo" {
    set root=UUID=5094d9fa-c4f0-452b-94db-760d2789d247
    linux /boot/bzImage root=UUID=094d9fa-c4f0-452b-94db-760d2789d247
}


Correct the filesystem UUID value if needed according of the output of the blkid command for your Gentoo root filesystem and add other kernel parameters you want to the real kernel image name. Do not disable any execution right to Grub2 scripts until a successful boot with this entry. Do a Grub2 update configuration file
Code:
grub2-mkconfig -o /boot/grub2/grub.cfg

I am not sure of the exact configuration file path and name of Gentoo Grub2. I use ArchLinux Grub2 to boot all my systems.

Note that you have to set /etc/fstab to use filesystem UUID's too to mount filesystems. I never use partition UUID's. I use LABEL's for everything. It's more human readable.
_________________
Paul
Back to top
View user's profile Send private message
AaylaSecura
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jun 2011
Posts: 122

PostPosted: Wed Aug 10, 2016 12:24 am    Post subject: Reply with quote

frostschutz wrote:
or it got the wrong parameters.

Yes, this was my point. Sorry I should have clarified I know GRUB loads the kernel fine and is done then, but it is responsible for passing it the root parameter. I just saw in /boot/grub/grub.cfg that it passes it root=/dev/sda3 no matter what. So when I plug in the flash drive, GRUB still finds the root partition, since it searches by UUID, but the kernel panics cause it searches for sda3, which is not there. So how can I tell GRUB to pass root=PARTUUID to the kernel?

Logicien wrote:
If the Grub2 /etc/grub.d/ scripts do not allow you to boot by the filesystem UUID, you have to create you own entries in /etc/grub.d/40_custom

Thanks, sure I can do that, but I really wanted to avoid it and make use of GRUB's automatic menu creation. And I can't use the fs UUID on the kernel cmdline (I can use it in fstab, no problem), since I am not using an initarmfs and the kernel doesn't know the fs UUID's, so it panics. I need the PARTUUID there. By the way set=root=UUID does not work for GRUB, it can't find the kernel, it says
Code:
error: disk ... not found

I can use the search command again in my custom entry of course.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2971
Location: Germany

PostPosted: Wed Aug 10, 2016 1:17 am    Post subject: Reply with quote

AaylaSecura wrote:
So how can I tell GRUB to pass root=PARTUUID to the kernel?


I don't know - the code you posted is not related to that at all so no clue what your config looks like.

(I actually use a custom/handwritten config because the generated stuff looks so horrible... hated grub2 until I wrote my own config same way I did for grub1, then it turned out to be simple)
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


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

PostPosted: Wed Aug 10, 2016 2:42 am    Post subject: Reply with quote

Sorry about filesystem UUID. I miss the fact that it depend on an initramfs. One thing I remark is when I plug a Usb key in my laptops Asus EeePc 900 and Lenovo Thinkpad T420, for the Bios and the Bios/Efi this key become sda (hd0) and move the main internal hard drive to sdb (hd1). I never boot with a Usb key in.

On my desktop HP Compaq 6000 Pro I have 2 internal hard drives. No matter how many Usb keys I plug in they always stay sda and sdb for the Bios.

Check if there is a Bios/Efi option who allow to set the boot drives priority. Grub can swap the disks order. I did it a few times with Grub1. Maybe you can have an entry for this when there is a Usb key plugged in. You are on your own.
_________________
Paul
Back to top
View user's profile Send private message
AaylaSecura
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jun 2011
Posts: 122

PostPosted: Wed Aug 10, 2016 3:22 am    Post subject: Reply with quote

frostschutz wrote:
I don't know - the code you posted is not related to that at all so no clue what your config looks like.

Yeah, I just couldn't find what options there are apart from DISABLE_LINUX_UUID (which I normally set to true, since root=UUID does not work for me, but just for testing I tried setting to false---GRUB still passes root=/dev/sda3; maybe it knows UUID will not work without an initramfs?). In any case, here is my config

Logicien wrote:
Check if there is a Bios/Efi option who allow to set the boot drives priority. Grub can swap the disks order. I did it a few times with Grub1. Maybe you can have an entry for this when there is a Usb key plugged in. You are on your own.

Aha! Indeed, in my UEFI settings I had set USB initialization during POST to partial, meaning only USB keyboards/mice will be initialized. Which then meant that the kernel adds other USB devices and apparently it adds USB disks before SATA ones. Once I let my MoBo initialize all USB devices, the SSD stays first, HDD second and all USB flash drives follow, which is the normal order; and I boot fine. Thanks!

I'll not mark it as solved though, cause I'm still interested if there's a way to configure GRUB2 to pass PARTUUID to the kernel. I couldn't find info on how to reorder devices either, will look more into that, as well as how to tell the kernel the order in which it should add disks.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 7138
Location: Saint Amant, Acadiana

PostPosted: Wed Aug 10, 2016 10:21 am    Post subject: Reply with quote

Write your own.
_________________
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
bpkent
n00b
n00b


Joined: 17 Feb 2011
Posts: 13

PostPosted: Tue Oct 25, 2016 8:32 pm    Post subject: Reply with quote

AaylaSecura wrote:
frostschutz wrote:
I don't know - the code you posted is not related to that at all so no clue what your config looks like.

Yeah, I just couldn't find what options there are apart from DISABLE_LINUX_UUID (which I normally set to true, since root=UUID does not work for me, but just for testing I tried setting to false---GRUB still passes root=/dev/sda3; maybe it knows UUID will not work without an initramfs?). In any case, here is my config

Logicien wrote:
Check if there is a Bios/Efi option who allow to set the boot drives priority. Grub can swap the disks order. I did it a few times with Grub1. Maybe you can have an entry for this when there is a Usb key plugged in. You are on your own.

Aha! Indeed, in my UEFI settings I had set USB initialization during POST to partial, meaning only USB keyboards/mice will be initialized. Which then meant that the kernel adds other USB devices and apparently it adds USB disks before SATA ones. Once I let my MoBo initialize all USB devices, the SSD stays first, HDD second and all USB flash drives follow, which is the normal order; and I boot fine. Thanks!

I'll not mark it as solved though, cause I'm still interested if there's a way to configure GRUB2 to pass PARTUUID to the kernel. I couldn't find info on how to reorder devices either, will look more into that, as well as how to tell the kernel the order in which it should add disks.

In my /etc/default/grub I have:

Code:
GRUB_DISABLE_LINUX_UUID=true

and:
Code:
GRUB_DEVICE="PARTUUID=812..."

Apparently GRUB_DEVICE is not for use by end users ("it's internal-use variable, you shouldn't override it" from grub bug 44611), but hey, it worked for me :). As I understand it, grub dev expects users to have initrds and thus be able to use filesystem UUIDs, rather than partition UUIDs.

Also, if you're not using gentoo-sources you may need to apply the fix for bug 467266.
Back to top
View user's profile Send private message
AaylaSecura
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jun 2011
Posts: 122

PostPosted: Tue Oct 25, 2016 8:58 pm    Post subject: Reply with quote

bpkent wrote:
In my /etc/default/grub I have:

Code:
GRUB_DISABLE_LINUX_UUID=true

and:
Code:
GRUB_DEVICE="PARTUUID=812..."

Apparently GRUB_DEVICE is not for use by end users ("it's internal-use variable, you shouldn't override it" from grub bug 44611), but hey, it worked for me :).

Thanks, it's good to know this variable exists.

bpkent wrote:
As I understand it, grub dev expects users to have initrds and thus be able to use filesystem UUIDs, rather than partition UUIDs.

This is indeed what I ended up using. Guess there's no other way to make use of PARTLABEL or FS LABEL.
Back to top
View user's profile Send private message
cord
Guru
Guru


Joined: 28 Apr 2007
Posts: 303

PostPosted: Sun Oct 30, 2016 3:10 pm    Post subject: Reply with quote

You can add
Code:
GRUB_CMDLINE_LINUX_DEFAULT="root=PARTUUID=XXXXXXXXXXXXXX"

to /etc/default/grub
And there will be something like that in result grub.cfg:
Code:
linux /vmlinuz-3.15.5-r2 root=/dev/sda3 ro root=PARTUUID=ХХХХХХХХХХХХХХХХХХ

The second definition of 'root' has major priority, so it will work.
You can also edit grub.cfg manually and remove the first definition.

ps Are you using SATA drive?
Back to top
View user's profile Send private message
AaylaSecura
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jun 2011
Posts: 122

PostPosted: Sun Oct 30, 2016 10:35 pm    Post subject: Reply with quote

cord wrote:
You can add
Code:
GRUB_CMDLINE_LINUX_DEFAULT="root=PARTUUID=XXXXXXXXXXXXXX"

to /etc/default/grub
And there will be something like that in result grub.cfg:
Code:
linux /vmlinuz-3.15.5-r2 root=/dev/sda3 ro root=PARTUUID=ХХХХХХХХХХХХХХХХХХ

The second definition of 'root' has major priority, so it will work.
You can also edit grub.cfg manually and remove the first definition.

ps Are you using SATA drive?

Thanks for the tip. Yes, it's a SATA SSD.
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