Ubuntu grub2 detailed description in early Ubuntu, using Grub as the system boot program, it is very easy to modify the system boot item, you only need to use gedit to open the System menu setting file (sudogedit/boot/grub/menu. (lst), modify the content in the file,...
Ubuntu grub2 detailed description in early Ubuntu, using Grub as the system boot program, it is very easy to modify the system boot item, you only need to use gedit to open the System menu setting file (sudo gedit/boot/grub/menu. (lst), modify the content in the file, but in Grub 2, you cannot modify the system startup item in this way. Grub 2 features Grub 2 (GRand uniied Bootloader, version 2) is the second version of Grub. Grub 2 has completely rewritten Grub interfaces. based on the PUPA (Detailed introduction) project, Grub 2 is more modular and easier to expand. some improvements of Grub 2 are as follows: it has a graphical interface and supports topic modularization. the compatibility of the exaggerated platform supports script customization. the startup project definition is changed. the partition name is Grub 2. the structure Grub 2 contains the following parts:/boot/grub. cfg file/etc/grub. d/folder/etc/default/grub file. Grub. cfg is similar to/boot/Grub/menu. lst in grub. The format is in menu. lst is similar, but now you are not allowed to modify the startup item by directly modifying the file to the way, because the file is after executing "update-grub" or update-grub2, dynamically generated based on the two commands 2 and 3 mentioned above. that is to say, if you modify this file, the next time these two commands are executed (for example, after kernel update ), if you modify the content, it will overwrite it. The official file www.2cto.com only says/boot/grub. cfg should not be manually modified. This file is automatically generated by running update-grub. To modify the configuration file, you only need to open/boot/grub. cfg file, find the location you want to modify, and find the corresponding/etc/default/grub OR/etc/grub according to the annotation. d/(folder. The grub. cfg file contains two parts: one is the definition of each startup item, and the other is the setting of the startup interface. You can use gedit to open the file and view the content. Since grub. cfg cannot be modified, there is nothing to elaborate on. you can understand how it is written in a little research. Next we will introduce the other two parts of Grub 2. The other two parts of Grub 2 correspond to the two parts in grub. cfg respectively. First,/etc/grub. d. Each startup item is defined in the folder. the file represents one or more startup items. the naming rules are "two digit _ Names ", the preceding two digits determine the position of one or more startup items on the startup interface. the default "00 _" is reserved for "00_header, "10 _ is reserved for the current system kernel, and 20 _ is reserved for third-party programs. in addition to these, you can use them to add your own, such as 05 _, 15 _, the smaller the number, the higher the front. The file here seems to be code. I haven't thoroughly studied it yet. I won't write it myself, but I will change it. After executing the "update-grub" or update-grub2 "command, the files in this folder are used to generate the definition of the startup item in grub. cfg. The last part of Grub 2 is the/etc/default/grub file, which is mainly used to configure the startup interface, such as the default startup item, waiting for the time when the user selects the startup item. The file content is very simple, that is, some key-value pairs. for detailed configurable attributes, refer to the "Grub (/etc/default/grub)" section in the Wiki of grub 2. After you run the "update-grub" or update-grub2 "command, the content of this file is used to generate settings for the startup interface in grub. cfg. Detailed modification method of the/etc/default/grub file sudo gedit/etc/default/grub system after installation is complete, you will find/boot/grub. the cfg file can only be read by the root user. if you want to modify grub directly. cfg file, you must first modify its permissions. Grub. cfg is modified. when the system kernel or grub is upgraded, update-grub and grub are automatically executed. the cfg file will be typed back to its original shape. how can we ensure that the modified configuration file can be retained all the time? Www.2cto.com actually does not need to modify grub. cfg, you only need to write the personalized configuration to grub and/etc/gurb in the/etc/default/directory. the script file in the d directory will create a personalized grub as required no matter whether the kernel is upgraded or the update-grub executed by grub is upgraded. cfg. 1. First, check/etc/default/grub, open the terminal from the application-attachment, and enter sudo gedit/etc/default/grub to see what changes can be made to the opened file: # If you change this file, run 'UPDATE-grub 'afterwards to update #/boot/grub. cfg. GRUB_DEFAULT = 0 --------> set the default startup item in the order of menuentry. For example, to start from the fourth menu item by default, change the number to 3. if it is changed to saved, it is the last startup item by default. GRUB_HIDDEN_TIMEOUT = 0 the default value is 0. when a single system is enabled, the menu is automatically hidden. to cancel the menu, change it to greater than 0 and then sudo update-grub. (Note: in a single system,/etc/grub. d/30_ OS-prober may not reference the variables here. if the menu cannot be displayed here, modify/etc/grub. d/30_os-prober. For more information, see the following changes.) GRUB_HIDDEN_TIMEOUT_QUIET = true
GRUB_TIMEOUT = "3" -----------> set the waiting time for the default startup item. the default value is 10 seconds, modify GRUB_DISTRIBUTOR = 'lsb _ release-I-s 2>/dev/null as needed | echo Debian 'grub _ javasline_linux_default = "quiet splash" -----------> add kernel startup parameters, this is the default GRUB_CMDLINE_LINUX = "noresume" ---------> manually add kernel startup parameters. for example, you can add acpi = off noapic here, and add the text parameter to start and enter the character mode. # Uncomment to disable graphical terminal (grub-pc only) # GRUB_TERMINAL = console ----------> set whether to use the graphic interface. Remove the front # and only use the console terminal, do not use The graphic interface www.2cto.com # the resolution used on graphical terminal # note that you can use only modes which your graphic card supports via VBE # you can see them in real GRUB with The command 'vbeinfo '# GRUB_GFXMODE = 640x480 sets the graphic interface resolution, if the default value is not used, remove # from the front, change the resolution to 800x600 or 1024x768 # Uncomment if you don't want GRUB to pass "root = UUID = xxx" parameter to Linux # GRUB_DISABLE_LINUX_UUID = true ----------> set whether the grub command is used UUID, remove #, use root =/dev/sdax instead of root = UUDI = xxx # Uncomment to disable generation of recovery mode menu entrys # GRUB_DISABLE_LINUX_RECOVERY = "true" -----------> to set whether to create the repair mode menu item/ etc/grub. d. detailed folder modification method
Check/etc/grub again. d folder: 00_header 05_debian_theme 10_linux 20_memtest86 + 30_o-prober 40_custom README. the preceding five scripts correspond to grub. to ensure that the running of update-grub is not damaged and grub can be modified. what if cfg meets your needs? In fact, it is very easy to find statements such as cat <EOF ************************* EOF, the text in the middle of EOF is directly written to grub. the corresponding position in cfg, so you can add the personalized statement here. The 00_header can be modified in two places: cat <EOF www.2cto.com load_envset default =$ {GRUB_DEFAULT} <----- set according to the default variable in/etc/default/grub, you do not need to modify if [/$ {prev_saved_entry}]; thensaved_entry =/$ {prev_saved_entry} save_env saved_entryprev_saved_entry = save_env 1_jpeg <----------- This part is added to, or the system format supports insmod ntfs, insmod fat, and other insmod png <----------- EOF another cat <EOFset timeout =$ {GRUB_TIMEOUT} <------ -Timeout is set based on the timeout variable in/etc/default/grub above. you do not need to change background_image (hd0, 7) here) /boot/images/012.jpg <---------- the absolute path of the background image here (it seems useless to see each other "instance ") EOF05_debian_theme: modify the background color cat <EOF www.2cto.com set menu_color_normal = white/black <-------- set menu_color_highlight = yellow/black <------- the front font color can be customized, otherwise, the background color will block the background image. Note: set menu_color_highlight = black/light-grayEOF10_linux before modification this part is to automatically search the current system, establish the current system boot menu, including the system header, kernel and other information, do not modify, to use a personalized menu name, such as a Chinese menu, you can modify the name here. do not modify the name elsewhere: cat <EOFmenuentry "start $1" {<--------- add personalized text in double quotation marks "and variable $1, or change the variable $1 to a fixed character, such as Ubuntu KarmicEOF if ["x $3" = "xquiet"]; thencat <EOFset quiet = 1EOF20_memtest86 + to add the memory test startup item, where to modify: cat <EOFmenuentry "Memory test (memtest86 +)" {<------ can be changed to a Chinese menu, such as menuentry" Memory test "{, double quotation marks must be English characters linux16 $ MEMTESTPATH} # The second menu item below can be deleted menuentry" Memory test (memtest86 +) "linux16 $ MEMTESTPATH *********} www.2cto.com EOF30_os-prober to find systems that exist in other partitions and create menu items, in turn windows> linux> macos, you do not need to modify it here. Or modify menuentry "$ {LONGNAME} (on $ {DEVICE})" <------- to fix the variable in quotation marks, such as windows xp, vista, or linux, menu items such as Fedora. 40_custom custom startup item, which can be added according to the standard menu format. after update-grub, it will be automatically added to grub. cfg, for example, menuentry "start Veket" {set root = (hd0, 8) linux/veket/vmlinuz root =/dev/ram0 PMEDIA = hdinitrd/veket/initrd.gz} menuentry "start CDLinux" {set root = (hd0, 8) linux/CDlinux/bzImage root =/dev/ram0 vga = 791 CDL_LANG = zh_CN.UTF-8initrd/CDlinux/initrd} menuentry "start Grub4Dos" {set root = (hd0, 8) linux/grub.exe} save the changes, and then sudo update-grubcat/boot/grub. cfg Check whether the configuration file is the same as what you think. Different ??? Modify sudo update-grub www.2cto.com. to modify the default startup item, use the following method: 1. modify/etc/grub. d/, set the order of the items you want to start to a smaller value by default. The advantage is that the modification will not be overwritten by the update-grub command. it seems that there is no power shortage. only when the other program is modified to a value smaller than yours will it be started by default. 2. modify the default startup item in/etc/default/grub and set the GRUB_DEFAULT value in the file. The value is the generated grub. the subscript of each startup item in cfg starting from 0. The advantage of this method is that the modification will not be overwritten by the update-grub command, but the subscript will change after the order of the startup items changes... Step 1: enable the terminal, modify the/etc/default/grub file $ sudo gedit/etc/default/grub cancel # comment symbol before GRUB_GFXMODE = 640 × 480, modify the following number to a proper value, such as 1024x768. This value affects both the grub startup menu and the text resolution in the console. Note: the resolution of the startup menu is the same as that of the startup interface. if the resolution is too high, the startup menu will be ugly. it seems that the resolution modification will not affect the startup speed. Step 2: modify/etc/grub. d/00_header file $ sudo gedit/etc/grub. d/00_header press ctrl + F to search for the keyword "set gfxmode =$ {GRUB_GFXMODE}" (remove double quotation marks), and then add a new line under this line. The content is: "set gfxpayload = keep" (remove double quotation marks) Step 3: update grub $ sudo update-grub. restart and try again, without an accident, you will see that the plymouth Uth startup screen is indeed more beautiful. Add image 1 to the grub2 menu. in etc/grub. d. find the 00_header file in the folder. after opening it, add www.2cto.com insmod png2. in etc/gr under save_env prev_saved_entryfi. Ub. in d/05_debian_theme, set menu_color_normal = white/black set menu_color_highlight = yellow/black (the front font color can be customized, and the background must be set to black; otherwise, the background color will block the background image. See the preceding statement for details) 3. you can determine the default image folder location of the grub system based on the image location, and place an image file with the same name in the same location. The file name in the figure is moreblue-orbit-grub.png. remarks: 1. modify/boot/grub. cfg file method (can be treated as modifying/etc/grub. d/folder and/etc/default/grub file reference) grub. cfg is read-only by default. before modification, set it to sudo chmod + w/boot/grub. setting set default = 0 # The default value is 0 insmod jpg # add jpg support. if you want to use a png or tga file as the background, add insmod png or insmod tga (adding images does not work) insmod ext2 # In addition to the partitions used for startup, you can add set root = (hd0, 7) under the menu in other partition formats) # set root partition search-no-floppy-fs-uuid-set f255285a-5ad4-4eb8-93f5-4f767190d3b3 # set uuid = *** The partition is root, which is the same as the preceding statement. you can delete it. # configure if loadfont/usr/share/grub/unicode for the terminal. pf2; then # set the terminal font, unicode. pf2 supports Chinese display set gfxmode = 640 × 480 www.2cto.com # sets the resolution. the default value is 640 × 480, which can be 800 × 768, ×, we recommend that you set the image size to the same as that set for the insmod gfxterm # insert module gfxterm, which supports Chinese display and 24-bit image insmod vbe # insert into the vbe module, GRUB 2 introduces many modules. to use it, add if terminal_output gfxterm; then true; else # For backward compatibility with versions of terminal here. mod that Don't # understand terminal_outputterminal gfxterm # set the GRUB 2 terminal to gfxterm incluiset timeout = 10background_image (hd0, 7)/boot/images/1.jpg (adding images does not work) # set the background image ### END/etc/grub. d/00_header ###### BEGIN/etc/grub. d/05_debian_theme ### set menu_color_normal = white/blackset menu_color_highlight = cyan/black # The menu color settings under Debian. if the default value is true, you will find that the background is completely blocked by blue, and you need to change blue to black, so that the background will appear ## END/etc/grub. d/05_debian_them E #### 10_linux is the automatically added linux boot item for the current root partition ### BEGIN/etc/grub. d/10_linux #### menu items, which must contain menuentry double quotation marks "and braces {}. Otherwise, the menu menuentry" Ubuntu, linux 2.6.31-9-386 "{insmod ext2 www.2cto.com set root = (hd0, 7) search-no-floppy-fs-uuid-set f255285a-5ad4-4eb8-93f5-4f767190d3b3 # This statement corresponds to set root = (hd0, 7) repeat, can delete linux/boot/vmlinuz-2.6.31-9-386 root = UUID = f255285a-5ad4-4eb8-93f5-4f767190d3b3 ro quite splash # don't like to see a long string, Roo = UUID = *** replace initrd/boot/initrd with root =/dev/sda7. img-2.6.31-9-386 ### END/etc/grub. d/10_linux ###### BEGIN/etc/grub. d/20_memtest86 + ### menuentry "Memory test (memtest86 +)" {linux16/boot/memtest86 +. bin }### END/etc/grub. d/20_memtest86 + #### automatically add system boot items that exist in other partitions ### BEGIN/etc/grub. d/30_os-prober #### windows boot menu menuentry "Windows Vista (loader) (on/dev/sda1)" {insmod ntfs # The windows format is ntfs, or the fat32 format is changed Insmod fatset root = (hd0, 1) search-no-floppy-fs-uuid-set ece067d2e067a196 # deletable # grub2 is more advanced. if you find that windows is started through ntldr, set it to 2000/xp/2003, the drivemap-s (hd0) $ {root} will be added here, which serves as the map of grub. the xp/2003 system of non-first hard disk can be started normally. Chainloader + 1} # Find the linux system on other partitions and automatically add menuentry "Ubuntu karmic (development branch) (9.10) (on/dev/sda3) "{insmod ext2set root = (hd0, 3) search-no-floppy-fs-uuid-set others/boot/vmlinuz-2.6.31-9-generic root =/dev/sda3initrd/boot/initrd. img-2.6.31-9-generic} www.2cto.com # will be automatically added here if macos exists. ### END/etc/grub. d/30_os-prober #### The following are manually added menu items ### BEGIN/etc/grub. d/40_custom ### menuentry "CDLinux" {set root = (hd0, 8) linux/CDlinux/bzImage root =/dev/ram0 vga = 791 CDL_LANG = zh_CN.UTF-8initrd/CDlinux/initrd }## END/etc/grub. d/40_custom #### hard disk number starting from 0 (hd0), primary partition number starting from 1 (hd0, 1), and logical partition starting from 5 (hd0, 5) 2. some commands on the grub2 terminal: when the menu is selected, press C to enter the terminal command line mode, and press E to enter the current menu item editing mode (the same as grub ), press Ctrl + C to exit the editing process, and press Ctrl + X to start the editing process. 1. help to view command usage, display all available command help searchsearch command usage 2. ls to list all current devices. For example, (hd0) (hd0, 1) (hd0, 5) (hd1) (hd1, 1) (hd1, 2 )....... ls-l lists all current devices in detail. The label and uuid of the partition are displayed. Ls/list the files in the current root partition ls (hd1, 1)/List (hd1, 1) the files in the partition 3. searchsearch-f/ntldr lists the partitions that contain the ntldr file in the root directory, and returns the partition code search-l LINUX www.2cto.com. The search label is a LINUX partition. Search-set-f/ntldr: search for the partitions in the root directory that contain the ntldr file and set it to root. Note that if multiple external partitions contain the ntldr file, set is ineffective. 4. the loopbackloopback command can be used to create a playback device, such as loopback lo0 (hd1, 1)/abc. iso can use lo0 devices to access abc. the content in iso, for example, from abc. start loopback lo0 (hd1, 1)/aa. isolinux (lo0)/memdiskinitrd (lo0)/abc. to delete a playback device, use the-d parameter loopback-d lo0 5. set can be used to set the variable value set root = set timeout = when the variable value needs to be called, use $ {AA}, such as set root = (hd1, 1) then $ {root} = (hd1, 1) 6. pager page display. Set pager = 1 when the page is full, press space to continue set pager = 0 cancel page 7. replacing kernel in grub in linuxlinux 3. placing iso on drive C when installing a single linux system or hard disk at www.2cto.com. several processing methods for failing to believe that menu items cannot appear in a single system due to umount/isodevice. 1. after self-check, press the shift key to adjust the menu item. sudo update-grub reconstruction grub. cfg, you will find a new system and rewrite grub. cfg. 3. if the second method cannot be solved, modify grub directly. cfg puts it in ### BEGIN/etc/grub. d/30_oss-prober: if keystatus; thenif keystatus-shift; thenset timeout =-1 elseset timeout = 0 fielseif sleep $ verbose-interruptible 3; thenset timeout = 0fifi delete or modify three places set timeout = <大于0> 4. Dual-disk dual-system Grub Loading solution grub2 boot. img sets the root uuid to search for and load modules in/boot/grub from the first partition. if The linux partition is on the second or third hard disk, the search takes a long time, the menu appears for more than 10 seconds. For dual (multiple) hard disks, it is recommended to install grub on the mbr of the disk where ubuntu is located, and set the/boot partition or/partition as front as possible, and set the hard disk as the boot disk, the startup time is greatly shortened. Five, grub2 several repair methods www.2cto.com 1. solution 1: grub4dos0.4.4 add grub4dos on the windows startup item (if you don't want to talk about it later, see the top post), restart and choose to go to grub, enter the code in the command line (remove/boot from the/boot partition): grub> find-set-root/boot/grub/core. imggrub> kernel/boot/grub/core. imggrub> boot: go to the grub2 menu, and then run the code: sudo grub-install/dev/sd? Method 2: fix the vulnerability after entering Livecd (thanks to billbear) reference: sudo-imount your root partition/mntmount your/boot partition/mnt/boot # if Yes # mount your other partitions, if yes, # re-create the grub-sda mbrgrub-install-root-directory =/mnt/dev/sda2. startup fails due to the change of the root partition uuid, only the fixed code in grub rescue mode can be entered: www.2cto.com grub rescue> setgrub rescue> prefix = (hd ?,?) /Grubgrub rescue> root = hd ?,? Grub rescue> set root = hd ?,? Grub rescue> set prefix = (hd ?,?) /Boot/grubgrub rescue> setgrub rescue> root = hd ?,? Grub rescue> prefix = (hd ?,?) /Boot/grubgrub rescue> insmod/boot/grub/normal. modgrub rescue> normal now you can call up/boot/grub. cfg, change the uuid to grub> insmod/boot/grub/linux under the command line. modgrub> set root = hd ?,? Grub> linux/boot/vmlinuz-*** root =/dev/sd ?? Grub> initrd/boot/initrg. img-**** enter the system hd ?,? Is the partition where the grub file is located, sda? Yes/partition. 3. grub module and configuration file grub. repair Livcd startup when cfg is damaged and cannot be started. Trial reference: sudo-imount your root partition/mnt mount your/boot partition/mnt/boot # if Yes # mount your other partitions, if yes # recreate grub to sda's mbrgrub-install-root-directory =/mnt/dev/sda # recreate grub. cfg www.2cto.com mount-bind/proc/mnt/procmount-bind/dev/mnt/devmount-bind/sys/mnt/syschroot/mnt update-grubumount/mnt/sysumount/mnt/devumount /mnt/proc 6. other supplementary instructions 1. chainloadergrub2 will support chainloader/file Usage. Currently, only grub2 boot. img and grub4dos grldr and grub.exe files are supported. The official version is expected to support ntldr bootmgr peldr and other files. 2. drivemapdrivemap is compatible with grub map and is mainly used for systems that can only be started from (hd0) boot, such as win2000 xp 2003. it can be used like map, such as menuentry "Windows XP" {insmod ntfsdrivemap (hd0) (hd1) drivemap (hd1) (hd0) set root = (hd1, 1) chainloader + 1} actually drivemap has a more convenient usage: menuentry "Windows XP" {insmod ntfs www.2cto.com set root = (hd1, 1) drivemap-s (hd0) $ {root} chainloader + 1} 3. grub2 boot floppy disk img Image startup, for example,. img image, first decompress memdisk from memdisk.gz. usage: linux (hd1, 1) /memdisk # if the image file exceeds 2.88M, add c = * h = * s = * initrd (hd1, 1)/. imgboot
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service