bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Allow appending kernel options directly from the main menu


From: Jeremy Katz
Subject: [PATCH] Allow appending kernel options directly from the main menu
Date: 01 Oct 2002 17:16:11 -0400

The following patch lets users to directly edit the kernel command line
by pressing 'a' at the grub menu.  This makes it significantly easier
for users to do things such as boot in single user mode or pass kernel
options for debugging.

Patch is against current CVS.

Cheers,

Jeremy

Index: ChangeLog
===================================================================
RCS file: /cvsroot/grub/grub/ChangeLog,v
retrieving revision 1.522
diff -u -r1.522 ChangeLog
--- ChangeLog   13 Sep 2002 11:49:56 -0000      1.522
+++ ChangeLog   1 Oct 2002 20:48:57 -0000
@@ -1,3 +1,9 @@
+2002-10-01  Jeremy Katz  <address@hidden>
+
+       From Erik Troan <address@hidden>:
+       * stage2/stage2.c (run_menu): Add support for appending options to
+       kernel lines and booting directly with those changes.
+
 2002-09-13  Yoshinori K. Okuji  <address@hidden>
 
        * stage2/serial.c (fill_input_buf): Take a new argument NOWAIT.
Index: stage2/stage2.c
===================================================================
RCS file: /cvsroot/grub/grub/stage2/stage2.c,v
retrieving revision 1.38
diff -u -r1.38 stage2.c
--- stage2/stage2.c     22 Aug 2002 05:59:55 -0000      1.38
+++ stage2/stage2.c     1 Oct 2002 20:48:58 -0000
@@ -314,7 +314,8 @@
          if (config_entries)
            printf ("\
       Press enter to boot the selected OS, \'e\' to edit the\n\
-      commands before booting, or \'c\' for a command-line.");
+      commands before booting, \'a\' to modify the kernel arguments\n\
+      before booting, or \'c\' for a command-line.");
          else
            printf ("\
       Press \'b\' to boot, \'e\' to edit the selected command in the\n\
@@ -665,6 +666,98 @@
                {
                  enter_cmdline (heap, 0);
                  goto restart;
+               }
+             if (config_entries && c == 'a')
+               {
+                 int new_num_entries = 0, i = 0, j;
+                 int needs_padding, amount;
+                 char *new_heap;
+                 char * entries;
+                 char * entry_copy;
+                 char * append_line;
+                 char * start;
+
+                 entry_copy = new_heap = heap;
+                 cur_entry = get_entry (config_entries, first_entry + entryno,
+                                        1);
+                 
+                 do
+                   {
+                     while ((*(new_heap++) = cur_entry[i++]) != 0);
+                     new_num_entries++;
+                   }
+                 while (config_entries && cur_entry[i]);
+
+                 /* this only needs to be done if config_entries is non-NULL,
+                    but it doesn't hurt to do it always */
+                 *(new_heap++) = 0;
+
+                 new_heap = heap + NEW_HEAPSIZE + 1;
+
+                 entries = entry_copy;
+                 while (*entries) 
+                   {
+                     if ((strstr(entries, "kernel") == entries) &&
+                         isspace(entries[6])) 
+                         break;
+
+                     while (*entries) entries++;
+                     entries++;
+                   }
+
+                 if (!*entries)
+                     goto restart;
+
+                 start = entries + 6;
+
+                 /* skip the white space */
+                 while (*start && isspace(*start)) start++;
+                 /* skip the kernel name */
+                 while (*start && !isspace(*start)) start++;
+
+                 /* skip the white space */
+                 needs_padding = (!*start || !isspace(*start));
+                 while (*start && isspace(*start)) start++;
+
+                 append_line = new_heap;
+                 grub_strcpy(append_line, start);
+
+                 cls();
+                 print_cmdline_message (0);
+
+                 if (get_cmdline(PACKAGE " append> ", 
+                                   append_line, NEW_HEAPSIZE + 1, 
+                                   0, 1))
+                     goto restart;
+
+                 /* have new args; append_line points to the
+                    new args and start points to the old
+                    args */
+
+                 i = grub_strlen(start);
+                 j = grub_strlen(append_line);
+
+                 if (i > (j + needs_padding))
+                     amount = i;
+                 else
+                     amount = j + needs_padding;
+
+                 /* align rest of commands properly */
+                 memmove (start + j + needs_padding, start + i,
+                      ((int) append_line) - ((int) start) - (amount));
+
+                 if (needs_padding)
+                     *start = ' ';
+
+                 /* copy command to correct area */
+                 memmove (start + needs_padding, append_line, j);
+
+                 /* set up this entry to boot */
+                 config_entries = NULL;
+                 cur_entry = entry_copy;
+                 heap = new_heap;
+
+                 break;
                }
 #ifdef GRUB_UTIL
              if (c == 'q')







reply via email to

[Prev in Thread] Current Thread [Next in Thread]