linux-compiling kernel and kernel module operations

Source: Internet
Author: User

• Source code to compile the Linux kernel
• Using the Linux kernel module
• Actual combat-compile an NTFS kernel module to implement Linux mount NTFS file system and read and write functions

Upgrade the kernel two ways:
1:rpm
Yum
RPM-IVH cannot overwrite old kernel directly with UVH u update
Automatically start the new kernel as default
2:src

Precautions:
Make sure you have more than 7G of free disk space before installation, or you will not be able to install it because of insufficient space.
。 In addition, to speed up the installation, the virtual machine memory to adjust to more than 2.5G (the larger the better)

To perform the steps:
1, to www.kernel.org download the corresponding kernel source package
2, confirm that your system already has the basic conditions of compiling software, that is to install make, GCC, gcc-c++, ncurses-devel and library tools and so on. Development tools and libraries
3, decompression kernel source package
4. Configuring kernel compilation Parameters
5. Compile the kernel
6, install the compiled kernel and module
7. View or modify the Grub menu (to make sure you've actually installed the kernel)
8. Restart the system to test the new kernel's performance

Here's a look at how to recompile the kernel on RHEL6
1: Add a new hard drive 20G, and partition mount
[Email protected] ~]# Fdisk/dev/sdb
Mkfs.ext4/dev/sdb1
[Email protected] ~]# MOUNT/DEV/SDB1/SDB1
2: Download the kernel and install the build environment.
Compiling the environment
Make, GCC, gcc-c++, ncurses-devel, and library tools, and more
3: Unzip the kernel compression pack
[Email protected] sdb1]# tar XF tar-xf linux-3.10.75.tar.xz
xz-d TAR-XF Linux-3.10.75.tar.xz
#-d,--decompress Force decompression (Di:k?m?pres extract)

[Email protected] sdb1]# du-sh tar-xf linux-3.10.75.tar.xz

The Linux kernel is now very complex, and there is no one inside the back door, no one knows

4: Configure kernel compilation parameters, generate kernel parameter configuration file:. config
Copy system's own kernel configuration to the new kernel (the system comes with a red hat optimized configuration)
[Email protected] linux-3.10.75]# Cp/boot/config-2.6.32-431.el6.x86_64/sdb1/linux-3.10.75/.config

Cp:overwrite '/sdb1/linux-3.16.2/.config '? Y

[email protected] linux-3.10.75]# make Menuconfig
Configure kernel, FILE system-->dos/fat/ntfs-->ntfs kernel enable NTFS
Select "File System" and press ENTER
Select NTFS file system support carriage return, and then move the cursor down to: NTFS write

How to see if the kernel is NTFS enabled
See NTFS-related content in a configuration file
[[email protected] linux-3.10.75]# vim. config #搜索 NTFS
Config_ntfs_fs=m
# Config_ntfs_debug is not set
Config_ntfs_rw=y


5: Compile Kernel
[[email protected] linux-3.10.75]# make Bzimage #生成内核, this kernel is a compressed kernel
Setup is 15516 bytes (padded to 15872 bytes).
System is 4392 KB
CRC 5be44720
Kernel:arch/x86/boot/bzimage is ready (#1)
Success

6, the following generation of the new kernel driver module:
[email protected] linux-3.10.75]# make modules

Long wait ah, longer than the compilation of the kernel

7, install the compiled kernel and module
(1) Mounting module
[email protected] linux-3.10.75]# make Modules_install
It also takes a while, this step is to copy the compiled modules into the/lib/modules/corresponding kernel directory
Countless bytes are omitted here

............
Install/lib/firmware/keyspan_pda/xircom_pgs.fw
Depmod 3.10.75


(2) Install the newly compiled system kernel
[[email protected] linux-3.10.75]# make install


Some errors can be skipped
ERROR:modinfo:could not find module Vmhgfs
ERROR:modinfo:could not find module Vsock
ERROR:modinfo:could not find module Vmware_balloon
ERROR:modinfo:could not find module VMCI
There are ways to solve this.
You can use make menuconfig to go inside the kernel compile menu, select Device Drivers, MISC devices, VMware Balloon Driver to M or *
Second, and this module in the later version, has been renamed to Vmw_balloon, so you can use the following command to solve:
Cd/lib/modules/3.x.xx/kernel/drivers/misc #将版本号改成你自己的
Ln-s Vmw_balloon.ko Vmware_balloon.ko #建立软连接


8. View or modify the Grub menu (to make sure you've actually installed the kernel)
[Email protected] linux-3.10.75]# vim/boot/grub/grub.conf
Title Red Hat Enterprise Linux Server (3.10.75)
I found a few more inside.
Can be modified default=0, equal to 1 or the previous kernel

9. Restart the system to test the new kernel's performance
Note that in the start, you need to come in to choose, otherwise the default or the previous kernel boot Oh. Unless you change the default startup item in the previous step.
After booting the system with the new kernel, view the kernel version:
[Email protected] ~]# uname-r
3.10.75
This compiles the installation kernel to be OK

————————————————————————————————————————————————————————————————————————————————————————————————————————
Kernel---operating system--software

Kernel module Operation:
The function of a module: A program that encapsulates a specific function.
The target path of the kernel module is stored:
[Email protected] ~]# ls/lib/modules/
2.6.32-431.el6.x86_64 3.10.75
[Email protected] ~]# Ls/lib/modules/2.6.32-431.el6.x86_64/kernel/fs/fat
Fat.ko Msdos.ko Vfat.ko

Insmod: Inserting modules
[Email protected] fat]# Insmod Fat.ko

Lsmod: List current system modules, view current system loaded modules
[Email protected] fat]# Lsmod | grep fat
Fat 58310 0

RMMOD: Deleting a module
[Email protected] fat]# rmmod fat

Depmod: Analyze the dependencies of loadable modules, load the Delete module to let the system know, equivalent to refresh
Resolving dependencies for loading and deleting modules
[[email protected] fat]# depmod # processing dependencies (must be manipulated after inserting the delete module)
Note: Depmod updates the configuration file, which is the
[Email protected] fat]# VIM/LIB/MODULES/3.10.75/MODULES.DEP
Open File search related modules can see the dependencies between them and the module path

Modinfo: Viewing module information
[Email protected] fat]# modinfo fat
FileName:/lib/modules/3.10.75/kernel/fs/fat/fat.ko
License:gpl
Srcversion:5e42099824e463d8af16eed
Depends
Intree:y
vermagic:3.10.75 SMP mod_unload modversions

Modprobe: Insert Module (can automatically resolve dependencies between modules, like Yum can automatically resolve dependencies between RPMs)
[Email protected] fat]# insmod Vfat.ko #no
Insmod:error inserting ' Vfat.ko ':-1 Unknown symbol in module

[Email protected] fat]# modprobe vfat #ok

[Email protected] fat]# modprobe Vfat.ko #no
Fatal:module Vfat.ko not found.

-r:modprobe-r and Rmmod, deleting a module does not automatically resolve dependency removal
[Email protected] fat]# modprobe-r VFAT
[Email protected] fat]# modprobe-r fat

Automatically load a module on boot
[Email protected] fat]# vim/etc/rc.local
Add content: Modprobe fat
can also be automatically mounted on the boot
Mount/dev/sdb1/sdb1

____________________________________________________________________________

Actual combat-Compile an NTFS kernel module to implement Linux mounted NTFS file system

To install fuse:
[Email protected] fuse-2.8.3]#./configure
[[email protected] fuse-2.8.3]# make && make install



Installation: ntfs-3g:
[Email protected]pagoda63 ntfs-3g-2011.1.15]#./configure
[[email protected] ntfs-3g-2011.1.15]# make && make install

Mount:
Insert an NTFS removable hard disk and import the removable hard drive into the virtual machine
[Email protected] hgfs]# Mount/dev/sdc/mnt/media
Automatic mount on Boot:
[Email protected] media]# Vim/etc/fstab
/dev/sdc/mnt/media ntfs-3g Defaults 0 0



linux-compiling kernel and kernel module operations

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.