Add --reuse-cmdline
Subsystems (2)
PATCH 1/1 Add --reuse-cmdline
This patch adds an option "--reuse-cmdline" for people that are lazy in typing --append="$(cat /proc/cmdline)". The advantage of "--reuse-cmdline" is also that it strips off BOOT_IMAGE (since it may not be correct any more) from lilo and other boot loaders, and, more important, the crashkernel option in case a panic kernel is loaded.
If you like the option I can also add it for really all architectures. Tested only with x86-bzImage both the kexec and kdump case.
--- kexec/arch/i386/kexec-bzImage.c | 12 +++- kexec/arch/i386/kexec-elf-x86.c | 16 ++++-- kexec/arch/i386/kexec-multiboot-x86.c | 12 +++- kexec/arch/x86_64/kexec-elf-x86_64.c | 16 ++++-- kexec/kexec.8 | 18 +++++++ kexec/kexec.c | 85 +++++++++++++++++++++++++++++----- kexec/kexec.h | 1 7 files changed, 132 insertions(+), 28 deletions(-)
kexec/arch/i386/kexec-bzImage.c +9 -3
@@ -89,6 +89,7 @@ void bzImage_usage(void)" --real-mode Use the kernels real mode entry point.\n" " --command-line=STRING Set the kernel command line to STRING.\n" " --append=STRING Set the kernel command line to STRING.\n" +" --reuse-cmdline Use kernel command line from running system.\n" " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n" " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n" );
@@ -335,14 +336,16 @@ int bzImage_load(int argc, char **argv,int debug, real_mode_entry;int opt;int result; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_REAL_MODE (OPT_ARCH_MAX+2) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_REAL_MODE (OPT_ARCH_MAX+3)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"debug" ,0 ,0 ,OPT_DEBUG }, {"command-line" ,1 ,0 ,OPT_APPEND }, {"append" ,1 ,0 ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,0 ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,0 ,OPT_RAMDISK }, {"ramdisk" ,1 ,0 ,OPT_RAMDISK }, {"real-mode" ,0 ,0 ,OPT_REAL_MODE },
@@ -374,6 +377,9 @@ int bzImage_load(int argc, char **argv,case OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
kexec/arch/i386/kexec-elf-x86.c +11 -5
@@ -73,6 +73,7 @@ void elf_x86_usage(void) {printf (" --command-line=STRING Set the kernel command line to STRING\n" " --append=STRING Set the kernel command line to STRING\n" +" --reuse-cmdline Use kernel command line from running system.\n" " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n" " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n" " --args-linux Pass linux kernel style options\n"
@@ -97,16 +98,18 @@ int elf_x86_load(int argc, char **argv,#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+2) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+3) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+4) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) +#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) +#define OPT_ARGS_NONE (OPT_ARCH_MAX+5)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,NULL ,OPT_APPEND }, {"append" ,1 ,NULL ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,NULL ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,NULL ,OPT_RAMDISK }, {"ramdisk" ,1 ,NULL ,OPT_RAMDISK }, {"args-elf" ,0 ,NULL ,OPT_ARGS_ELF },
@@ -138,6 +141,9 @@ int elf_x86_load(int argc, char **argv,case OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
kexec/arch/i386/kexec-multiboot-x86.c +9 -3
@@ -129,6 +129,7 @@ void multiboot_x86_usage(void)/* Multiboot-specific options */ {printf (" --command-line=STRING Set the kernel command line to STRING.\n" ); +printf (" --reuse-cmdline Use kernel command line from running system.\n" );printf (" --module=\"MOD arg1 arg2...\" Load module MOD with command-line \"arg1...\"\n" );printf (" (can be used multiple times).\n" ); }
@@ -155,13 +156,15 @@ int multiboot_x86_load(int argc, char **int i;int opt;int modules, mod_command_line_space; -#define OPT_CL (OPT_ARCH_MAX+0) -#define OPT_MOD (OPT_ARCH_MAX+1) -#define OPT_VGA (OPT_ARCH_MAX+2) +#define OPT_CL (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_MOD (OPT_ARCH_MAX+2) +#define OPT_VGA (OPT_ARCH_MAX+3)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,0 ,OPT_CL }, {"append" ,1 ,0 ,OPT_CL }, + {"reuse-cmdline" ,1 ,0 ,OPT_REUSE_CMDLINE }, {"module" ,1 ,0 ,OPT_MOD }, {0 ,0 ,0 ,0 }, };
@@ -194,6 +197,9 @@ int multiboot_x86_load(int argc, char **case OPT_CL : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_MOD : modules++; mod_command_line_space +=strlen (optarg) +1 ;
kexec/arch/x86_64/kexec-elf-x86_64.c +11 -5
@@ -73,6 +73,7 @@ void elf_x86_64_usage(void) {printf (" --command-line=STRING Set the kernel command line to STRING\n" " --append=STRING Set the kernel command line to STRING\n" +" --reuse-cmdline Use kernel command line from running system.\n" " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n" " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n" " --args-linux Pass linux kernel style options\n"
@@ -96,16 +97,18 @@ int elf_x86_64_load(int argc, char **arg#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+2) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+3) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+4) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) +#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) +#define OPT_ARGS_NONE (OPT_ARCH_MAX+5)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,NULL ,OPT_APPEND }, {"append" ,1 ,NULL ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,NULL ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,NULL ,OPT_RAMDISK }, {"ramdisk" ,1 ,NULL ,OPT_RAMDISK }, {"args-elf" ,0 ,NULL ,OPT_ARGS_ELF },
@@ -138,6 +141,9 @@ int elf_x86_64_load(int argc, char **argcase OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
kexec/kexec.8 +18 -0
@@ -186,6 +186,15 @@ to the kernel command line. Set the kernel command line to .IR string . .TP +.BI \-\-reuse-cmdline +Use the command line from the running system. When a panic kernel is loaded, it +strips the +.I +crashkernel +parameter automatically. The +.I BOOT_IMAGE +parameter is also stripped. +.TP .BI \-\-initrd= file Use .I file
@@ -204,6 +213,15 @@ as the kernel's initial ramdisk. Set the kernel command line to .IR string . .TP +.BI \-\-reuse-cmdline +Use the command line from the running system. When a panic kernel is loaded, it +strips the +.I +crashkernel +parameter automatically. The +.I BOOT_IMAGE +parameter is also stripped. +.TP .BI \-\-module= "mod arg1 arg2 ..." Load module .I mod
kexec/kexec.c +73 -12
118 lines not on this page · raw message
kexec/kexec.h +1 -0
@@ -220,6 +220,7 @@ int arch_process_options(int argc, charint arch_compat_trampoline (struct kexec_info *info);void arch_update_purgatory (struct kexec_info *info);int is_crashkernel_mem_reserved (void ); +char *get_command_line (void ); int kexec_iomem_for_each_line(char *match, int (*callback)(void *data,
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 9 lines · Bernhard Walle
This patch adds an option "--reuse-cmdline" for people that are lazy in typing --append="$(cat
/proc/cmdline)". The advantage of "--reuse-cmdline" is also that it strips offBOOT_IMAGE(since it may not be correct any more) from lilo and other boot loaders, and, more important, the crashkernel option in case a panic kernel is loaded.If you like the option I can also add it for really all architectures. Tested only with x86-bzImage both the kexec and kdump case.
I for one like the idea of the patch.
-ben
Quoted 349 lines
Signed-off-by Bernhard Walle <[email protected]>--- kexec/arch/i386/kexec-bzImage.c | 12 +++- kexec/arch/i386/kexec-elf-x86.c | 16 ++++-- kexec/arch/i386/kexec-multiboot-x86.c | 12 +++- kexec/arch/x86_64/kexec-elf-x86_64.c | 16 ++++-- kexec/kexec.8 | 18 +++++++ kexec/kexec.c | 85 +++++++++++++++++++++++++++++----- kexec/kexec.h | 1 7 files changed, 132 insertions(+), 28 deletions(-)kexec/arch/i386/kexec-bzImage.c +9
-3@@ -89,6 +89,7 @@ void bzImage_usage(void)" --real-mode Use the kernels real mode entry point.\n" " --command-line=STRING Set the kernel command line to STRING.\n" " --append=STRING Set the kernel command line to STRING.\n" +" --reuse-cmdline Use kernel command line from running system.\n" " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n" " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n" );@@ -335,14 +336,16 @@ int bzImage_load(int argc, char **argv,int debug, real_mode_entry;int opt;int result; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_REAL_MODE (OPT_ARCH_MAX+2) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_REAL_MODE (OPT_ARCH_MAX+3)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"debug" ,0 ,0 ,OPT_DEBUG }, {"command-line" ,1 ,0 ,OPT_APPEND }, {"append" ,1 ,0 ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,0 ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,0 ,OPT_RAMDISK }, {"ramdisk" ,1 ,0 ,OPT_RAMDISK }, {"real-mode" ,0 ,0 ,OPT_REAL_MODE },@@ -374,6 +377,9 @@ int bzImage_load(int argc, char **argv,case OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;kexec/arch/i386/kexec-elf-x86.c +11
-5@@ -73,6 +73,7 @@ void elf_x86_usage(void) {printf (" --command-line=STRING Set the kernel command line to STRING\n" " --append=STRING Set the kernel command line to STRING\n" +" --reuse-cmdline Use kernel command line from running system.\n" " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n" " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n" " --args-linux Pass linux kernel style options\n"@@ -97,16 +98,18 @@ int elf_x86_load(int argc, char **argv,#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+2) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+3) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+4) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) +#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) +#define OPT_ARGS_NONE (OPT_ARCH_MAX+5)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,NULL ,OPT_APPEND }, {"append" ,1 ,NULL ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,NULL ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,NULL ,OPT_RAMDISK }, {"ramdisk" ,1 ,NULL ,OPT_RAMDISK }, {"args-elf" ,0 ,NULL ,OPT_ARGS_ELF },@@ -138,6 +141,9 @@ int elf_x86_load(int argc, char **argv,case OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;kexec/arch/i386/kexec-multiboot-x86.c +9
-3@@ -129,6 +129,7 @@ void multiboot_x86_usage(void)/* Multiboot-specific options */ {printf (" --command-line=STRING Set the kernel command line to STRING.\n" ); +printf (" --reuse-cmdline Use kernel command line from running system.\n" );printf (" --module=\"MOD arg1 arg2...\" Load module MOD with command-line \"arg1...\"\n" );printf (" (can be used multiple times).\n" ); }@@ -155,13 +156,15 @@ int multiboot_x86_load(int argc, char **int i;int opt;int modules, mod_command_line_space; -#define OPT_CL (OPT_ARCH_MAX+0) -#define OPT_MOD (OPT_ARCH_MAX+1) -#define OPT_VGA (OPT_ARCH_MAX+2) +#define OPT_CL (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_MOD (OPT_ARCH_MAX+2) +#define OPT_VGA (OPT_ARCH_MAX+3)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,0 ,OPT_CL }, {"append" ,1 ,0 ,OPT_CL }, + {"reuse-cmdline" ,1 ,0 ,OPT_REUSE_CMDLINE }, {"module" ,1 ,0 ,OPT_MOD }, {0 ,0 ,0 ,0 }, };@@ -194,6 +197,9 @@ int multiboot_x86_load(int argc, char **case OPT_CL : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_MOD : modules++; mod_command_line_space +=strlen (optarg) +1 ;kexec/arch/x86_64/kexec-elf-x86_64.c +11
-5@@ -73,6 +73,7 @@ void elf_x86_64_usage(void) {printf (" --command-line=STRING Set the kernel command line to STRING\n" " --append=STRING Set the kernel command line to STRING\n" +" --reuse-cmdline Use kernel command line from running system.\n" " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n" " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n" " --args-linux Pass linux kernel style options\n"@@ -96,16 +97,18 @@ int elf_x86_64_load(int argc, char **arg#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+2) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+3) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+4) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) +#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) +#define OPT_ARGS_NONE (OPT_ARCH_MAX+5)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,NULL ,OPT_APPEND }, {"append" ,1 ,NULL ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,NULL ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,NULL ,OPT_RAMDISK }, {"ramdisk" ,1 ,NULL ,OPT_RAMDISK }, {"args-elf" ,0 ,NULL ,OPT_ARGS_ELF },@@ -138,6 +141,9 @@ int elf_x86_64_load(int argc, char **argcase OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;kexec/kexec.8 +18
-0@@ -186,6 +186,15 @@ to the kernel command line. Set the kernel command line to .IR string . .TP +.BI \-\-reuse-cmdline +Use the command line from the running system. When a panic kernel is loaded, it +strips the +.I +crashkernel +parameter automatically. The +.I BOOT_IMAGE +parameter is also stripped. +.TP .BI \-\-initrd= file Use .I file@@ -204,6 +213,15 @@ as the kernel's initial ramdisk. Set the kernel command line to .IR string . .TP +.BI \-\-reuse-cmdline +Use the command line from the running system. When a panic kernel is loaded, it +strips the +.I +crashkernel +parameter automatically. The +.I BOOT_IMAGE +parameter is also stripped. +.TP .BI \-\-module= "mod arg1 arg2 ..." Load module .I modkexec/kexec.c +73
-12@@ -31,6 +31,7 @@#include <unistd.h> #include <fcntl.h> #include <getopt.h> +#include <ctype.h> #include "config.h" @@ -46,6 +47,7 @@unsigned long long mem_min =0 ;unsigned long long mem_max =ULONG_MAX ; +unsigned long kexec_flags =0 ;void die (char *fmt, ...) {@@ -792,26 +794,86 @@ static int kexec_loaded(void)return ret; } +/* +* Remove parameter from a kernel command line. Helper function by get_command_line(). +*/ +static void remove_parameter (char *line,const char *param_name) +{ +char *start, *end; + + start =strstr (line, param_name); + +/* parameter not found */ +if (!start) +return ; + +/* +* check if that's really the start of a parameter and not in +* the middle of the word +*/ +if (start != line && !isspace (*(start-1 ))) +return ; + + end =strstr (start," " ); +if (!end) + *start =0 ; +else { +memmove (start, end+1 ,strlen (end)); + *(end +strlen (end)) =0 ; + } +} + +/* +* Returns the contents of the current command line to be used with +* --reuse-cmdline option. The function gets called from architecture specific +* code. If we load a panic kernel, that function will strip the +* "crashkernel=" option because it does not make sense that the crashkernel +* reserves memory for a crashkernel (well, it would not boot since the +* amount is exactly the same as the crashkernel has overall memory). Also, +* remove the BOOT_IMAGE from lilo (and others) since that doesn't make +* sense here any more. The kernel could be different even if we reuse the +* commandline. +* +* The function returns dynamically allocated memory. +*/ +char *get_command_line (void ) +{ +FILE *fp; +size_t len; +char *line =NULL ; + + fp =fopen ("/proc/cmdline" ,"r" ); +if (!fp) +die ("Could not read /proc/cmdline." ); +getline (&line, &len, fp); +fclose (fp); + +if (line) { +/* strip newline */ + *(line +strlen (line) -1 ) =0 ; + +remove_parameter (line,"crashkernel" ); +if (kexec_flags &KEXEC_ON_CRASH ) +remove_parameter (line,"BOOT_IMAGE" ); + }else + line =strdup ("" ); + +return line; +} +/* check we retained the initrd */ void check_reuse_initrd (void ) { -FILE * fp; -char * line =NULL ; -size_t len =0 ; -ssize_t read; +char *line =get_command_line (); - fp =fopen ("/proc/cmdline" ,"r" ); -if (fp ==NULL ) -die ("unable to open /proc/cmdline\n" ); - read =getline (&line, &len, fp);if (strstr (line,"retain_initrd" ) ==NULL )die ("unrecoverable error: current boot didn't " "retain the initrd for reuse.\n" ); -if (line) -free (line); -fclose (fp); + +free (line); } +int main (int argc,char *argv[]) {int do_load =1 ;@@ -821,7 +883,6 @@ int main(int argc, char *argv[])int do_ifdown =0 ;int do_unload =0 ;int do_reuse_initrd =0 ; -unsigned long kexec_flags =0 ;char *type =0 ;char *endptr;int opt;kexec/kexec.h +1
-0@@ -220,6 +220,7 @@ int arch_process_options(int argc, charint arch_compat_trampoline (struct kexec_info *info);void arch_update_purgatory (struct kexec_info *info);int is_crashkernel_mem_reserved (void ); +char *get_command_line (void ); int kexec_iomem_for_each_line(char *match, int (*callback)(void *data,
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 1 line · In message <[email protected]> you wrote:
This patch adds an option "--reuse-cmdline" for people that are lazy in typin
g
Quoted 1 line
--append="$(cat
/proc/cmdline)". The advantage of "--reuse-cmdline" is also t
hat
Quoted 5 lines
it strips off
BOOT_IMAGE(since it may not be correct any more) from lilo and other boot loaders, and, more important, the crashkernel option in case a panic kernel is loaded.If you like the option I can also add it for really all architectures. Tested
only
Quoted 1 line
with x86-bzImage both the kexec and kdump case.
For ppc64, the default is to reuse the command line. We should probably merge functionality.
Either way, this should probably be a generic option, not x86 specific.
Mikey
Quoted 11 lines
Signed-off-by Bernhard Walle <[email protected]>--- kexec/arch/i386/kexec-bzImage.c | 12 +++- kexec/arch/i386/kexec-elf-x86.c | 16 ++++-- kexec/arch/i386/kexec-multiboot-x86.c | 12 +++- kexec/arch/x86_64/kexec-elf-x86_64.c | 16 ++++-- kexec/kexec.8 | 18 +++++++ kexec/kexec.c | 85 +++++++++++++++++++++++++++++--
---
kexec/arch/i386/kexec-bzImage.c void bzImage_usage(void) · line 89
Quoted 7 lines
kexec/kexec.h | 1 7 files changed, 132 insertions(+), 28 deletions(-)kexec/arch/i386/kexec-bzImage.c +0
-0@@ -89,6 +89,7 @@ void bzImage_usage(void) " --real-mode Use the kernels real mode entry poin
t.\n"
kexec/arch/i386/kexec-bzImage.c void bzImage_usage(void) · line 90
Quoted 1 line
kexec/arch/i386/kexec-bzImage.c +0
-0" --command-line=STRING Set the kernel command line to STRIN
G.\n"
kexec/arch/i386/kexec-bzImage.c void bzImage_usage(void) · line 91
Quoted 1 line
kexec/arch/i386/kexec-bzImage.c +0
-0" --append=STRING Set the kernel command line to STRIN
G.\n"
kexec/arch/i386/kexec-bzImage.c void bzImage_usage(void) · line 92
Quoted 1 line
kexec/arch/i386/kexec-bzImage.c +1
-0+ " --reuse-cmdline Use kernel command line from running
system.\n"
kexec/arch/i386/kexec-bzImage.c void bzImage_usage(void) · line 93
Quoted 1 line
kexec/arch/i386/kexec-bzImage.c +0
-0" --initrd=FILE Use FILE as the kernel's initial ram
disk.\n"
kexec/arch/i386/kexec-bzImage.c void bzImage_usage(void) · line 94
Quoted 1 line
kexec/arch/i386/kexec-bzImage.c +0
-0" --ramdisk=FILE Use FILE as the kernel's initial ram
disk.\n"
kexec/arch/i386/kexec-bzImage.c int bzImage_load(int argc, char **argv, · line 342
Quoted 12 lines
kexec/arch/i386/kexec-bzImage.c +4
-3);@@ -335,14 +336,16 @@ int bzImage_load(int argc, char **argv,int debug, real_mode_entry;int opt;int result; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_REAL_MODE (OPT_ARCH_MAX+2) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_REAL_MODE (OPT_ARCH_MAX+3)
What space updates?
Quoted 22 lines
kexec/arch/i386/kexec-bzImage.c +4
-0static const struct option options[] = { KEXEC_ARCH_OPTIONS {"debug" ,0 ,0 ,OPT_DEBUG }, {"command-line" ,1 ,0 ,OPT_APPEND }, {"append" ,1 ,0 ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,0 ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,0 ,OPT_RAMDISK }, {"ramdisk" ,1 ,0 ,OPT_RAMDISK }, {"real-mode" ,0 ,0 ,OPT_REAL_MODE },@@ -374,6 +377,9 @@ int bzImage_load(int argc, char **argv,case OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
kexec/arch/i386/kexec-elf-x86.c void elf_x86_usage(void) · line 74
Quoted 2 lines
kexec/arch/i386/kexec-elf-x86.c +0
-0@@ -73,6 +73,7 @@ void elf_x86_usage(void) { printf( " --command-line=STRING Set the kernel command line to STRIN
G\n"
kexec/arch/i386/kexec-elf-x86.c void elf_x86_usage(void) · line 75
Quoted 1 line
kexec/arch/i386/kexec-elf-x86.c +0
-0" --append=STRING Set the kernel command line to STRIN
G\n"
kexec/arch/i386/kexec-elf-x86.c void elf_x86_usage(void) · line 76
Quoted 1 line
kexec/arch/i386/kexec-elf-x86.c +1
-0+ " --reuse-cmdline Use kernel command line from running
system.\n"
kexec/arch/i386/kexec-elf-x86.c void elf_x86_usage(void) · line 77
Quoted 1 line
kexec/arch/i386/kexec-elf-x86.c +0
-0" --initrd=FILE Use FILE as the kernel's initial ram
disk.\n"
kexec/arch/i386/kexec-elf-x86.c void elf_x86_usage(void) · line 78
Quoted 1 line
kexec/arch/i386/kexec-elf-x86.c +0
-0" --ramdisk=FILE Use FILE as the kernel's initial ram
disk.\n"
Quoted 38 lines
kexec/arch/i386/kexec-elf-x86.c +10
-5" --args-linux Pass linux kernel style options\n" @@ -97,16 +98,18 @@ int elf_x86_load(int argc, char **argv,#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+2) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+3) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+4) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) +#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) +#define OPT_ARGS_NONE (OPT_ARCH_MAX+5)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,NULL ,OPT_APPEND }, {"append" ,1 ,NULL ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,NULL ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,NULL ,OPT_RAMDISK }, {"ramdisk" ,1 ,NULL ,OPT_RAMDISK }, {"args-elf" ,0 ,NULL ,OPT_ARGS_ELF },@@ -138,6 +141,9 @@ int elf_x86_load(int argc, char **argv,case OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
kexec/arch/i386/kexec-multiboot-x86.c void multiboot_x86_usage(void) · line 131
Quoted 3 lines
kexec/arch/i386/kexec-multiboot-x86.c +0
-0@@ -129,6 +129,7 @@ void multiboot_x86_usage(void)/* Multiboot-specific options */ { printf(" --command-line=STRING Set the kernel command line to
STRING.\n");
kexec/arch/i386/kexec-multiboot-x86.c void multiboot_x86_usage(void) · line 132
Quoted 1 line
kexec/arch/i386/kexec-multiboot-x86.c +1
-0+ printf(" --reuse-cmdline Use kernel command line from r
unning system.\n");
kexec/arch/i386/kexec-multiboot-x86.c void multiboot_x86_usage(void) · line 133
Quoted 1 line
kexec/arch/i386/kexec-multiboot-x86.c +0
-0printf(" --module=\"MOD arg1 arg2...\" Load module MOD with command
-line \"arg1...\"\n");
kexec/arch/i386/kexec-multiboot-x86.c void multiboot_x86_usage(void) · line 134
Quoted 1 line
kexec/arch/i386/kexec-multiboot-x86.c +0
-0printf(" (can be used multiple times).\
n");
Quoted 33 lines
kexec/arch/i386/kexec-multiboot-x86.c +8
-3}@@ -155,13 +156,15 @@ int multiboot_x86_load(int argc, char **int i;int opt;int modules, mod_command_line_space; -#define OPT_CL (OPT_ARCH_MAX+0) -#define OPT_MOD (OPT_ARCH_MAX+1) -#define OPT_VGA (OPT_ARCH_MAX+2) +#define OPT_CL (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_MOD (OPT_ARCH_MAX+2) +#define OPT_VGA (OPT_ARCH_MAX+3)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,0 ,OPT_CL }, {"append" ,1 ,0 ,OPT_CL }, + {"reuse-cmdline" ,1 ,0 ,OPT_REUSE_CMDLINE }, {"module" ,1 ,0 ,OPT_MOD }, {0 ,0 ,0 ,0 }, };@@ -194,6 +197,9 @@ int multiboot_x86_load(int argc, char **case OPT_CL : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_MOD : modules++; mod_command_line_space +=strlen (optarg) +1 ;
kexec/arch/x86_64/kexec-elf-x86_64.c void elf_x86_64_usage(void) · line 74
Quoted 2 lines
kexec/arch/x86_64/kexec-elf-x86_64.c +0
-0@@ -73,6 +73,7 @@ void elf_x86_64_usage(void) { printf( " --command-line=STRING Set the kernel command line to STRIN
G\n"
kexec/arch/x86_64/kexec-elf-x86_64.c void elf_x86_64_usage(void) · line 75
Quoted 1 line
kexec/arch/x86_64/kexec-elf-x86_64.c +0
-0" --append=STRING Set the kernel command line to STRIN
G\n"
kexec/arch/x86_64/kexec-elf-x86_64.c void elf_x86_64_usage(void) · line 76
Quoted 1 line
kexec/arch/x86_64/kexec-elf-x86_64.c +1
-0+ " --reuse-cmdline Use kernel command line from running
system.\n"
kexec/arch/x86_64/kexec-elf-x86_64.c void elf_x86_64_usage(void) · line 77
Quoted 1 line
kexec/arch/x86_64/kexec-elf-x86_64.c +0
-0" --initrd=FILE Use FILE as the kernel's initial ram
disk.\n"
kexec/arch/x86_64/kexec-elf-x86_64.c void elf_x86_64_usage(void) · line 78
Quoted 1 line
kexec/arch/x86_64/kexec-elf-x86_64.c +0
-0" --ramdisk=FILE Use FILE as the kernel's initial ram
disk.\n"
Quoted 38 lines
kexec/arch/x86_64/kexec-elf-x86_64.c +10
-5" --args-linux Pass linux kernel style options\n" @@ -96,16 +97,18 @@ int elf_x86_64_load(int argc, char **arg#define ARG_STYLE_LINUX 1#define ARG_STYLE_NONE 2int opt; -#define OPT_APPEND (OPT_ARCH_MAX+0) -#define OPT_RAMDISK (OPT_ARCH_MAX+1) -#define OPT_ARGS_ELF (OPT_ARCH_MAX+2) -#define OPT_ARGS_LINUX (OPT_ARCH_MAX+3) -#define OPT_ARGS_NONE (OPT_ARCH_MAX+4) +#define OPT_APPEND (OPT_ARCH_MAX+0) +#define OPT_REUSE_CMDLINE (OPT_ARCH_MAX+1) +#define OPT_RAMDISK (OPT_ARCH_MAX+2) +#define OPT_ARGS_ELF (OPT_ARCH_MAX+3) +#define OPT_ARGS_LINUX (OPT_ARCH_MAX+4) +#define OPT_ARGS_NONE (OPT_ARCH_MAX+5)static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line" ,1 ,NULL ,OPT_APPEND }, {"append" ,1 ,NULL ,OPT_APPEND }, + {"reuse-cmdline" ,1 ,NULL ,OPT_REUSE_CMDLINE }, {"initrd" ,1 ,NULL ,OPT_RAMDISK }, {"ramdisk" ,1 ,NULL ,OPT_RAMDISK }, {"args-elf" ,0 ,NULL ,OPT_ARGS_ELF },@@ -138,6 +141,9 @@ int elf_x86_64_load(int argc, char **argcase OPT_APPEND : command_line = optarg;break ; +case OPT_REUSE_CMDLINE : + command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
kexec/kexec.8 to the kernel command line. · line 190
Quoted 5 lines
kexec/kexec.8 +2
-0@@ -186,6 +186,15 @@ to the kernel command line. Set the kernel command line to .IR string . .TP +.BI \-\-reuse-cmdline +Use the command line from the running system. When a panic kernel is loaded,
it
Quoted 11 lines
kexec/kexec.8 +7
-0+strips the +.I +crashkernel +parameter automatically. The +.I BOOT_IMAGE +parameter is also stripped. +.TP .BI \-\-initrd= file Use .I file
kexec/kexec.8 as the kernel's initial ramdisk. · line 217
Quoted 5 lines
kexec/kexec.8 +2
-0@@ -204,6 +213,15 @@ as the kernel's initial ramdisk. Set the kernel command line to .IR string . .TP +.BI \-\-reuse-cmdline +Use the command line from the running system. When a panic kernel is loaded,
it
Quoted 29 lines
kexec/kexec.8 +7
-0+strips the +.I +crashkernel +parameter automatically. The +.I BOOT_IMAGE +parameter is also stripped. +.TP .BI \-\-module= "mod arg1 arg2 ..." Load module .I modkexec/kexec.c +2
-0@@ -31,6 +31,7 @@#include <unistd.h> #include <fcntl.h> #include <getopt.h> +#include <ctype.h> #include "config.h" @@ -46,6 +47,7 @@unsigned long long mem_min =0 ;unsigned long long mem_max =ULONG_MAX ; +unsigned long kexec_flags =0 ;void die (char *fmt, ...) {
kexec/kexec.c static int kexec_loaded(void) · line 798
Quoted 5 lines
kexec/kexec.c +2
-0@@ -792,26 +794,86 @@ static int kexec_loaded(void)return ret; } +/* +* Remove parameter from a kernel command line. Helper function by get_comma
nd_line().
Quoted 20 lines
kexec/kexec.c +20
-0+*/ +static void remove_parameter (char *line,const char *param_name) +{ +char *start, *end; + + start =strstr (line, param_name); + +/* parameter not found */ +if (!start) +return ; + +/* +* check if that's really the start of a parameter and not in +* the middle of the word +*/ +if (start != line && !isspace (*(start-1 ))) +return ; + + end =strstr (start," " ); +if (!end)
kexec/kexec.c static int kexec_loaded(void)
Quoted 10 lines
kexec/kexec.c +10
-0+ *start =0 ; + else { +memmove (start, end+1 ,strlen (end)); + *(end +strlen (end)) =0 ; + } +} + +/* +* Returns the contents of the current command line to be used with +* --reuse-cmdline option. The function gets called from architecture speci
fic
Quoted 81 lines
kexec/kexec.c +39
-12+* code. If we load a panic kernel, that function will strip the +* "crashkernel=" option because it does not make sense that the crashkernel +* reserves memory for a crashkernel (well, it would not boot since the +* amount is exactly the same as the crashkernel has overall memory). Also, +* remove the BOOT_IMAGE from lilo (and others) since that doesn't make +* sense here any more. The kernel could be different even if we reuse the +* commandline. +* +* The function returns dynamically allocated memory. +*/ +char *get_command_line (void ) +{ +FILE *fp; +size_t len; +char *line =NULL ; + + fp =fopen ("/proc/cmdline" ,"r" ); +if (!fp) +die ("Could not read /proc/cmdline." ); +getline (&line, &len, fp); +fclose (fp); + +if (line) { +/* strip newline */ + *(line +strlen (line) -1 ) =0 ; + +remove_parameter (line,"crashkernel" ); +if (kexec_flags &KEXEC_ON_CRASH ) +remove_parameter (line,"BOOT_IMAGE" ); + }else + line =strdup ("" ); + +return line; +} +/* check we retained the initrd */ void check_reuse_initrd (void ) { -FILE * fp; -char * line =NULL ; -size_t len =0 ; -ssize_t read; +char *line =get_command_line (); - fp =fopen ("/proc/cmdline" ,"r" ); -if (fp ==NULL ) -die ("unable to open /proc/cmdline\n" ); - read =getline (&line, &len, fp);if (strstr (line,"retain_initrd" ) ==NULL )die ("unrecoverable error: current boot didn't " "retain the initrd for reuse.\n" ); -if (line) -free (line); -fclose (fp); + +free (line); } +int main (int argc,char *argv[]) {int do_load =1 ;@@ -821,7 +883,6 @@ int main(int argc, char *argv[])int do_ifdown =0 ;int do_unload =0 ;int do_reuse_initrd =0 ; -unsigned long kexec_flags =0 ;char *type =0 ;char *endptr;int opt;kexec/kexec.h +1
-0@@ -220,6 +220,7 @@ int arch_process_options(int argc, charint arch_compat_trampoline (struct kexec_info *info);void arch_update_purgatory (struct kexec_info *info);int is_crashkernel_mem_reserved (void ); +char *get_command_line (void ); int kexec_iomem_for_each_line(char *match, int (*callback)(void *data,
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi,
at first thanks for looking at the patch.
Quoted 10 lines · Michael Neuling
Quoted 1 line · In message <[email protected]> you wrote:
This patch adds an option "--reuse-cmdline" for people that are lazy in typin
g
Quoted 1 line
--append="$(cat
/proc/cmdline)". The advantage of "--reuse-cmdline" is also that
Quoted 4 lines
it strips off
BOOT_IMAGE(since it may not be correct any more) from lilo and other boot loaders, and, more important, the crashkernel option in case a panic kernel is loaded.
Quoted 6 lines
Quoted 1 line
If you like the option I can also add it for really all architectures. Tested
only
Quoted 1 line
with x86-bzImage both the kexec and kdump case.
For ppc64, the default is to reuse the command line. We should probably merge functionality.
Where is that functionality implemented? I couldn't find it. Does the kernel that automatically on PPC64? I know too litte about that architecture.
Quoted 1 line
Either way, this should probably be a generic option, not x86 specific.
Well, I thought first of it. But since the '--append' parameter is not generic, this makes no sense.
Maybe it would make sense to change the command line handling in general to be global and not image specific, but first I need to understand how that works on PPC64 ... (and probably others).
Bernhard
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 26 lines · In message <[email protected]> you wrote:
--Sig_/XVYJV.ZkU.f5R3y3b_UR6.k
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printableHi,
at first thanks for looking at the patch.
Quoted 3 lines · Michael Neuling
=20
Quoted 1 line · In message <[email protected]> you wrote:
This patch adds an option "--reuse-cmdline" for people that are lazy in=
typin
Quoted 2 lines
g
Quoted 1 line
--append=3D"$(cat
/proc/cmdline)". The advantage of "--reuse-cmdline" i=s also t
Quoted 2 lines
hat
Quoted 1 line
it strips off
BOOT_IMAGE(since it may not be correct any more) from li=lo and
Quoted 1 line
Quoted 1 line
other boot loaders, and, more important, the crashkernel option in case=
a
Quoted 3 lines
Quoted 3 lines
panic kernel is loaded.
=20
If you like the option I can also add it for really all architectures. =Tested
Quoted 1 line
only
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
with x86-bzImage both the kexec and kdump case.
=20
For ppc64, the default is to reuse the command line. We should probably merge functionality.Where is that functionality implemented? I couldn't find it. Does the kernel that automatically on PPC64? I know too litte about that architecture.
Sorry, I think I was mistaken. ppc64 only takes the "root=<blah>" from the first kernel, provided it's not specified on the kexec command line for the next kernel.
Anyway, the code is in kexec/arch/ppc64/fs2dt.c (search for "root=")
Quoted 8 lines
Quoted 1 line
Either way, this should probably be a generic option, not x86 specific.
Well, I thought first of it. But since the '--append' parameter is not generic, this makes no sense.
Maybe it would make sense to change the command line handling in general to be global and not image specific, but first I need to understand how that works on PPC64 ... (and probably others).
Yeah, the cmdline should be generically and consistently handled rather than what we have now.
Mikey
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 7 lines · Michael Neuling
In message <[email protected]> you wrote:
Sorry, I think I was mistaken. ppc64 only takes the "root=<blah>" from the first kernel, provided it's not specified on the kexec command line for the next kernel.
Anyway, the code is in
kexec/arch/ppc64/fs2dt.c(search for "root=")
Externally to kexec(8), I copy the console keyword under the same circumstances, e.g., it has not been explicitly set.
Quoted 11 lines
Quoted 8 lines
Quoted 1 line
Either way, this should probably be a generic option, not x86 specific.
Well, I thought first of it. But since the '--append' parameter is not generic, this makes no sense.
Maybe it would make sense to change the command line handling in general to be global and not image specific, but first I need to understand how that works on PPC64 ... (and probably others).
Yeah, the cmdline should be generically and consistently handled rather than what we have now.
The problem is that not all boot options are always usable in the next kernel, in addition to being architecturally specific, it's very situational. Having written that, a generic framework could be usable.
Signature · 7 lines
David N. Lombard, Intel, Irvine, CA I do not speak for Intel Corporation; all comments are strictly my own. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 4 lines · Lombard, David N
The problem is that not all boot options are always usable in the next kernel, in addition to being architecturally specific, it's very situational. Having written that, a generic framework could be usable.
Yes. I think that the framework to read out the command line and filter out options like crashkernel that *never* make sense should be architecture independent. Then architecture specific code could make the rest.
Bernhard
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec