When the boot loader/kernel is not configured to reserve memory for
crashkernel and the user tries to load the kdump kernel using kexec -p,
tools does not give a meaningful error message.

The following patch checks for the "crashkernel=" parameter in the
/proc/cmdline and if "crashkernel=" is present then only calls the
corresponding kexec system call to load the kdump kernel image.
Otherwise it gives the error message and exits.

Any comment, suggestion?

Regards,
Mohan

Note: Following patch is generated over Horm's kexec-tools-testing git
tree.



Signed-off-by: Mohan Kumar M <[EMAIL PROTECTED]>


---

 kexec/kexec.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

95edf80f062aa4b30a7bffa4ce6f861e69e4d9bb
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 0206fa6..4a28337 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -712,6 +712,30 @@ static int kexec_loaded(void)
        return ret;
 }
 
+/* Return true if crashkernel= parameter is passed to the kernel */
+static int check_for_crashkernel(void)
+{
+       int ret;
+       FILE *fp;
+       char buf[80];
+
+       fp = fopen("/proc/cmdline", "r");
+       if (fp == NULL)
+               return -1;
+
+       ret = 0;
+
+       if (fgets(buf, sizeof(buf), fp) == NULL)
+               return 0;
+
+       if (strstr(buf, "crashkernel="))
+               ret = 1;
+       else
+               ret = 0;
+       fclose(fp);
+       return ret;
+}
+
 int main(int argc, char *argv[])
 {
        int do_load = 1;
@@ -823,7 +847,14 @@ int main(int argc, char *argv[])
                result = k_unload(kexec_flags);
        }
        if (do_load && (result == 0)) {
-               result = my_load(type, fileind, argc, argv, kexec_flags);
+               /* Check for crashkernel parameter  before trying to load
+                  the kdump kernel */
+               if (check_for_crashkernel())
+                       result = my_load(type, fileind, argc, argv, 
kexec_flags);
+               else {
+                       printf("crashkernel parameter is not present in the 
kernel commandline\n");
+                       die("Update your boot loader with crashkernel 
parameter\n");
+               }
        }
        /* Don't shutdown unless there is something to reboot to! */
        if ((result == 0) && (do_shutdown || do_exec) && !kexec_loaded()) {
-- 
1.0.GIT
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot

Reply via email to