View previous topic :: View next topic |
Author |
Message |
dmpogo Advocate

Joined: 02 Sep 2004 Posts: 3511 Location: Canada
|
Posted: Fri May 09, 2025 9:56 pm Post subject: Where does GRUB2 take root UUID from ? |
|
|
Basically, the subject. grub-mkconfig generates grub.cfg with particular root UUID - where does it take it from ?
My particular scenario - I want to migrante / to another disk temporarily. In a first instance I planned to keep untouched /boot/efi/EFI which is on a separate
partition, and all efibootmng entries. I can copy / to another disk, change /etc/fstab, in case copy /boot/all the kernels and /boot/grub to the new disk as well.
Next I though of pointing grub to a new root will be easy, but .. I can do it manually in /boot/grub/grub.cfg but grub-mkconfig overwrites its to the old UUID.
And I am scared whether it will happen over the reboot, and reboot will fail. And it is a remote machine, with no easy physical access.
I would have preferred to be certain that grub-mkconfig would generate configuration with new UUID |
|
Back to top |
|
 |
keekkenen n00b

Joined: 05 Oct 2024 Posts: 67
|
Posted: Fri May 09, 2025 10:36 pm Post subject: Re: Where does GRUB2 take root UUID from ? |
|
|
dmpogo wrote: | Basically, the subject. grub-mkconfig generates grub.cfg with particular root UUID - where does it take it from ? |
Maybe it uses blkid command. _________________ 7950x3d / x670e MSI Tomagawk / Sapphire RX 7800XT 16Gb / G.Skill 64Gb 5600 / A-Data Legend 960 2Tb (x2), A-Data SX8200PNP 256Gb |
|
Back to top |
|
 |
dmpogo Advocate

Joined: 02 Sep 2004 Posts: 3511 Location: Canada
|
Posted: Fri May 09, 2025 10:53 pm Post subject: Re: Where does GRUB2 take root UUID from ? |
|
|
keekkenen wrote: | dmpogo wrote: | Basically, the subject. grub-mkconfig generates grub.cfg with particular root UUID - where does it take it from ? |
Maybe it uses blkid command. |
Yes, to find UUID is easy if you know what partition is / I meant to ask how GRUB decides what partition should be root when it generates grub.cfg
Does it always generate config pointing to the current root ? Then how can I tell it to create config pointing to another partition to be a root at the next boot ? |
|
Back to top |
|
 |
keekkenen n00b

Joined: 05 Oct 2024 Posts: 67
|
Posted: Fri May 09, 2025 11:09 pm Post subject: Re: Where does GRUB2 take root UUID from ? |
|
|
dmpogo wrote: | keekkenen wrote: | dmpogo wrote: | Basically, the subject. grub-mkconfig generates grub.cfg with particular root UUID - where does it take it from ? |
Maybe it uses blkid command. |
Yes, to find UUID is easy if you know what partition is / I meant to ask how GRUB decides what partition should be root when it generates grub.cfg
Does it always generate config pointing to the current root ? Then how can I tell it to create config pointing to another partition to be a root at the next boot ? |
find root partition -> GRUB_DEVICE
Code: | grub-probe --target=device /
|
find partition UUID
Code: | grub-probe --device ${GRUB_DEVICE} --target=fs_uuid |
_________________ 7950x3d / x670e MSI Tomagawk / Sapphire RX 7800XT 16Gb / G.Skill 64Gb 5600 / A-Data Legend 960 2Tb (x2), A-Data SX8200PNP 256Gb |
|
Back to top |
|
 |
dmpogo Advocate

Joined: 02 Sep 2004 Posts: 3511 Location: Canada
|
Posted: Fri May 09, 2025 11:15 pm Post subject: Re: Where does GRUB2 take root UUID from ? |
|
|
keekkenen wrote: | dmpogo wrote: | keekkenen wrote: | dmpogo wrote: | Basically, the subject. grub-mkconfig generates grub.cfg with particular root UUID - where does it take it from ? |
Maybe it uses blkid command. |
Yes, to find UUID is easy if you know what partition is / I meant to ask how GRUB decides what partition should be root when it generates grub.cfg
Does it always generate config pointing to the current root ? Then how can I tell it to create config pointing to another partition to be a root at the next boot ? |
find root partition -> GRUB_DEVICE
Code: | grub-probe --target=device /
|
find partition UUID
Code: | grub-probe --device ${GRUB_DEVICE} --target=fs_uuid |
|
Right, so if that is what is used internally to generate config, it means that always uses the current root ? Now, the questions is how to overwrite it .... or whether if I do it manually, something jumps in, and reverts the change |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1671 Location: Richmond Hill, Canada
|
Posted: Fri May 09, 2025 11:27 pm Post subject: |
|
|
You can consider use chroot. if you setup fstab correctly in chroot env you should be able to get grub-mkconfig in chroot generate correct /boot/grub/grub.cfg.
mount your new disk to /chroot, copy old rootfs to /chroot, exclude pseudo file systems (i.e. sys, proc, dev, run, etc...). Modify /chroot/etc/fstab to use right UUID for the new disk (or LABEL), chroot in to /chroot and run grub-mkconfig (no argument yet) to see if generated output match your expectation. if match then run grub-mkconfig -o /boot/grub/grub.cfg to save it.
This is rough idea, if it did not work, post your command sequence and what grub-mkconfig generated, so we can work from there. |
|
Back to top |
|
 |
keekkenen n00b

Joined: 05 Oct 2024 Posts: 67
|
Posted: Fri May 09, 2025 11:36 pm Post subject: Re: Where does GRUB2 take root UUID from ? |
|
|
dmpogo wrote: | Right, so if that is what is used internally to generate config, it means that always uses the current root ? |
I really don't know, maybe grub-probe analyse current mounted points. _________________ 7950x3d / x670e MSI Tomagawk / Sapphire RX 7800XT 16Gb / G.Skill 64Gb 5600 / A-Data Legend 960 2Tb (x2), A-Data SX8200PNP 256Gb |
|
Back to top |
|
 |
dmpogo Advocate

Joined: 02 Sep 2004 Posts: 3511 Location: Canada
|
Posted: Fri May 09, 2025 11:37 pm Post subject: |
|
|
pingtoo wrote: | You can consider use chroot. if you setup fstab correctly in chroot env you should be able to get grub-mkconfig in chroot generate correct /boot/grub/grub.cfg.
mount your new disk to /chroot, copy old rootfs to /chroot, exclude pseudo file systems (i.e. sys, proc, dev, run, etc...). Modify /chroot/etc/fstab to use right UUID for the new disk (or LABEL), chroot in to /chroot and run grub-mkconfig (no argument yet) to see if generated output match your expectation. if match then run grub-mkconfig -o /boot/grub/grub.cfg to save it.
This is rough idea, if it did not work, post your command sequence and what grub-mkconfig generated, so we can work from there. |
under chroot, grub-mkconfig fails with
Code: |
grub-mkconfig -o test
/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).
|
where /dev is of course not mounted. But it confirmed that it actually uses grub-probe to determine the root Which I could have seen by just looking into grub-mkconfig shell  |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1671 Location: Richmond Hill, Canada
|
Posted: Sat May 10, 2025 1:01 am Post subject: |
|
|
So did you mount your new disk to /chroot and bind mount /sys, /proc, /dev in to /chroot/{sys,proc,dev}? |
|
Back to top |
|
 |
dmpogo Advocate

Joined: 02 Sep 2004 Posts: 3511 Location: Canada
|
Posted: Sat May 10, 2025 2:51 am Post subject: |
|
|
pingtoo wrote: | So did you mount your new disk to /chroot and bind mount /sys, /proc, /dev in to /chroot/{sys,proc,dev}? |
I obviously did not do the second step
Ok, we /dev and /proc mounted, grub-mkconfig generates the config file with new root, identical to what manual change did (some section about memtest is slightly different, but OK).
So the original question where grub decides on root is solved. Now I just need to take a breath and convince myself that everything is set to boot into new root.
Not as trivial. because that machine is Ubuntu, and all this root play is to convert it to Gentoo eventually  |
|
Back to top |
|
 |
|
|
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
|
|