Add a command to display an example in GRUB

zhaozj2021-02-16  49

Add a command to display an example in GRUB

LU_YI_MING (AT) sina.com 2004.5.30

Recently, it is more time to use GRUB. I feel that there is too little help information of the command line. When using it, I can't open the detailed document while using the operating system. It is very inconvenient, so I find some source code, increase it. A command "EXAMPLE [1 | 2 | 3]", display the command line code example of starting Linux, FreeBSD, Windows, respectively.

My operating environment: Redhat Linux 8.0, GRUB 0.92

step:

1. Go to http://www.gnu.org/software/grub/grub.en.html to download the source code.

2. Modify Stage2 / Builtins.c, add the following code before the last struct builtin * builtin_table [] =:

/ * eXample * / static intexample_func (char * arg, int flags) {char * example_info_1 = "" "" boot linux / n "" --------------------- --------------------------------------- / n "" 1. set grub's root Device to the Same Drive As GNU / Linux's. probably / n "" The Command `Find / Boot / Vmlinuz ',' root (hd0, 5) or Similar can / n" "Help You./N" "2. Load the Kernel: / n "" GRUB> kernel / vmlinuz root = / dev / hda1 / n "" if you need to specify some kernel parameters, just append them to / n "" the command. for example, to set `VGA 'To `ext ', do this: / n" "GRUB> kernel / vmlinuz root = / dev / hda1 vga = ext / n" "See the documentation in the linux source tree for completion / n" "Information on The Available Options./ n "" 3. if you use an initrd, execute the command `initrd 'after` kernel': / n "" GRUB> INITRD / INITRD / N "" 4. Finally, Run the command `boot './ n" " ---------------------------------------- / N " Boot my Linux 2.4.18-14 / n "" root (hd0, 10) / n "" kernel /boot/vmlinuz-2.4 .18-14 ROOT = label = / hdd = IDE-SCSI / N "" Initrd /Boot/initrd-2.4.18-14.img/n "" boot ";

Char * eXample_info_2 = "" "" Boot FreeBSD / N "" ------------------------------------- ------------------------- / N "" GRUB CAN LOAD THE KERNEL DIRECTLY, EIGER IN EIF OR A.out Format. But / N "" this is not recommended, since FreeBSD's bootstrap interface sometimes / n "" changes heavily, so GRUB can not guarantee to pass kernel parameters / n "" correctly./n "" Thus, we'd recommend loading the very flexible loader `/ Boot / loader '/ n "" INSTEAD. See excample: / n "" GRUB> root (hd0, a) / n "" GRUB> KERNEL / BOOT / LOADER / N "" GRUB> BOOT ";

Char * example_info_3 = "" "Load Another Boot Loader to Boot Unsupported Operating Systems / N" "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------ / N "" if you want to boot an unsupported Operating System (EG Windows 95) , / n "" Hain-load / n "" Loader is Embedded in the / "Boot Sector /" of the partition on which the / n "" Operating System is Installed. / n "" 1. set grub's root device to the partition by the command / n "" `rootnoverified '/ n" "GRUB> rootnoverify (hd0, 0) / n" "2. set the /" Active / "Flag in THE PARTITION Using THE COMMAND / N "" `makeactive '(1) / n" "GRUB> makeactive / n" "3. Load the boot loader with the commit` chainloader' / n "" GRUB> CHAINLOADER 1 / N " "` 1 'indeicates "4. Run the command` boot'. "; Switch (arg [0]) {CASE '1' : Grub_printf (example_info_1); Break; Case '2': GRUB_PRINTF (Examp Le_info_2); Break; Case '3': Grub_Printf (Example_info_3); Break; Default: Grub_Printf ("Example [1 | 2 | 3] / N / N" "Exmple 1: Boot Linux / N" "Exmple 2: boot freebsd / n "" exmple 3: boot windows ");

Return 0;}

Static struct builtin builtin_example = {"example", example_func, builtin_cmdline | Builtin_HELP_LIST, "Example [1 | 2 | 3]", "Show Examles, Page 1 | 2 | 3"}; 3. Continue to modify Stage2 / Builtins.c, Increase the definition of EXAMPLE in the last struct builtin * builtin_table [] =

Struct Builtin * Builtin_Table [] = {& Builtin_BlockList,

...

& Builtin_Embed,

& Builtin_example,

& Builtin_Fallback,

...

& Builtin_vbeprobe, 0};

4. Compile, install, do not have to be said in detail

./configure make make install

5. Test it, enter GRUB in the command line, then press the Tab button to see if there is an example, if any, the code is written successfully, you can continue to enter EXAMPLE 1 to see if it is an example of launching Linux.

6. Mount the modified GRUB to the main guidance record of the hard disk to truly work.

Grub-install / dev / hda

7. Restart your computer, you can find that the original RedHat beautiful GRUB color interface is not a black interface. This is a little loss. Press C to enter the GRUB command line interface ...

转载请注明原文地址:https://www.9cbs.com/read-24691.html

New Post(0)