GRUB application + Small Linux system preliminary

Source: Internet
Author: User
Tags administrator password

GRUB Full name GNU Grub

Version: Grub (GNU grub 0.97)

GRUB2 is the rewritten version of Grub, which can be said to be different.

Wiki:https://zh.wikipedia.org/wiki/gnu_grub

Grub has a total of 3 phases:
bootloader:1st Stage
Partition:filesystem driver, 1.5 stage
Partition:/boot/grub, 2nd Stage

Directory:

1, grub description.

2. Add authentication for GRUB.

3. Installing GRUB

4, Small Linux.


1.

The configuration file for grub is/boot/grub/grub.conf.

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/79/10/wKiom1aHQ9mR7txvAAE4eL8n8LA392.jpg "title=" 096. JPG "alt=" wkiom1ahq9mr7txvaae4el8n8la392.jpg "/>

In this version of Grub, the root of grub is defined, 0 means the disk where grub is located (it is the first disk for grub), the next 0 represents the first partition, and so on. But on the GRUB2 it seems that both the disk and the partition start from 1.

The location of the kernel or INITRD is defined for the location of the grub root, because only grub, kernel, and INITRD are now running for grub to boot.


The parameters used in the following KERNL are:

These parameters are arguments passed to kernel, which are not related to grub. When the system starts to arrive at this step, grub is out of the lake.

RO: Indicates a read-only mount Root partition, which is the/in the system.

Root: Defines the location of the root, which is the location where the hardware information is refreshed after the kernel is started, unlike the grub location. Above is the address of the LVM logical volume. If it is a direct physical address, such as:/dev/sda2.

SELinux: Defines whether SELinux is enabled (the kernel has this capability). Selinux=0 means half closed. 1 means enable. Enabled by default.

Init: Defines where the INIT program is used to manage user space after the system is started. such as: Init=/bin/bash.

Quiet: Silent mode, the kernel information is not displayed during startup.

Single or 1 or S or S. Enter single-user mode without entering the administrator password. Often used in situations where the root password is forgotten.


Grub file Full Configuration entry:
default=#: Sets the default Start menu item, and the entry (title) number starts at 0;
timeout=#: Specifies the length of time the menu item waits for an option to be selected;
Splashimage= (hd#,#)/path/to/xpm_pic_file: Indicates the menu background picture file path;
Hiddenmenu: Hide menu;
Password [--MD5] STRING: Menu Editor authentication;
Title Title: Define the menu item "title", can appear multiple times;
Root (hd#,#): Grub finds the device partition where the Stage2 and kernel files are located; "root" for grub;
Kernel/path/to/vmlinuz_file [PARAMETERS]: Boot kernel
Initrd/path/to/initramfs_file: Kernel-matched Ramfs file;
Password [--MD5] STRING: Authenticates when the selected kernel or operating system is started;


The function of the second phase of Grub:
(1) menu and interactive interface available
E: Edit mode, for editing menus;
C: Command mode, interactive interface;
(2) Loading the user-selected kernel or operating system
Allow parameters to be passed to the kernel
To hide this menu
(3) provides a protection mechanism for the menu
Certification for the Edit menu
To enable authentication for the kernel or operating system


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/79/11/wKiom1aHWmyRDUldAACd7POjNQQ269.jpg "title=" 101. JPG "alt=" wkiom1ahwmyrduldaacd7pojnqq269.jpg "/>

A modifies the parameters currently attached to the kernel.

E goes into edit mode, just like the configuration in the grub.conf file.

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/79/11/wKiom1aHWs_zJC5SAAAwz4ongzM176.jpg "title=" 102. JPG "alt=" wkiom1ahws_zjc5saaawz4ongzm176.jpg "/>

I'm here in kernel. This item presses e into the edit state of this item.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/79/11/wKiom1aHXmChmz2QAAAb2wEnbLw660.jpg "title=" 105. JPG "alt=" wkiom1ahxmchmz2qaaab2wenblw660.jpg "/>

Here you can modify the settings inside, press ESC to return and press B to start booting.


C interactive mode, which is also set in this way. As the following, after the setup is complete, enter boot to start booting.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/79/11/wKiom1aHW-6CD4e-AADNoC5qL8k307.jpg "title=" 103. JPG "alt=" wkiom1ahw-6cd4e-aadnoc5ql8k307.jpg "/>

Help can view the instructions that can be entered.


2, add certification :

Added password certification to/boot/grub/grub.conf.

The representation in the respective title for authentication using the kernel does not have a certificate in the title for the edit grub.

Password [--MD5]

No--md5 means that the key behind password is clear text,

Plus--MD5 indicates that the key is encrypted with MD5.

To generate an encrypted key can be used: Grub-md5-crypt

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/79/11/wKiom1aHZE2gQKaXAAA1cvxcFNE379.jpg "title=" 107. JPG "alt=" wkiom1ahze2gqkaxaaa1cvxcfne379.jpg "/>

Join the grub.conf file. I've added both the kernel and grub certifications here.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/11/wKiom1aHZVnQh6eSAAC6g3oxxa8598.jpg "title=" 108. JPG "alt=" wkiom1ahzvnqh6esaac6g3oxxa8598.jpg "/>

Save and reboot later, to grub here. You must press p to enter a password before you can edit grub. This is the GRUB certification.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/10/wKioL1aHZe6iru7nAAB4e1ClLZw257.jpg "style=" float: none; "title=" 109.jpg "alt=" Wkiol1ahze6iru7naab4e1cllzw257.jpg "/>

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/79/11/wKiom1aHZc_hT8uoAAB_nDVz6yI845.jpg "style=" float: none; "title=" 110.jpg "alt=" Wkiom1ahzc_ht8uoaab_ndvz6yi845.jpg "/>


And the kernel authentication that, as long as the corresponding kernel to launch the following will appear. Only the password is correct to boot the kernel into the system.

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/79/10/wKioL1aHZfHwqEsGAAAIfrATdEY372.jpg "style=" float: none; "title=" 111.jpg "alt=" Wkiol1ahzfhwqesgaaaifratdey372.jpg "/>


3. Install Grub:

There are two commands, Grub-install, and the Setup command in the GRUB command interaction mode.

(1) Grub-install

Grub-install--root-directory=root/dev/disk

(2) Grub
grub> Root (hd#,#)
grub> Setup (hd#)


grub.conf configuration files should be written on their own.

Grub-install can install a complete grub that contains all the stages.

Setup installs each stage and 1.5 stages of grub. And relies on the second phase of the document on phase 1th, 1.5. This is the 1, 1.5-stage file in the/boot/grub/directory.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/10/wKioL1aHaXLjiGl3AADs7LXQWuM969.jpg "title=" 112. JPG "alt=" wkiol1ahaxljigl3aads7lxqwum969.jpg "/>

The above 1-stage file Stage1, just one. But 1.5 of the files have a lot of them, but look carefully to understand the different file systems. The purpose of GRUB 1.5 is to load the driver of the basic file system. When Setup installs, it automatically recognizes which file system files are being used.


Try Grub-install first.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/79/10/wKioL1aHbPnjb1olAABYmi4J_L4253.jpg "title=" 113. JPG "alt=" wkiol1ahbpnjb1olaabymi4j_l4253.jpg "/>

Specifies the disk directory installation boot (grub phase 2nd). Specifies the disk installation 1th, 1.5-stage grub.

Do not specify the boot directory directly, because the command output is boot. Specify the boot directory, which will have a boot directory in the boot directory.


Let's take a look at setup:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/79/10/wKioL1aHb8bzDXl7AAGHVjnrZ1s883.jpg "title=" 114. JPG "alt=" wkiol1ahb8bzdxl7aaghvjnrz1s883.jpg "/>

root specifies the grub directory, which disk the setup installs to. As you can see, Setup looks for Stage1, 1.5, and 2 stage files. Finally installed the E2FS (EXT series) 1.5-stage file, which occupies 27 sectors, and the 1th phase of the file.


4, Small Linux.

I have installed a second disk here, divided into two zones, one as the boot partition, and one as the primary partition. Of course, only one partition is also possible.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/79/11/wKiom1aHcduwJcK_AAC-6c-3Nz0418.jpg "title=" 115. JPG "alt=" wkiom1ahcduwjck_aac-6c-3nz0418.jpg "/>

Two partitions were formatted as EXT4 file systems. and mount to the boot and sysroot directories below/mnt.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/11/wKiom1aHctbTDKsDAAAsIkz2Ps8819.jpg "title=" 116. JPG "alt=" wkiom1ahctbtdksdaaasikz2ps8819.jpg "/>


To install Grub:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/79/10/wKioL1aHc3WQVGa1AABoU-M3ZM8275.jpg "title=" 117. JPG "alt=" wkiol1ahc3wqvga1aabou-m3zm8275.jpg "/>

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/79/12/wKiom1aHdHCzrEySAACcRCfe8Dc790.jpg "title=" 120. JPG "alt=" wkiom1ahdhczreysaaccrcfe8dc790.jpg "/>


Copy the kernel on the system into our small system.

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/79/12/wKiom1aHdNWBnTjWAABL2SPES6A331.jpg "title=" 121. JPG "alt=" wkiom1ahdnwbntjwaabl2spes6a331.jpg "/>


Edit the grub.conf file.

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/79/12/wKiom1aHdTCy6oAVAAARD8LQ2eY925.jpg "title=" 122. JPG "alt=" wkiom1ahdtcy6oavaaard8lq2ey925.jpg "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/79/12/wKiom1aHcz7xYVlwAAAti2vQzc8967.jpg "title=" 118. JPG "alt=" wkiom1ahcz7xyvlwaaati2vqzc8967.jpg "/>

The above init can be init=/bin/bash directly. I'm here for Echo Point information.


The grub file is complete. Let's add some material to the Sysroot catalogue. Inside the proc directory must have, otherwise open the opportunity to fail.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/10/wKioL1aHdmngFatOAAA-79BNYy8868.jpg "title=" 123. JPG "alt=" wkiol1ahdmngfatoaaa-79bnyy8868.jpg "/>

And then put bash inside the/bin/bash. Note that the software is dependent on the library, to copy the past.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/79/10/wKioL1aHdxyw3GxcAACJm4YpfT8570.jpg "title=" 124. JPG "alt=" wkiol1ahdxyw3gxcaacjm4ypft8570.jpg "/>

Here's a script that can be copied all, and I'll test it with this script.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/79/10/wKioL1aHd92z-wHEAAB10u5l1pU561.jpg "title=" 125. JPG "alt=" wkiol1ahd92z-wheaab10u5l1pu561.jpg "/>

Almost, if the front is Init=/bin/bash (bash is located in the directory is under the/bin directory), then you can shut down this host, the hard drive to hang to another host to try. I'm using init here, so we're going to create an init file.

The above forgot to create the Sbin directory. Our init designation is/sbin/init.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/79/10/wKioL1aHeqvwD4q2AAAOtIy_LxQ379.jpg "title=" 129. JPG "alt=" wkiol1aheqvwd4q2aaaotiy_lxq379.jpg "/>

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/79/12/wKiom1aHemWyvikzAAAQPy-YNHo615.jpg "style=" float: none; "title=" 127.jpg "alt=" Wkiom1ahemwyvikzaaaqpy-ynho615.jpg "/>

Add executable permissions.

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/79/10/wKioL1aHeoehWNAqAAAa9R9Gf0U385.jpg "style=" float: none; "title=" 128.jpg "alt=" Wkiol1aheoehwnaqaaaa9r9gf0u385.jpg "/>

Add a few sync commands and you can hang up the machine.


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/79/10/wKioL1aHfBCz7xBfAAA1HpkyLcY392.jpg "title=" 131. JPG "alt=" wkiol1ahfbcz7xbfaaa1hpkylcy392.jpg "/>

I am a notebook here, the disk is a bit slow, to wait until the hard drive light is not lit after you can open another virtual machine. Oh, of course, we haven't built it yet.

The newly created virtual machine uses the disk that you just added.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/79/12/wKiom1aHfBXDcAAtAABcaA87vd0089.jpg "title=" 132. JPG "alt=" wkiom1ahfbxdcaataabcaa87vd0089.jpg "/>


After the completion of the boot, the following is the title of the grub we did just now. 650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/79/12/wKiom1aHfPaTuBNFAAAurub0fSs815.jpg "style=" float: none; "title=" 133.jpg "alt=" Wkiom1ahfpatubnfaaaurub0fss815.jpg "/>

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/79/12/wKiom1aHfQfQe9FAAAHAPCgKeQ8327.jpg "style=" float: none; "title=" 135.jpg "alt=" Wkiom1ahfqfqe9faaahapcgkeq8327.jpg "/>

Success, this time is a one-off success. It was a good time to do it several times yesterday. Let's fix it next.

Without the power off function, we have no shutdown function here from start to finish.

Turn off the power directly, and then open the original host.

Here are a few more commands:

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/79/12/wKiom1aHf9jBJF_3AABUWG_PMUw339.jpg "title=" 136. JPG "alt=" wkiom1ahf9jbjf_3aabuwg_pmuw339.jpg "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/79/11/wKioL1aHggSgjV64AAAUkWeVEUE601.jpg "title=" 139. JPG "alt=" wkiol1ahggsgjv64aaaukweveue601.jpg "/>

Find out how to know your NIC driver module below. I'm a e1000.ko here.

With Lsmod You can view all the loaded modules, Modinfo can view the module details.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/79/12/wKiom1aHgDbhfO1MAAAo_ES328Q766.jpg "title=" 137. JPG "alt=" wkiom1ahgdbhfo1maaao_es328q766.jpg "/>

Copy it to the Lib directory of our small system and load it in the init file for a moment.

Now the init file: let echo out the color, and mount re-read and write to mount the root, Mount boot. Load the NIC module and configure the IP address.

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/79/12/wKiom1aHggyx5PfuAAB-lFX4RMo607.jpg "title=" 138. JPG "alt=" wkiom1ahggyx5pfuaab-lfx4rmo607.jpg "/>


Sync,sync, hangs, and then starts another host. Note Do not directly turn off the original host power.

Start the small host to see:

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/79/11/wKioL1aHg1vgJNbxAAEJovrkVqI554.jpg "style=" float: none; "title=" 140.jpg "alt=" Wkiol1ahg1vgjnbxaaejovrkvqi554.jpg "/>

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/79/12/wKiom1aHgzyQseZgAAEVz6_ccRw782.jpg "style=" float: none; "title=" 142.jpg "alt=" Wkiom1ahgzyqsezgaaevz6_ccrw782.jpg "/>

Found a problem, use CTRL + C no use.

Well, I don't know what to do next. This is the right place to go. I hope my friends can understand how Linux is started through this process.

Thank you for browsing, if you have the wrong place, please also point out. Thank you.

This article is from the "Big Tomato" blog, be sure to keep this source http://fanqie.blog.51cto.com/9382669/1730875

GRUB application + Small Linux system preliminary

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.