Linux tips Grub Super Useful tips

Source: Internet
Author: User
Tags gcov lost password

1. Introduction

What is GRUB? GRUB Full name Grand Unified boot Loader, which is a boot loader-it is responsible for loading the kernel and booting the Linux system. GRUB can also boot other operating systems, such as FreeBSD, NetBSD, OpenBSD, GNU HURD, DOS, and Windows. Although booting the operating system looks like an ordinary and trivial task, it is actually important. If the boot loader does not perform well or is not resilient,
Then it is possible to lock the system and not boot the computer. Additionally, a good boot loader gives you the flexibility to install multiple
Operating system without having to deal with unnecessary hassles.

Not much nonsense to say, look at also not much meaning, hurriedly into the text, want to see the introduction can go to the "Grub Tutorial" learning.


2. Basic application of grub techniques

today, newer computers are loaded with GRUB2, and GRUB2 uses a configuration file that is/boot/grub/grub.cfg. After opening we can find a sentence like this:

set default= "0"   This option is used to select the default system of , 0 is the first one, if you have 5 options, they correspond to  /boot/grub/grub.cfg file:

menuentry ' Debian gnu/linux, with Linux 3.2.51-trace '- -class Debian--class gnu-linux--class GNU--class os {                  &N Bsp ---0
...
}
Menuentry ' Debian gnu/linux, with Linux 3.2.51-trace (recovery mode) '--class Debian--class gnu-linux--class gn U--class os {   ---1
...
}
Menuentry ' Debian gnu/linux, with Linux 3.2.0-4-amd64 '--class Debian--class gnu-linux--class GNU--class os {                    ---2
...
}
Menuentry ' Debian gnu/linux, with Linux 3.2.0-4-amd64 (recovery mode) '--class Debian--class gnu-linux--class g Nu--class os {   ---3
...  
}
Menuentry "Windows 7 (Loader) (ON/DEV/SDA1)"--class windows--CL The  ---4
...
}

So, you just have to choose the number of cores according to your own! For example I want my win 7 as the default system, I can menuentry "Windows 7 ... This section moved to menuentry ' Debian gnu/linux, with Linux 3.2.5 ... Before, you can change the set default= "0" to 0 directly to 4!


Set timeout=5 This option to set the GRUB option wait time , if it is 5 is not selected in 5 seconds, load the cursor option!


3. The Grub skill folding option

A computer system with more or more variants of the kernel, perhaps your grub options will become this:


Choose a kernel you want to go up and down the page, so how to deal with this problem? Effective management of these options? About this, the grub on Ubuntu can give us a good hint, yes, if you have used Ubuntu, after you compile the kernel, the kernel on one system will be collapsed, for example, the grub on my other laptop will be like this:

* Ubuntu, with Linux 3.2.0-61-generic-pae
* Ubuntu, with Linux 3.2.0-61-generic-pae
* Previous Linux versions
* Windows 8 (loader)

The cursor moves to the "Previous Linux versions" option, and after entering, Grub will show some other kernel options:

* Ubuntu, with Linux 3.12.13-rt4
* Ubuntu, with Linux 3.12.13-rt4 (recovery mode)
* Ubuntu, with Linux 3.12.13-ftrace
* Ubuntu, with Linux 3.12.13-ftrace (recovery mode)
* Ubuntu, with Linux 3.4.24-test
* Ubuntu, with Linux 3.4.24-test (recovery mode)
* Ubuntu, with Linux 3.2.0-51-generic-pae
* Ubuntu, with Linux 3.2.0-51-generic-pae (recovery mode)

So how do we do this on our own, open Ubuntu/boot/grub/grub.cfg after I understand, originally this is just grub a level two menu feature "submenu" Previous Linux versions "{...}", so my pen Ben can play like this:

$ sudo vim/boot/grub/grub.cfg

Menuentry ' Debian Gnu/linux, with Linux 3.12.9-gcov-rt13 '--class Debian--class gnu-linux--class GNU--class os
submenu "Previous Debian versions" {
Menuentry ' Debian Gnu/linux, with Linux 3.12.9-gcov-rt13 (recovery mode) '--class Debian--class gnu-linux--class GNU--c Lass OS
Menuentry ' Debian Gnu/linux, with Linux 3.12.9-testing-rt13 '--class Debian--class gnu-linux--class GNU--class os
Menuentry ' Debian Gnu/linux, with Linux 3.12.9-testing-rt13 (recovery mode) '--class Debian--class gnu-linux--class GNU --class OS
Menuentry ' Debian Gnu/linux, with Linux 3.10.17-trace-rt12 '--class Debian--class gnu-linux--class GNU--class os
Menuentry ' Debian Gnu/linux, with Linux 3.10.17-trace-rt12 (recovery mode) '--class Debian--class gnu-linux--class GNU- -class OS
Menuentry ' Debian Gnu/linux, with Linux 3.9.11-trace '--class Debian--class gnu-linux--class GNU--class os
...
}
Menuentry "Windows 7 (Loader) (ON/DEV/SDA1)"--class Windows--class OS
Menuentry "Elementary OS, with Linux 3.2.0-51-generic (on/dev/sda10)"--class gnu-linux--class GNU--class OS
submenu "Previous Elementary OS versions" {
Menuentry "Elementary OS, with Linux 3.2.0-51-generic (recovery mode) (ON/DEV/SDA10)"--class gnu-linux--class GNU--cla SS OS
}
Menuentry "Ubuntu (on/dev/sda8)"--class gnu-linux--class GNU--class os
submenu "Previous Ubuntu versions" {
Menuentry "Ubuntu,linux 3.11.0-18-generic (on/dev/sda8)"--class gnu-linux--class GNU--class os
Menuentry "Ubuntu,linux 3.11.0-18-generic (Recovery mode) (ON/DEV/SDA8)"--class gnu-linux--class GNU--class os
Menuentry "Ubuntu,linux 3.11.0-13-generic (on/dev/sda8)"--class gnu-linux--class GNU--class os
Menuentry "Ubuntu,linux 3.11.0-13-generic (Recovery mode) (ON/DEV/SDA8)"--class gnu-linux--class GNU--class os
...

So suddenly, my machine is now booting up like this:


Is it a lot fresher?


4. Change password of grub technique

Do you think you are using Linux system security? Are you safe with the code? Try the Mighty Grub!!!

(1). System boot, enter the GRUB selection screen! As shown in the picture above

(2). Press the E key above an option to enter the GRUB editing interface! (Nothing, bold attempt, will not be permanently saved, even if the preservation of the wrong things, not recovery mode!!! )

(3). For example, my current editing interface shows something like this:

Recordfail
Gfxmode $linux _gfx_mode
Insmod Gzio
Insmod Part_msdos
Insmod ext2
Set root= ' (Hd0,msdos8) '
Search--no-floppy--fs-uuid--set=root c81eebc3-ed49-4661-be49-eadeb0de4696
linux/boot/vmlinuz-3.2.0-61-generic-pae root=uuid=c81eebc3-ed49-4661-be49-eadeb0de4696 ro quiet Splash $vt _hand Off
Initrd/boot/initrd.img-3.2.0-61-generic-pae

We need to modify the above I use color-coded lines, we will change the RO to RW, the contents of the following all deleted! Add on Init=/bin/bash

In other words, after the change is done:

Linux/boot/vmlinuz-3.2.0-61-generic-pae root=uuid=c81eebc3-ed49-4661-be49-eadeb0de4696 RW Init=/bin/bash

At this point, we press ctrx+x or F10 to save and enter, we will find that after a period of time after loading, we do not have any password to get root privileges! !! So is the system still safe??? We can load any partition and then get any content you want to keep secret! Cheer Up ~ ~ ~


However, I'm here to introduce this method is not to let you go to the trick!!! It can be used in a very useful way: lost Password can use this method to modify the password! System crashes you can use this method to copy important files away! Wait ~ ~


5. Grub Skills Recovery System

Sometimes, we will install multiple systems, such as the photo above, I have a notebook installed 4 systems, which will be a system of grub as a computer loader! For example, the Debian grub on my computer is used by me as the default loader for my Computer! But one day I compiled a kernel on Ubuntu and used UPDATE-GRUB2 to update grub, but when the system starts, you will find that your update is not in effect and you need to go to Debian and use UPDATE-GRUB2, which is under Ubuntu. The kernel will appear in the System boot Menu!

There is a situation, such as my computer only Debian and win8 two systems, but one day my win 8 crashed so I re-installed the system, I found that I can only enter Windows, and no longer lead Debian, because the Windows boot program does not boot Linux!


What do you do when you encounter both of these situations? Use grub-install! methods can be found in the Ubuntu system failures of those years



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.