Skip to contentSkip to conversation

Mandatory install device check for PowerPC

PATCH Superseded Avnish Chouhan 3 participants 7 messages Oct 13, 2025 – Jan 27

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Mandatory install device check for PowerPC

This patch adds a check on install_device while installing grub for PowerPC. If install_device is not mentioned in grub2-install and machine is detected as PowerPC, the error will be thrown and it will terminates the grub2-install operation. Running grub2-install on PowerPC without the install_device may result in bootlist corruption. When no install device is specified, it attempts to load images from the filesystem, which leads to nvram bootlist corruption. The idea is to fail the operation and avoid creating the invalid boot entry.

---
 util/grub-install.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
util/grub-install.c +13 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the PowerMac. We need to check
+	   * whether the install_device has been mentioned while installing. If no device has been
+	   * mentioned, we need to exit and mark it as an error as the install_device is required for
+	   * PowerPC installation. An installation with no device mentioned may lead to corruptions.
+	   */
+          if (!install_device)
+            grub_util_error ("%s", _("install device isn't specified required for PowerPC"));
+       }
+#endif /* __powerpc__ */
     }
 
   size_t ndev = 0;
Signature · 7 lines
2.47.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 7 lines · Avnish Chouhan

This patch adds a check on install_device while installing grub for PowerPC. If install_device is not mentioned in grub2-install and machine is detected as PowerPC, the error will be thrown and it will terminates the grub2-install operation. Running grub2-install on PowerPC without the install_device may result in bootlist corruption. When no install device is specified, it attempts to load images from the filesystem, which leads to nvram bootlist corruption. The idea is to fail the operation and avoid creating the invalid boot entry.

Hello,

there is the part
if (install_device)
is_prep = 1;

The check added by this patch now assumes PReP.

For consistency this should be set unconditionally now.

Quoted 13 lines
---
 util/grub-install.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
util/grub-install.c +0 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}

util/grub-install.c main (int argc, char *argv[]) · line 1301

Quoted 10 lines
util/grub-install.c +10 -0
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the PowerMac. We need to check
+	   * whether the install_device has been mentioned while installing. If no device has been
+	   * mentioned, we need to exit and mark it as an error as the install_device is required for
+	   * PowerPC installation. An installation with no device mentioned may lead to corruptions.
+	   */
+          if (!install_device)

Then instead of nesting inside else you could change the condition to

if (is_prep && !install_device)

That clarifies what it is checking for, and will cover the cases when there is a partition that is checked for macppc content but none is found.

Thanks

Michal

util/grub-install.c main (int argc, char *argv[]) · line 1302

Quoted 1 line
util/grub-install.c +1 -0
+            grub_util_error ("%s", _("install device isn't specified required for PowerPC"));

I think this can be worded better.

Something like "No install device specified and no PowerPC Mac partition found."

Thanks

Michal

Quoted 8 lines
util/grub-install.c +2 -0
+       }
+#endif /* __powerpc__ */
     }
 
   size_t ndev = 0;
Signature · 1 line
2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 9 lines · Michal Suchánek
Quoted 7 lines · Avnish Chouhan

This patch adds a check on install_device while installing grub for PowerPC. If install_device is not mentioned in grub2-install and machine is detected as PowerPC, the error will be thrown and it will terminates the grub2-install operation. Running grub2-install on PowerPC without the install_device may result in bootlist corruption. When no install device is specified, it attempts to load images from the filesystem, which leads to nvram bootlist corruption. The idea is to fail the operation and avoid creating the invalid boot entry.

Hi Michal,
Hope you're doing wonderful!
Thank you so much for your response!

Surely the changes can be done the way you mentioned. But in my honest opinion, keeping this check in "else" make the code looks lot more understandable (if we see the complete if else condition). Keeping this in as added "else" part clearly stats that this check is only specific to PowerPC. And it has no impact on PowerMac. Thank you!

Regards,
Avnish Chouhan

Quoted 52 lines

Hello,

there is the part
if (install_device)
is_prep = 1;

The check added by this patch now assumes PReP.

For consistency this should be set unconditionally now.

Quoted 25 lines
---
 util/grub-install.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
util/grub-install.c +5 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the 

PowerMac. We need to check

util/grub-install.c +1 -0
+	   * whether the install_device has been mentioned while installing. 

If no device has been

util/grub-install.c +1 -0
+	   * mentioned, we need to exit and mark it as an error as the 

install_device is required for

util/grub-install.c +1 -0
+	   * PowerPC installation. An installation with no device mentioned 

may lead to corruptions.

util/grub-install.c main (int argc, char *argv[]) · line 1301

Quoted 2 lines
util/grub-install.c +2 -0
+	   */
+          if (!install_device)

Then instead of nesting inside else you could change the condition to

if (is_prep && !install_device)

That clarifies what it is checking for, and will cover the cases when there is a partition that is checked for macppc content but none is found.

Thanks

Michal

Quoted 2 lines

+ grub_util_error ("%s", _("install device isn't specified
required for PowerPC"));

Quoted 16 lines

I think this can be worded better.

Something like "No install device specified and no PowerPC Mac partition found."

Thanks

Michal

Quoted 8 lines
util/grub-install.c +2 -1
+       }
+#endif /* __powerpc__ */
     }
 
   size_t ndev = 0;
--

2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw
Quoted 22 lines · Avnish Chouhan
Quoted 16 lines · Michal Suchánek
Quoted 6 lines · Avnish Chouhan

This patch adds a check on install_device while installing grub for PowerPC.
If install_device is not mentioned in grub2-install and machine is detected
as PowerPC, the error will be thrown and it will terminates the grub2-install

Quoted 8 lines

operation. Running grub2-install on PowerPC without the install_device may
result in bootlist corruption. When no install device is specified, it attempts
to load images from the filesystem, which leads to nvram bootlist corruption.
The idea is to fail the operation and avoid creating the invalid boot entry.

Hi Michal,
Hope you're doing wonderful!
Thank you so much for your response!

Quoted 6 lines

Surely the changes can be done the way you mentioned. But in my honest opinion, keeping this check in "else" make the code looks lot more understandable (if we see the complete if else condition). Keeping this in as added "else" part clearly stats that this check is only specific to PowerPC. And it has no impact on PowerMac.
Thank you!

As has been pointed out in the other subthread this is in fact confusing.

The nesting in an else clause makes this code implicitly non-mac, while reducing the nesting and explicitly checking is_prep makes it clearly non-mac.

Thanks

Michal

Quoted 73 lines

Regards,
Avnish Chouhan

Quoted 69 lines

Hello,

there is the part
if (install_device)
is_prep = 1;

The check added by this patch now assumes PReP.

For consistency this should be set unconditionally now.

Quoted 25 lines
---
 util/grub-install.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
util/grub-install.c +5 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the

PowerMac. We need to check

util/grub-install.c +1 -0
+	   * whether the install_device has been mentioned while

installing. If no device has been

util/grub-install.c +1 -0
+	   * mentioned, we need to exit and mark it as an error as the

install_device is required for

util/grub-install.c +1 -0
+	   * PowerPC installation. An installation with no device

mentioned may lead to corruptions.

util/grub-install.c main (int argc, char *argv[]) · line 1301

Quoted 2 lines
util/grub-install.c +2 -0
+	   */
+          if (!install_device)

Then instead of nesting inside else you could change the condition to

if (is_prep && !install_device)

That clarifies what it is checking for, and will cover the cases when there is a partition that is checked for macppc content but none is found.

Thanks

Michal

Quoted 2 lines

+ grub_util_error ("%s", _("install device isn't
specified required for PowerPC"));

I think this can be worded better.

Something like "No install device specified and no PowerPC Mac partition found."

Thanks

Michal

Quoted 8 lines
util/grub-install.c +2 -1
+       }
+#endif /* __powerpc__ */
     }
 
   size_t ndev = 0;
--

2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw
In reply to Avnish Chouhan

Hello Avnish,

util/grub-install.c main (int argc, char *argv[]) · line 1296

Quoted 13 lines · Avnish Chouhan
util/grub-install.c +5 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the PowerMac. We need to check

I have not looked at the patch context here, so I'm just asking: Where are you checking that the target machine is not a PowerMac where installation isn't performed on a device but into a directory?

Should there be a check whether --macppc-directory is set?

Also, minor nitpick: It should be just "As the machine has been detected as PowerPC and not a PowerMac".

util/grub-install.c main (int argc, char *argv[]) · line 1307

Quoted 11 lines
util/grub-install.c +8 -0
+	   * whether the install_device has been mentioned while installing. If no device has been
+	   * mentioned, we need to exit and mark it as an error as the install_device is required for
+	   * PowerPC installation. An installation with no device mentioned may lead to corruptions.
+	   */
+          if (!install_device)
+            grub_util_error ("%s", _("install device isn't specified required for PowerPC"));
+       }
+#endif /* __powerpc__ */
     }
 
   size_t ndev = 0;

Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#5 lore raw
Quoted 20 lines · John Paul Adrian Glaubitz

Hello Avnish,

util/grub-install.c main (int argc, char *argv[]) · line 1296

Quoted 13 lines · Avnish Chouhan
util/grub-install.c +5 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the PowerMac. We need to check

I have not looked at the patch context here, so I'm just asking: Where are you checking that the target machine is not a PowerMac where installation isn't performed on a device but into a directory?

Quoted 1 line

Should there be a check whether --macppc-directory is set?

It's in the else branch of that check. It could be written clearer, though.

Thanks

Michal

Quoted 12 lines

Also, minor nitpick: It should be just "As the machine has been detected as PowerPC and not a PowerMac".

Quoted 10 lines
util/grub-install.c +8 -0
+	   * whether the install_device has been mentioned while installing. If no device has been
+	   * mentioned, we need to exit and mark it as an error as the install_device is required for
+	   * PowerPC installation. An installation with no device mentioned may lead to corruptions.
+	   */
+          if (!install_device)
+            grub_util_error ("%s", _("install device isn't specified required for PowerPC"));
+       }
+#endif /* __powerpc__ */
     }
 
Quoted 9 lines

util/grub-install.c main (int argc, char *argv[]) · line 1307

Quoted 1 line
util/grub-install.c +0 -0
   size_t ndev = 0;

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw
In reply to John Paul Adrian Glaubitz
Quoted 23 lines · John Paul Adrian Glaubitz

Hello Avnish,

Quoted 13 lines · Avnish Chouhan
util/grub-install.c +5 -0
index 0602465..f7389b3 100644
@@ -1289,6 +1289,19 @@ main (int argc, char *argv[])
 	      is_prep = 0;
 	    }
 	}
+#if defined(__powerpc__)
+     else
+       {
+         /*
+	   * As the machine has been detected as PowerPC and not the 
Quoted 1 line

PowerMac. We need to check

I have not looked at the patch context here, so I'm just asking: Where are you checking that the
target machine is not a PowerMac where installation isn't performed on a device but into a directory?

Quoted 1 line

Should there be a check whether --macppc-directory is set?

Hi Adrian,

The code block just above this "if (macppcdir)......" checks whether the machine is a "PowerMac" or not a "PowerMac". We have just added the else part of "if (macppcdir)" !

Thank you!

Regards,
Avnish Chouhan

Quoted 18 lines

Also, minor nitpick: It should be just "As the machine has been detected as PowerPC and not a PowerMac".

Quoted 14 lines
util/grub-install.c +1 -0
+	   * whether the install_device has been mentioned while installing. 

If no device has been

util/grub-install.c +1 -0
+	   * mentioned, we need to exit and mark it as an error as the 

install_device is required for

util/grub-install.c +1 -0
+	   * PowerPC installation. An installation with no device mentioned 

may lead to corruptions.

util/grub-install.c +3 -0
+	   */
+          if (!install_device)
+            grub_util_error ("%s", _("install device isn't specified 

required for PowerPC"));

util/grub-install.c +2 -0
+       }
+#endif /* __powerpc__ */
     }
Quoted 3 lines
Quoted 1 line
   size_t ndev = 0;

Adrian

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel