How to modify Ubuntu grub to modify a startup entry

Source: Internet
Author: User
Tags reserved uuid

Recently installed Xen to the server, need to modify the Grub boot entry, just take this opportunity to learn.


Basic Files


In Ubuntu, you cannot modify the boot configuration by modifying the Menu.lst file, grub2 mainly contains
1./boot/grub/grub.cfg Documents
2./etc/grub.d/folder

3./etc/default/grub Documents


Grub.cfg is the configuration option, similar to Menu.lst, which has the same format as Menu.lst. However, we cannot modify the configuration by directly modifying this file.

The Grub.cfg file contains two parts, one part is the definition of each startup item, and the second part is the setting of the startup interface.


feature describes the various startup items defined in the/etc/grub.d/folder, where the folder represents one or more startup items, the naming conventions used are "two number _ names", and the preceding two numbers determine the position of this or multiple startup items in the startup interface, and the default " 00_ "is the 00_header", "10_" is reserved for the current system kernel, "20_" is reserved for third-party programs, in addition to these you can use, add their own, such as "05_" the smaller the more the more the more forward.

/etc/default/gurb file, the file is mainly the start interface configuration, such as the default startup items, waiting for the user's choice of time.

Well, with the above introduction, you should have some understanding of Grub 2, smart you should think of how to modify the default startup items, there are the following three ways:

• Direct modifications to the/boot/grub/grub.cfg that have been generated, based on previous methods of modifying/boot/grub/menu.lst. The advantage of this method is simple, the disadvantage is that after the modification will be "update-grub" command coverage.

• Modify the order of the startup items in the/etc/grub.d/and set the order of the items you want to start by default to a smaller value. The advantage is that the changes will not be "update-grub" command coverage, as if there is no shortage of power, only another program to change the smaller than your value will become the default boot.


• Modify the default startup entry in/etc/default/grub, and set the Grub_default in the file to the value you want, which is the starting 0 subscript for each startup item in the generated grub.cfg. The advantage of this method is that the modification is not overwritten by the "Update-grub" command, but the downside is that when the order of the Startup items changes, the subscript is changed.

Example:


Take the simplest and most commonly used option to turn on the default selection sequence and select wait time for example, I will start the Xen modified kernel.
1.vim/etc/default/grub
2. Change the numbers after the grub_default= and grub_timeout= two strings to what we want and save them off
How to get the order in which the system needs to be started can be obtained by/boot/grub/grub.cfg based on the generated.
This is my existing startup item:

0 ubuntu,linux 3.2.0-27-generic
1 ubuntu,linux 3.2.0-27-generic (recovery mode)
2 submenu "Previous Linux Versions":
#这是子项
ubuntu,linux 3.0.0-23-server
ubuntu,linux 3.0.0-23-server (recovery mode)
Ubuntu,linux 3.0.0-12-server
ubuntu,linux 3.0.0-12-server (Recovery mode)
3 ubuntu gnu/linux,xen 4.1-amd64 and Linux 3.2.0-27-generic
ubuntu gnu/ Linux,xen 4.1-amd64 and Linux 3.2.0-27-generic (recovery mode)
Ubuntu gnu/linux,xen 4.1-amd64 and Linux 3.0.0-23-server
Ubuntu Gnu/linux,xen 4.1-amd64 and Linux 3.0.0-23-server (recovery mode)
Ubuntu gnu/linux,xen 4.1-amd64 and Linux 3.0.0-12-server< C9/>ubuntu gnu/linux,xen 4.1-amd64 and Linux 3.0.0-12-server (recovery mode)
Memory Test (memtest86+)
Memory Test ( memtest86+, serial console 115200)


However: submenu "Previous Linux versions" is a system that belongs to 2,xen and is numbered 3. So modify the grub_default=3.

3. The final sudo update-grub don't forget.


The simplest approach:

In fact, the most simple thing is to read directly the content of/boot/grub/grub.cfg.

Find the keyword menuentry. The order of the kernel is the order of the Menuentry. You may see:

if ["${linux_gfx_mode}"!= "text"]; Then Load_video;
        Fi menuentry ' Ubuntu,linux 3.5.0-rc1+ '--class Ubuntu--class gnu-linux--class GNU--class os {recordfail
        Gfxmode $linux _gfx_mode insmod Gzio insmod part_gpt the Insmod set ext2 ' (root=) ' Search--no-floppy--fs-uuid--set=root 47caf968-871e-40da-b292-7d5683ef3e94 linux/vmlinuz-3.5.0-rc1+ Roo T=/dev/mapper/ubuntu-root ro initrd/initrd.img-3.5.0-rc1+} menuentry ' Ubuntu,linux 3.5.0-rc1+ (recovery mode) '--clas
        s Ubuntu--class gnu-linux--class GNU--class os {recordfail insmod Gzio insmod part_gpt Insmod ext2 set root= ' (hd0,gpt2) ' Search--no-floppy--fs-uuid--set=root f3e94 echo ' loads Linux 3.5.0-rc1+ ... ' linux/vmlinuz-3.5.0-rc1+ root=/dev/mapper/ubuntu-root ro recove RY Nomodeset echo Load initialization memory disk ... ' initrd/initrd.img-3.5.0-rc1+} submenU "Previous Linux versions" {menuentry ' ubuntu,linux 3.2.0-27-generic '--class Ubuntu--class gnu-linux--class GNU--cla 
        SS OS {recordfail Gfxmode $linux _gfx_mode insmod gzio insmod part_gpt insmod Set root= ' (hd0,gpt2) ' Search--no-floppy--fs-uuid--set=root 47caf968-871e-40da-b292-7d5683ef3e94

submenu appears with a submenu in it.

For example

1. Go directly to a kernel in the main menu

I'm going to start Linux 3.5.0-rc1+, which is the first of the main menu. I will modify the set default= "0" in this file (note, to obtain the right to write).

or directly modify the grub_default= "0" in/etc/default/grub (this will perform update-grub).

2. Use ">" to enter the submenu

I'm going to start Ubuntu,linux 3.2.0-27-generic can see that it belongs to the first of the submenu submenu that is ranked third in the main menu. So modify the set default= "2>0" in this file (note, to get the right to write).

or directly modify the grub_default= "2>0" in/etc/default/grub (this will be done update-grub).

Reference documents:
Http://www.360doc.com/content/10/0806/00/2369031_43985480.shtml
http://wenku.baidu.com/view/96a6b14f2b160b4e767fcffe.html###

Https://help.ubuntu.com/community/Grub2

Very detailed explanation: http://www.tudou.com/home/diary_v3885358.html


Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.