grub: update search parameter
PATCH 1/1 grub: update search parameter
From: Xiangyu Chen <[email protected]>
Grub would report an error message in boot stage as below:
"error: no such device: ((hd0,gpt1)/EFI/BOOT)/EFI/BOOT/grub.cfg"
Consequently, the root variable is not set, and the intended protection against cross-device configuration loading (the purpose of the original 2014 commit) is lost.
The most robust fix is to use the --hint parameter. This separates the search target from the device hint, avoiding fragile string concatenation and supporting both prefixed and non-prefixed $cmdpath formats.
--- meta/recipes-bsp/grub/files/cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-bsp/grub/files/cfg +1 -1
@@ -1,2 +1,2 @@ -search.file ($cmdpath)/EFI/BOOT/grub.cfg root +search --file --set=root --hint-efi=$cmdpath /EFI/BOOT/grub.cfg set prefix=($root)/EFI/BOOT
Signature · 1 line
2.39.4
Quoted 26 lines · Xiangyu Chen via lists.openembedded.org
From: Xiangyu Chen <[email protected]>
Grub would report an error message in boot stage as below:
"error: no such device: ((hd0,gpt1)/EFI/BOOT)/EFI/BOOT/grub.cfg"Consequently, the root variable is not set, and the intended protection against cross-device configuration loading (the purpose of the original 2014 commit) is lost.
The most robust fix is to use the --hint parameter. This separates the search target from the device hint, avoiding fragile string concatenation and supporting both prefixed and non-prefixed $cmdpath formats.
Fixes 5ce73b6055ac ("grub: add cmdpath to grub configuration file")Signed-off-by Xiangyu Chen <[email protected]>--- meta/recipes-bsp/grub/files/cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)meta/recipes-bsp/grub/files/cfg +0
-0
meta/recipes-bsp/grub/files/cfg line 1
Quoted 2 lines
meta/recipes-bsp/grub/files/cfg +1
-1@@ -1,2 +1,2 @@ -search.file ($cmdpath)/EFI/BOOT/grub.cfg root +search --file --set=root --hint-efi=$cmdpath /EFI/BOOT/grub.cfg
I'm not sure that this can work for all use cases. The grub documentatation for hints says "First try the device HINT" (i.e. it's explicitly a device), whereas the documentation for cmdpath says that it is "an absolute directory name".
Best regards,
Signature · 1 line
Paul Barker
Hi Paul,
Quoted 4 lines · Paul Barker
I'm not sure that this can work for all use cases. The grub documentatation for hints says "First try the device HINT" (i.e. it's explicitly a device), whereas the documentation for cmdpath says that it is "an absolute directory name".
While the documentation defines $cmdpath as a directory and hints as devices, grub’s internal implementation of grub_disk_open (grub-core/kern/disk.c [1]) is designed to handle this exact "device+path" format.
When a hint like (hd0,gpt1)/EFI/BOOT/ is passed, grub_disk_open calls find_part_sep to locate the partition/path delimiter. It then uses grub_memcpy to extract only the device part (e.g., (hd0) into the raw buffer for the disk driver.
The remaining string (gpt1)/EFI/BOOT/) is passed to grub_partition_probe, which identifies the partition and gracefully ignores the trailing directory path.
The current syntax ($cmdpath) results in double parentheses ((hd0...)) if the variable is already populated. In grub_disk_open, this extracts a malformed device name ((hd0 which no driver can open, triggering a hard no such device error.
Ref:
[1] https://elixir.bootlin.com/grub/grub-2.14/source/grub-core/kern/disk.c#L192
Br,
Xiangyu
Hi Richard,
Since the behavior was found in OE scarthgap branch, could you please help to cherry-pick this
commit: 42b530581f72 ("grub: update search parameter") to whinlatter and scarthgap branch?
Thanks.
Br,
Xiangyu
Quoted 30 lines · Xiangyu Chen
Hi Paul,
Quoted 4 lines · Paul Barker
I'm not sure that this can work for all use cases. The grub documentatation for hints says "First try the device HINT" (i.e. it's explicitly a device), whereas the documentation for cmdpath says that it is "an absolute directory name".
While the documentation defines $cmdpath as a directory and hints as devices, grub’s internal implementation of
grub_disk_open(grub-core/kern/disk.c[1]) is designed to handle this exact "device+path" format.When a hint like (hd0,gpt1)/EFI/BOOT/ is passed,
grub_disk_opencallsfind_part_septo locate the partition/path delimiter. It then usesgrub_memcpyto extract only the device part (e.g., (hd0) into the raw buffer for the disk driver.The remaining string (gpt1)/EFI/BOOT/) is passed to
grub_partition_probe, which identifies the partition and gracefully ignores the trailing directory path.The current syntax ($cmdpath) results in double parentheses ((hd0...)) if the variable is already populated. In
grub_disk_open, this extracts a malformed device name ((hd0 which no driver can open, triggering a hard no such device error.Ref:
[1] https://elixir.bootlin.com/grub/grub-2.14/source/grub-core/kern/disk.c#L192
Br,
Xiangyu
Quoted 8 lines · Xiangyu Chen via lists.openembedded.org
Hi Richard,
Since the behavior was found in OE scarthgap branch, could you please help to cherry-pick this
commit:
42b530581f72("grub: update search parameter") to whinlatter and scarthgap branch?
Hello,
For whinlatter, that will be too late (the last build has already left for QA).
For scarthgap, I would need to look into it (change does not look trivial). Can you send a rebased patch targeting scarthgap?
Thanks!
Quoted 48 lines
Thanks.
Br,
Xiangyu
Quoted 38 lines · Xiangyu Chen
Hi Paul,
Quoted 4 lines · Paul Barker
I'm not sure that this can work for all use cases. The grub documentatation for hints says "First try the device HINT" (i.e. it's explicitly a device), whereas the documentation for cmdpath says that it is "an absolute directory name".
While the documentation defines $cmdpath as a directory and hints as devices, grub’s internal implementation of
grub_disk_open(grub-core/kern/disk.c[1]) is designed to handle this exact "device+path" format.When a hint like (hd0,gpt1)/EFI/BOOT/ is passed,
grub_disk_opencallsfind_part_septo locate the partition/path delimiter.
It then usesgrub_memcpyto extract only the device part (e.g., (hd0) into the raw buffer for the disk driver.The remaining string (gpt1)/EFI/BOOT/) is passed to
grub_partition_probe, which identifies the partition and gracefully ignores the trailing directory path.The current syntax ($cmdpath) results in double parentheses ((hd0...)) if the variable is already populated.
Ingrub_disk_open, this extracts a malformed device name ((hd0 which no driver can open, triggering a hard no such device error.Ref:
[1]
https://elixir.bootlin.com/grub/grub-2.14/source/grub-core/kern/disk.c#L192Br,
Xiangyu
Signature · 2 lines
Yoann Congal Smile ECS
Quoted 14 lines · Yoann Congal via lists.openembedded.org
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 8 lines · Xiangyu Chen via lists.openembedded.org
Hi Richard,
Since the behavior was found in OE scarthgap branch, could you please help to cherry-pick this
commit:
42b530581f72("grub: update search parameter") to whinlatter and scarthgap branch?Hello,
Quoted 7 lines
For whinlatter, that will be too late (the last build has already left for QA).
For scarthgap, I would need to look into it (change does not look trivial). Can you send a rebased patch targeting scarthgap?
Thanks!
Thanks for your info, a rebased patch will be sent later.
Br,
Xiangyu
Quoted 62 lines
Quoted 48 lines
Thanks.
Br,
Xiangyu
Quoted 38 lines · Xiangyu Chen
Hi Paul,
Quoted 4 lines · Paul Barker
I'm not sure that this can work for all use cases. The grub documentatation for hints says "First try the device HINT" (i.e. it's explicitly a device), whereas the documentation for cmdpath says that it is "an absolute directory name".
While the documentation defines $cmdpath as a directory and hints as devices, grub’s internal implementation of
grub_disk_open(grub-core/kern/disk.c[1]) is designed to handle this exact "device+path" format.When a hint like (hd0,gpt1)/EFI/BOOT/ is passed,
grub_disk_opencallsfind_part_septo locate the partition/path delimiter.
It then usesgrub_memcpyto extract only the device part (e.g., (hd0) into the raw buffer for the disk driver.The remaining string (gpt1)/EFI/BOOT/) is passed to
grub_partition_probe, which identifies the partition and gracefully ignores the trailing directory path.The current syntax ($cmdpath) results in double parentheses ((hd0...)) if the variable is already populated.
Ingrub_disk_open, this extracts a malformed device name ((hd0 which no driver can open, triggering a hard no such device error.Ref:
[1]
https://elixir.bootlin.com/grub/grub-2.14/source/grub-core/kern/disk.c#L192Br,
Xiangyu
--
Yoann Congal
Smile ECS-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#235740): https://lists.openembedded.org/g/openembedded-core/message/235740
Mute This Topic: https://lists.openembedded.org/mt/118009422/7175143
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 19 lines · Xiangyu Chen
Quoted 17 lines · Yoann Congal via lists.openembedded.org
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 8 lines · Xiangyu Chen via lists.openembedded.org
Hi Richard,
Since the behavior was found in OE scarthgap branch, could you please help to cherry-pick this
commit:
42b530581f72("grub: update search parameter") to whinlatter and scarthgap branch?Hello,
For whinlatter, that will be too late (the last build has already left for QA).
Quoted 6 lines
Quoted 4 lines
For scarthgap, I would need to look into it (change does not look trivial). Can you send a rebased patch targeting scarthgap?
Thanks!
Thanks for your info, a rebased patch will be sent later.
Received, thanks!
I will consider it for the next review cycle.
Quoted 68 lines
Br,
Xiangyu
Quoted 62 lines
Quoted 48 lines
Thanks.
Br,
Xiangyu
Quoted 38 lines · Xiangyu Chen
Hi Paul,
Quoted 4 lines · Paul Barker
I'm not sure that this can work for all use cases. The grub documentatation for hints says "First try the device HINT" (i.e. it's explicitly a device), whereas the documentation for cmdpath says that it is "an absolute directory name".
While the documentation defines $cmdpath as a directory and hints as devices, grub’s internal implementation of
grub_disk_open(grub-core/kern/disk.c[1]) is designed to handle this exact "device+path" format.When a hint like (hd0,gpt1)/EFI/BOOT/ is passed,
grub_disk_opencallsfind_part_septo locate the partition/path delimiter.
It then usesgrub_memcpyto extract only the device part (e.g., (hd0) into the raw buffer for the disk driver.The remaining string (gpt1)/EFI/BOOT/) is passed to
grub_partition_probe, which identifies the partition and gracefully ignores the trailing directory path.The current syntax ($cmdpath) results in double parentheses ((hd0...)) if the variable is already populated.
Ingrub_disk_open, this extracts a malformed device name ((hd0 which no driver can open, triggering a hard no such device error.Ref:
[1]
https://elixir.bootlin.com/grub/grub-2.14/source/grub-core/kern/disk.c#L192Br,
Xiangyu
--
Yoann Congal
Smile ECS-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#235740): https://lists.openembedded.org/g/openembedded-core/message/235740
Mute This Topic: https://lists.openembedded.org/mt/118009422/7175143
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
Yoann Congal Smile ECS