Linux Boot and kernel management

Source: Internet
Author: User
Tags crypt parent directory

system boot and kernel management

Linux composition

Linux:kerne+rootfs (Application)

Kernel: Process management, memory management, network management, drivers, file systems, security features

Roots: Programs and GLIBC

Function: Equivalent to a collection of commands

Libraries: function sets, functions, calling interfaces (header file is responsible for description)

Procedure call: Procedure, no return value

Functions Call: function

Program: Binary Execution file

Kernel design:

Single core (monolithic kernel): Linux

Integrate all functions into one program

Microkernel (micro kernel): Windows,solaris

Each feature is implemented using a separate subsystem

Kernel

Linux kernel Features:

Support modularity:. KO (Kernel object)

Such as: File system, hardware driver, network protocol, etc.

Supports automated loading and unloading of kernel modules

Part:

Core files:/boot/vmlinuz-version-release (storing some of the most important files)

RAMDisk: Auxiliary pseudo-File system

Centos5;/boot/initrd-version-release.img

Centos6,7:/boot/initramfs-version-release.img

Module files:/lib/modules/version-release (most function modules)

/lib/modules (storage of most drives)


CENTOS6 startup process

Post Power-up check →mbr boot →grub→ load kernel


Start the process:

Post:power-on-self-test

ROM (Read only): BIOS, save the computer system important basic input and output programs, power will run these programs, System Information settings, power on the self-test program, etc.

RAM (does not represent memory here): Power loss does not lose data in RAM because the motherboard has a battery and the order of adjustment in the BIOS is saved here

Find the boot device in order, the first device with a boot program is the boot device (can be adjusted in the BIOS)

Bootloader: Boot loader (a program used to start the computer), boot program

Windows:ntloader, just start the OS and just start Windows

Linux: Early use of Lilo (Linux loader can only be used to boot Linux) to boot Linux,grub boot Linux can also boot Windows

Grub:grand Unified Bootloader

GRUB 0.X: Old version

Mbr:

446:bootloader (first stage of Grub), 64: Partition table, 2:55AA

Grub:

Primary boot loader:1st Stage (first phase of grub)

1.5 Stage (the file system driver used to read the boot partition) both are stored in binary mode

Read file system driver, use Initramfs-version-release file to read file system driver;

CENTOS5 RAMDisk: Simulates a disk and converts the emulated disk to a file system and then to a disk

CENTOS6 Ramfs: Directly to a file system to access the disk through the file system


System initialization

Post-->bootsequence (BIOS)-->bootloader (MBR)-->kernel (RAMDisk)-->rootfs (read-only)-->init (SYSTEMD)

RAMDisk File creation:

MKINITRD "filename (preferably formerly known as) ' Uname-r '. img" ' Uname-r ' (re-authoring RAMDisk file for the kernel currently in use)


Types of init programs

Sysv:init,centos 5 ago

Configuration file/etc/inittab

Upstart:init,centos6

Configuration files:/etc/inittab,/etc/init/*.conf

SYSTEMD:SYSTEMD, CentOS 7

Configuration file:/usr/lib/systemd/system

/etc/systemd/system


Boot START process:

Post

MBR boot loader Grub

/boot/vmlinxz

/boot/initramfs.

/sbin/init

/etc/inittab

/etc/rcn.d/-/etc/init.d/xxx

/etc/rc.d/rc.local

Login


Mode (adjust the boot mode in/etc/inittab):

0: Turn off the machine

1: Single-user mode

2: Multi-user mode, no NFS function

3: Multi-user mode (almost the same as 2, and the character interface)

4: Not used, temporarily useless

5: Graphical interface

6: Restart

Default Level: 3,5

Toggle Level: Init #

View level: RunLevel

Configuration file for Centos 5:/etc/inittab

NTSYSV viewing boot-up programs

Chkconfig--list "program name"

--add added to the boot-up service

"Program name" on boot start

--del "program name" Delete Service boot start

(1) Default mode definition

(2) System initialization script

(3) script corresponding to the running mode

/etc/rc#.d/a series of start-up files in the beginning of S, the lower the number, the highest priority of the boot;

Also holds a series of stop files at the beginning of K, the smaller the value, the higher the priority of the shutdown

/etc/rc#.d/s99local function is to write the boot to do things

The content in/etc/rc.d/rc.local is started as the server boots up

Services managed by xinetd

Transient: Service is managed by the XINETD process

The incoming request was first XINETD agent

Configuration files:/etc/xinetd.conf,/etc/xinetd.d/<servicename>


When the Vmlinux file in the/boot directory is lost, you can use the disc rescue mode to rename the Vmlinux under Isolinux in the disc and copy it to the/boot directory.

cp/mnt/cdrom/isolinux/vmlinux/mnt/sysimage/vmlinux-' Uname-r ' can

Enter rescue mode execution when the/boot directory is lost

Rpm-ivh/mnt/cdrom/package/kernel-xxxxxx--force--root=/mnt/sysimage/


Grub Legacy

Grub

Stage1:mbr

Stage1_5 (1.5 stage): Sector after MBR

GRUB.CONF (Grub configuration file)

The location of the root partition is indicated in/etc/grub.conf, a sequence of processes can be found after the root file is found, and then started


Installing GRUB

(1) Grub-install

Install Grub Stage1 and stage1_5 to/dev/disk disk and copy grub-related files to the Dir/boot directory

Grub-install [--root-directory=dir] (Specifies the parent directory for the location of the grub installation)/dev/disk 440-byte repair method GRUB-INSTALL/DEV/SDA

(2) Grub (Interactive command, HD writes the first hard drive of the boot mount point, hd0,0 is the number one partition of the first hard drive)

Root (hd#,#)

Setup (hd#)


Crack root password (must be in front of server)

(1) When the selection menu appears during startup, enter "a" in the rear input 1 to enter single user mode

(2) After entering passwd root to set a new password

(3) Append "Password Fang" to the/etc/grub.conf file to add the single-user mode to the plaintext password

Grub-md5-crypt can generate a random MD5 password, copy the generated random password to the/etc/grub.conf password followed by entering single-user mode encryption

Grub-crypt generates random passwords and copies the generated random passwords to password-encrypted in/etc/grub.conf

Start Password:/etc/grub.conf Start menu Add password-encrypted "generated random password" can be added with password to start


Configuration file:/boot/grub/grub.conf

default=#: Sets the default Startup menu item;

timeout=#: Specifies the duration of the menu item Wait option selection

Splashimage (hd#,#)/path/xpm_file: Menu background image

Password: Start menu edit Set Password

Hiddenmenu: Hide Menu

Title: Defining the menu item title

Root (hd#,#): Find the device partition where the Stage2 and kernel files reside;

Kernel: Root kernel "Kernel pack location" for Grub

INITRD "kernel-matched Ramfs file"


/proc directory:

Storing a series of process files

Parameters: Read-only: Output information

/proc/sys

Sysctl-a: All the settings that are in effect

SYSCTL-W: Modifies a specified row of data, the modified data is stored in memory, and is restored after a reboot

Sysctl-p: Read the/etc/sysctl.conf file, is the modification to take effect, when there is no line in the file, it will be synchronized with the definition in the NEI

Common parameters:

Net.ipv4.forward: Whether the management routing function turns on 0 on, 1 is off

Net.ipv4.icmp_echo_ignore_all: Do not allow other hosts to ping themselves

Vm.drop_caches: To change this value to 1 is to free the cache memory

/sys directory:

Storage of a range of key hardware-related content


Compiling the installation kernel

Kernel components:

Kernel, kernel core, typically in the/boot directory, named Vmlinuz-version-release

Kernel object: Kernel objects, typically placed in/lib/modules/version-release

[]:not Set (not enabled)

[M]:m (exists as a module, and is a standalone file)

[*]:y (stored in Vmlinuz, not stand-alone file)


Kernel version

In-run kernel:

uname command:

Uname-print System Information

uname [OPTION] ...

-N: Display host name

-R: Display Version-release

-A: Show All information

Kernel module Commands:

Lsmod displaying modules that have already been loaded

The content displayed is from:/proc/modules file

Modinfo command:

Display detailed description of the module

Modinfo [-K kernel] [modulename|filename]

-N: Show only module file path

-P: Display module parameters

-a:author author

-d:description description

-l:license

Example: Lsmod | grep Xfs;modinfo XFS to see if XFS modules are running and view details


modprobe command (automatically resolves dependencies):

Loading or unloading kernel modules

Modprobe

-R: Unload the module, and there is a dependency between the modules, and after the drive disappears, the hardware disappears.

Configuration file:/etc/modprobe.conf or/etc/modprobe.d/*.conf

Depmod command:

To set dependencies between modules

To mount or unload a kernel module:

Insmod command: Specifies the module file and does not automatically resolve the dependent module

insmod [filename] [module options]

Insmod ' Modinfo-n exportfs ' (The execution results in the anti-apostrophe are loaded with insomod)

Rmmod command: Uninstalling the module

Rmmod [ModuleName]


Compiling the kernel

1 Download the kernel file to be compiled from www.kernel.org

2 Installing the Development Tools Group

3. config: Prepare the text configuration file, you can modify the existing config-3.10.0-693.el7.x86_64 file on the system to the. config file editing

4 Make Menuconfig: Configure kernel options, this command is a menu, the menu "--->" after the description of the sub-menu

[]:not Set (not enabled)

[M]:m (exists as a module, and is a standalone file)

[*]:y (stored in Vmlinuz, not stand-alone file)

5 Make [-j #] (-j Specifies the number of CPU cores) will generate a compiled version of the directory under/lib

6 Make Modules_install: Install the module, which is equivalent to installing the Lib/modules directory

7 make install: Install kernel-related files


Linux Boot and kernel management

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.