Kernel compilation and system cropping

Source: Internet
Author: User

Kernel composition:

Kernel module (KO):/lib/modules/version

Core:/boot/vmlinuz-version

Kernel design:

Single Core: Linux uses this but has borrowed the advantages of microkernel

Micro-core

Installed in module command:

Insmod

Modprobe

Download kernel Address: www.kernel.org

Uname-r viewing the kernel version number

###########################################

How user space accesses and monitors the kernel

/proc; /sys pseudo file system, most of their files are read-only

/proc/sys: Many of the files in this directory are readable and writable

/sys/: Some files can be written

such as/PROC/SYS/VM

There are swappiness in this directory to indicate whether to use swap memory

Drop_caches in this file, echo 1 can erase buffers and cached data.

######################

How to set kernel parameters:

Example: Echo 1 >/proc/sys/vm/drop_caches

Free-m can find that the value of buffers and cached is 0

Example: Cat/proc/sys/kernel/hostname has a hostname

echo www.whoami.com >/proc/sys/kernel/hostname can change computer name

###############################################################

Sysctl-w kernel.hostname= "mylab.mageedu.com" can save the directory, and/or replace with.

Sysctl-w Vm.drop_caches=1 can achieve the effect, but must be in the/proc/sys directory

Take effect immediately, but not permanently.

########################################################

To be permanently valid:

Example: There are two network cards on the system, join one NIC Ping not to the destination, we can use another NIC Ping

1, Cat/proc/sys/net/ipv4/ip_forward 0 means that 1 is not enabled

2, vim/etc/sysctl.conf in the seventh row 0 to 1

3, Sysctl-p Notice kernel reread implementation immediately effective and permanent effect

Sysctl-a Show all kernel parameters and their values


Above we should remember the common three kernel parameters Drop_caches;ip_forward;hostname

###################################################################################

Kernel Module Management:

View: lsmod: Lists each module and module name in the current kernel, size, who was called several times

Load: modprobe mod_name implementation in a module

Uninstall: Modprobe-r mod_name Uninstalling a module does not require a path to be specified

View module Details: Modinfo mod_name: (The path of the module is displayed) (sig signature) (Depends: Dependent module) (Description description information)

##############################################

Implementing module loading and unloading there is another set of commands:

Insmod/path/to/somemod: The load module must specify the module path; modeinfo can find the path

Rmmod mod_name: Unload module does not need to specify a path

###############################################

Features in the kernel, in addition to core functionality, have three options at compile time

1. Do not use this function

2. Compile into kernel module

3. Compile into kernel

#############################################

How to manually compile the kernel:

1, directly upgrade to the latest may not be compatible;

2, first to install the compilation environment; development Tools;D Evelopment Libraries

3. Download kernel

4, the kernel source code is generally in the/USR/SRC directory

5. Tar XF linux-2.6.28.tar.gz-c/usr/src extract to this directory

6. Connect the extracted kernel files to Linux

LN-SV linux-2.6.28.10 Linux

7, there are many directories on the Linux directory (arch is a variety of platforms; FS is a variety of file systems; To learn more about Linux you can look at the files in this documenttation; the core of our learning of Linux is learning the kernel)

7.5. Installing GCC and ncurses-devel

8. Open a text menu and edit kernel parameters

Make Menuconfig border is big enough

9. After entering, we take general setup as an example

10, if the * is to do into the kernel, if M is made into a module; If you do not choose to indicate that this feature is not enabled

11. ESC can go back

12. Enter the file system (!!!) Tap SPACEBAR to select * M)

13, save the exit; it is saved to a hidden file in the Linux directory. config

14. Make Compile

########################################################

Most of us are replicating our own kernel to compile: Copy to that directory called. config

1, Cp/boot/config-2.6.18-308.el5/usr/src/linux/.config

2. Make Menuconfig Edit kernel parameters

3. Processor type and features can be configured with dedicated hardware driver

4, can see processor family use is Pentium because to adapt to a variety of CPU

5, if the CPU is core we choose core, if it is AMD choose K6 or K7

6, device Drivers can remove some unwanted equipment driver

"Taken ring token rings; Pcmpia card is very old"

7. Make compile

8. Make Modules_install Install kernel module

9. Make Install

10. Restart the operating system select the new kernel

################################################

Compile kernel do not use remote connection;

If you want to use a screen that can be installed

1. Execute screen will open a new window

2, CTRL + a release after pressing D to remove a process

3. Screen-ls View the screen number that was torn down

4, Screen-r + number can restore the torn down process even if you log in again

################################################

Two compile time how to clean up the original file back up the configuration file first. config

Make clear

Make Mrproper

################################################

Create a set of real Linux

ROOTFS (/sbin/init,/bin/bash), INITRD, kernel, grub

1, create/mnt/sysroot;/mnt/boot;

2. Create bin, sbin, etc, VAR, tmp, Proc, sys, Dev, lib, usr under sysroot

Home

2.5. Add Disk 20G IDE

3. Create two primary partitions one 20M a 512 MB

4, mke2fs-j format multiply ext3

5. Mount the 20M disk to the/mnt/boot 512M disk to/mnt/sysroot

6. Install Grub Grub-install--root-directory=/mnt/dev/hda

7, the kernel vmlinuz .... Copy to/mnt/boot/vmlinuz

8, INITRD small root, is the system start up automatically generated but we do not generate here; so to create manually

9, Red 5: Create INITRD:MKINITRD Red 6:dracup, also support MKINITRD

10,/* "Personal initrd bad can play this way: mkinitrd/boot/initrd-' uname-r '. img ' uname-r '" */

11, here we can not directly create, we have to change the inside; so we have to look at the file type.

12, file/boot/initrd-2.6.18-308.el5.img you will find is gzip

13, we cp out to the root directory, and then MV into. img.gz format

14, gzip-d initrd....img.gz

15, file initrd....img will find that the format has become cpio

16. Create a Directory test: Enter test execution Cpio-id <. /initrd-2.6.18.308.img

17, you can also play, create an empty directory: (with 13-16) zcat/boot/initrd-2.6.18-308.img | Cpio-id

18. We enter the catalogue: VIM Init will have a mkrootdev we change the tail mount point to/dev/hda2

19. Save and exit;

20. Let's pack it back; we'll stand on the test directory: Find. | Cpio-h NEWC--quiet-o | gzip-9 >/mnt/boot/initrd.gz

21. vim/mnt/boot/grub/grub.conf Edit Grub configuration file

22, Default=0

Timeout=5

Title Test Linux (magedu Team)

Root (hd0,0)

Kernel/vmlinuz

Initrd/initrd.gz

23. Create under/mnt/sysroot

mkdir proc Sys Dev etc/rc.d lib bin sbin boot home var/log usr/{bin,sbin} root TMP-PV

24. Copy/sbin/init to cp/sbin/init/mnt/sysroot/sbin/

Copy the/bin/bash. cp/bin/bash/mnt/sysroot/bin/

25. Copy the corresponding library.

Ldd/sbin/init; Cp/lib/libsepol.so.1/mnt/sysroot/lib

Ldd/bin/bash

26. Vim Etc/inittab

Id:3:initdefault:

Si::sysinit:/etc/rc.d/rc.sysinit Save

27, Vim/mnt/sysroot/etc/rc.d/rc.sysinit

#!/bin/bash

Echo-e "\twelcome to \033[31mmageEdu team\033[0m Linux."

/bin/bash

Kernel compilation and system cropping

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.