Homemade Linux Temporary Save draft

Source: Internet
Author: User
Tags echo command

Kernel compilation

Single kernel system design, but fully learn the advantages of micro-core design system for the kernel to introduce a modular mechanism.

Kernel components:

Kernel: Kernel core, generally bzimage, usually in the/boot directory, the name is vmlinuz-version-release;

Kernel object: Kernel objects, typically placed in

/lib/modules/version-release/

[]: N

[m]: M

[*]: Y

Auxiliary files: RAMDisk

Initrd

Initramfs


In-run kernel:

uname command:

Uname-print System Information

Uname[option] ...

-N: Displays the node name;

-R: Display version-release;

-A: Show All information


Lsmod command:

Displays kernel modules already loaded by the core

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

-d:description

-l:license

Lsmod|grep XFS;MODINFOXFS


modprobe command:

Loading or unloading kernel modules

Modprobe[-C Config-file] [modulename] [module parame-ters ...]

Configuration files:/etc/modprobe.conf,/etc/modprobe.d/*.conf

Modprobe[-r] modulename ...


Depmod command:

Kernel module dependency file and System Information mapping file Generation tool

To mount or unload a kernel module:

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

insmod[filename] [module Options ...]

Insmod ' Modinfo–n exportfs '

Lnsmod ' Modinfo–n xfs '

Rmmod

rmmod[ModuleName]

Rmmodxfs

Rmmodexportfs


/proc directory:

The kernel outputs its own internal state information and statistics, as well as configurable parameters through the proc pseudo-file system.

Parameters: Read-only: Output information

Writable: User-specified "new value" can be accepted for configuration of a function or feature of the kernel

/proc/sys

(1) The SYSCTL command is used to view or set many parameters in this directory

Sysctl-w Path.to.parameter=value

Sysctl-w kernel.hostname=mail.magedu.com

(2) The echo command can also modify the values of most parameters by means of redirection

echo "VALUE" >/proc/sys/path/to/parameter

echo "Websrv" >/proc/sys/kernel/hostname


Sysctl command:

Default configuration file:/etc/sysctl.conf

(1) Setting a parameter

Sysctl-w Parameter=value

(2) Setting parameters by reading the configuration file

Sysctl-p [/path/to/conf_file]

Route forwarding in the kernel:

/proc/sys/net/ipv4/ip_forward

A few common parameters:

Net.ipv4.ip_forward

Net.ipv4.icmp_echo_ignore_all

Vm.drop_caches


/sys directory:

SYSFS: For the user's pseudo-file system, the output kernel identifies the relevant property information of each hardware device, as well as the setting information of the kernel on the hardware characteristics; some parameters can be modified to adjust the hardware operating characteristics.

Udev creates the required device files for each device dynamically through the information that is output from this path, and Udev is the user-space program that runs the

Special tools: Udevadmin, HotPlug

When Udev creates a device file for a device, it reads its pre-defined rule file, typically in the/ETC/UDEV/RULES.D and/USR/LIB/UDEV/RULES.D directories


RAMDisk File creation:

(1) MKINITRD command

Re-authoring the RAMDisk file for the kernel that is currently in use

mkinitrd/boot/initramfs-$ (uname-r). img$ (Uname-r)

(2) Dracut command

Re-authoring the RAMDisk file for the kernel that is currently in use

dracut/boot/initramfs-$ (uname-r). img$ (Uname-r)


Compiling the kernel

Premise:

(1) Prepare the development environment.

(2) Get information about hardware devices on the target host

(3) Get information about the function of the target host system

For example, you need to enable the appropriate file system

(4) Get the kernel source code package


www.kernel.org


Development environment Preparation

Package Group (CentOS 6):

Server Platform Development

Development Tools

Target host hardware Device related information:

Cpu:

#cat/proc/cpuinfo

#x86info-A

#lscpu


Hardware devices

PCI Device:

Lspci

-V

-vv

Lsusb

-V

-vv

LSBLK Block Equipment

See all Hardware Device information

Hal-device


Kernel Compilation Installation System

Install the Development Pack Group

Download source file

. config: Preparing the text configuration file

Make Menuconfig: Configure kernel options

Make [-j #]

Make Modules_install: Install the module

Make install: Install kernel-related files

Install Bzimage to/boot/vmlinuz-version-release

Generate Initramfs File

Edit the Grub configuration file


Compiling the installation kernel instance

Tar XF linux-3.10.67.tar.xz-c/usr/src

Cd/usr/src

LN-SV linux-3.10.67 Linux

Cd/usr/src/linux

cp/boot/config-$ (uname-r)./.config

Make Help

Make Menuconfig

Make-j 2

Make Modules_install

Make install

Reboot


Compiling the kernel

(1) Configuring kernel options

Support for configuration in "Update" mode: Make Help

(a) Make config: Configure each option configurable in the kernel based on the command line in a traversed manner

(b) Make Menuconfig: curses-based text window interface

(c) Make Gconfig: GTK (GNOME) Environment-based window interface

(d) Make Xconfig: QT (KDE)-based window interface

Support for configuration in "New Configuration" mode

(a) Make Defconfig: Configuration based on the "default" configuration provided by the kernel for the target platform

(b) Make Allyesconfig: All options are answered "yes"

(c) Make Allnoconfig: All options are answered "no"

(2) compiling

Full compilation: Make [-j #]

Part of the kernel to compile:

(a) Compile only the relevant code in a subdirectory:

# Cd/usr/src/linux

# Make dir/

(b) Only one specific module is compiled:

# Cd/usr/src/linux

# Make Dir/file.ko

For example: Only the e1000 compiler driver:

#make Drivers/net/ethernet/intel/e1000/e1000.ko

How to cross-compile the kernel:

The target platform of the compilation is not the same as the current platform;

# Make Arch=arch_name

To get help with a specific target platform

# Make Arch=arch_namehelp

# Make Arch=arm Help


Recompile the kernel source tree that has already performed the compile operation:

You need to clear the operation beforehand:

# Make Clean: Cleans up most compiled generated files, but preserves config files, etc.

# make Mrproper: Clean up all compiled generated files, config, and some backup files

# make Distclean:mrproper, patches, and editor backup files


Example: Kernel compilation plot

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/70/wKiom1fflcrT5tFKAAC8v5gjsXw211.png "title=" 27.png "Style=" Float:none; "alt=" Wkiom1fflcrt5tfkaac8v5gjsxw211.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/6D/wKioL1fflcqx3E68AAAKZanLgRw217.png "title=" 28.png "Style=" Float:none; "alt=" Wkiol1fflcqx3e68aaakzanlgrw217.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/6D/wKioL1fflcvyUr3RAAAO42FsnUI159.png "title=" 29.png "Style=" Float:none; "alt=" Wkiol1fflcvyur3raaao42fsnui159.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/6D/wKioL1fflcujrwYKAAAD_587FlA769.png "title=" 30.png "Style=" Float:none; "alt=" Wkiol1fflcujrwykaaad_587fla769.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/70/wKiom1fflcvBXPlIAAAH3T7ACdE572.png "title=" 31.png "Style=" Float:none; "alt=" Wkiom1fflcvbxpliaaah3t7acde572.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/6D/wKioL1fflczjbHAEAAAHLYFr-zA654.png "title=" 32.png "Style=" Float:none; "alt=" Wkiol1fflczjbhaeaaahlyfr-za654.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/6D/wKioL1fflcyiZHQOAAA3Do2m5Bk410.png "title=" 33.png "Style=" Float:none; "alt=" Wkiol1fflcyizhqoaaa3do2m5bk410.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/6D/wKioL1fflc2zasTYAAADaaspNJY634.png "title=" 34.png "Style=" Float:none; "alt=" Wkiol1fflc2zastyaaadaaspnjy634.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/87/6D/wKioL1fflc3yZ_p5AAB4LAi4X1M990.png "title=" 35.png "Style=" Float:none; "alt=" Wkiol1fflc3yz_p5aab4lai4x1m990.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/6D/wKioL1fflc7iYpN3AABJmDBY0fQ796.png "title=" 36.png "Style=" Float:none; "alt=" Wkiol1fflc7iypn3aabjmdby0fq796.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/70/wKiom1fflc6SSWhtAAAokc9jaRs788.png "title=" 37.png "Style=" Float:none; "alt=" Wkiom1fflc6sswhtaaaokc9jars788.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/6D/wKioL1fflc_izO8eAABUUdb1yS8033.png "title=" 38.png "Style=" Float:none; "alt=" Wkiol1fflc_izo8eaabuudb1ys8033.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/70/wKiom1fflc_w3K2MAAAGj_q0RIo493.png "title=" 39.png "Style=" Float:none; "alt=" Wkiom1fflc_w3k2maaagj_q0rio493.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/6D/wKioL1fflc-AIxefAAAFKWkhEmE449.png "title=" 40.png "Style=" Float:none; "alt=" Wkiol1fflc-aixefaaafkwkheme449.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/6D/wKioL1ffldCSgTr8AAALbURsEH8793.png "title=" 41.png "Style=" Float:none; "alt=" Wkiol1ffldcsgtr8aaalburseh8793.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/70/wKiom1ffldCCr2ehAAAMrMhd-9E078.png "title=" 42.png "Style=" Float:none; "alt=" Wkiom1ffldccr2ehaaamrmhd-9e078.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/6D/wKioL1ffldCidD0jAAAHaqdJsM8631.png "title=" 43.png "Style=" Float:none; "alt=" Wkiol1ffldcidd0jaaahaqdjsm8631.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/70/wKiom1ffldHS7MmEAAAIv6quWkw224.png "title=" 44.png "Style=" Float:none; "alt=" Wkiom1ffldhs7mmeaaaiv6quwkw224.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/6D/wKioL1ffldHgplDiAAAg_j9QFac691.png "title=" 45.png "Style=" Float:none; "alt=" Wkiol1ffldhgpldiaaag_j9qfac691.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/70/wKiom1ffldLxJnxBAABupolqtH8245.png "title=" 46.png "Style=" Float:none; "alt=" Wkiom1ffldlxjnxbaabupolqth8245.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/70/wKiom1ffldKxl2z1AAADLv2uVXE397.png "title=" 47.png "Style=" Float:none; "alt=" Wkiom1ffldkxl2z1aaadlv2uvxe397.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/6D/wKioL1ffldKCnD6SAAAVp-at9hA161.png "title=" 48.png "Style=" Float:none; "alt=" Wkiol1ffldkcnd6saaavp-at9ha161.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/70/wKiom1ffldPwYr9FAAAGcfqvREk943.png "title=" 49.png "Style=" Float:none; "alt=" Wkiom1ffldpwyr9faaagcfqvrek943.png "/>

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/87/6D/wKioL1ffldPit8D3AAAPkMTJBp4265.png "title=" 50.png "Style=" Float:none; "alt=" Wkiol1ffldpit8d3aaapkmtjbp4265.png "/>


Home-made Linux samples

First, prepare an empty disk, where you experiment with a virtual machine's disk


Partitioning and creating file systems

Fdisk/dev/sdb

Divided into two necessary partitions

/DEV/SDB1 corresponding/boot/dev/sdb2 corresponding to the root/

Mkfs.ext4/dev/sdb1

Mount Boot

Mkdir/mnt/boot

Mount/dev/sdb1/mnt/boot

Installing GRUB

Grub-install--root-directory=/mnt/dev/sdb

Recovering kernel and Initramfs files

cp/boot/vmlinuz-2.6.32-642.el6.x86_64/mnt/boot/

Cp/boot/initramfs-2.6.32-642.el6.x86_64.img/mnt/boot

Establish grub.conf:

Vim/mnt/boot/grub.conf

Title Wanglinux

Root (hd0,0)

kernel/vmlinuz-2.6.32-642.el6.x86_64 root=/dev/sda2 selinux=0 Init=/bin/bash

Initrd/initramfs-2.6.32-642.el6.x86_64.img

Chroot/mnt/sysroot

Create a first-level catalog

Mkdir/mnt/sysroot

Mount/dev/sdb2/mnt/sysroot

Mkdir–pv/mnt/sysroot/{etc,lib,lib64,bin,sbin,tmp,var,usr,sys,proc,opt,home,root,boot,dev,mnt,media}

Copy bash and related library files

Copy related commands and related library files

such as: Ls,cat,vim,reboot,hostname, etc.



This article from "~ Breeze ~" blog, declined reprint!

Homemade Linux Temporary Save draft

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.