Tải bản đầy đủ (.pdf) (7 trang)

Topic 7 Linux Kernel

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (537.18 KB, 7 trang )

Topic 7: Linux Kernel
Kernel Components
Compiling a kernel
Patching a kernel
Customise, build and install a custom kernel and kernel modules


1. Kernel module:
Xem version của kernel bằng lệnh:
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27
UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@
Dùng lệnh lsmod để liệt kê các module của kernel:
[root@localhost ~]# lsmod | more
Module
Size Used by
tcp_lp
12663 0
nls_utf8
12557 1
isofs
39844 1
bnep
19704 2
bluetooth
372662 7 bnep
26536 3 bluetooth
rfkill
fuse
87741 3


coretemp
13435 0
crct10dif_pclmul
14289 0
crc32_pclmul
13113 0
crc32c_intel
22079 0
ghash_clmulni_intel 13259 0
aesni_intel
52846 0
lrw
13286 1 aesni_intel
gf128mul
14951 1 lrw
glue_helper
13990 1 aesni_intel
ablk_helper
13597 1 aesni_intel
cryptd
20359 3 ghash_clmulni_intel,aesni_intel,ablk_helper
snd_ens1371
25243 3
snd_rawmidi
30824 1 snd_ens1371
snd_ac97_codec
130476 1 snd_ens1371
12730 1 snd_ac97_codec
ac97_bus
snd_seq

63074 0
snd_seq_device
14497 2 snd_seq,snd_rawmidi
ppdev
17671 0
snd_pcm
103996 2 snd_ac97_codec,snd_ens1371
13415 0
vmw_balloon
serio_raw
13462 0
pcspkr
12718 0
snd_timer
29562 2 snd_pcm,snd_seq
Dùng lệnh modinfo để xem thông tin của một module:
[root@localhost ~]# modinfo ext4
filename:
/lib/modules/3.10.0-229.el7.x86_64/kernel/fs/ext4/ext4.ko
license:
GPL
description: Fourth Extended Filesystem
116

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


author:
Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger,
Theodore Ts'o and others

alias:
fs-ext4
Dùng lệnh insmod để insert thêm một module vào kernel:
[root@localhost ~]# insmod /lib/modules/3.10.0-229.el7.x86_64/kernel/crypto/arc4.ko
Nếu báo lỗi vì module này phụ thuộc vào một module khác chưa được insert. Tìm trong file
/lib/modules/3.10.0-229.el7.x86_64/modules.dep để biết mối quan hệ phụ thuộc.
Dùng lệnh lsmod, liệt kê lại các module:
[root@localhost Desktop]# lsmod | grep arc4
arc4
12608 0
Dùng lệnh rmmod để remove 2 module vừa insert.
# rmmod arc4
Liệt kê module lại để kiểm tra
[root@localhost Desktop]# lsmod | grep arc4
2. Compiling kernel
Cài thư viện :
# yum install gcc ncurses ncurses-devel
- Download source kernel từ trang kernel.org.
- Để biên dịch được kernel, cần cài bộ C compiler. Xem lại phần cài đặt ở bài trước.
- Giải nén gói source:
- Tạo file config. Có thể tạo file config:
o
make config: dạng text file, màn hình hiện ra nhiều câu hỏi, trả lời lần lượt.
o
make menuconfig: dạng đồ họa, (kiểu đồ họa trên DOS), dễ sử dụng hơn.


o

make xconfig hoặc gconfig: giao diện đồ họa.


o
make oldconfig: lấy lại file config cũ.
- Sau khi đã tạo file config, lần lượt thực hiện những lệnh sau để tiến hành biên dịch kernel:
o
make dep: kiểm tra sự phụ thuộc giữa những file C.
118

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


o
o

make clean: dọn dẹp những file biên dịch cũ, có thể đã được tạo ra trong gói source.
make bzImage: tạo kernel image.

o

make modules: biên dịch những module đã chọn lựa.

o

make modules_install: những module đã biên dịch sẽ được đưa vào
/lib/modules/kernel-version.

o

make install: Kernel image và initrd được đưa vào /boot/.



[root@localhost linux-3.2.3]# ll /boot/
total 116292
-rw-r--r--. 1 root root 123838 Mar 6 18:45 config-3.10.0-229.el7.x86_64
drwxr-xr-x 2 root root 1024 Apr 28 15:20 extlinux
drwxr-xr-x. 2 root root 1024 Apr 14 17:17 grub
drwxr-xr-x. 6 root root 1024 Apr 28 16:51 grub2
-rw-r--r--. 1 root root 16496720 Apr 14 17:25 initramfs-3.10.0-229.el7.x86_64.img
-rw-r--r-- 1 root root 16569444 Apr 18 10:24 initramfs-3.10.0-229.el7.x86_64kdump.img
-rw-r--r-- 1 root root 15951823 Apr 28 16:51 initramfs-3.2.3.img
-rwxr-xr-x. 1 root root 5029136 Mar 6 18:45 vmlinuz-3.10.0-229.el7.x86_64
-rw-r--r-- 1 root root 3855312 Apr 28 16:51 vmlinuz-3.2.3
-rw-r--r-- 1 root root 3855312 Apr 28 16:48 vmlinuz-3.2.3.old
o
o

Kiểm tra thư mục /boot đã có kernel image và initrd
Xem file /boot/grub2/grub.conf để kiểm tra một kernel mới đã được thêm vào.

76 menuentry 'CentOS Linux (3.2.3) 7 (Core)' --class rhel fedora --class gnu-linux --class gnu
--class os --unrestricted $men
uentry_id_option 'gnulinux-3.10.0-229.el7.x86_64advanced-92dd65a3-6293-4f7c-ac60-8cc0599cfe87' {
77
load_video
78
set gfxpayload=keep
79
insmod gzio
80
insmod part_msdos

81
insmod ext2
82
set root='hd0,msdos1'
83
if [ x$feature_platform_search_hint = xy ]; then
84
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hintefi=hd0,msdos1 --hint-baremetal=ahci0,msdo
s1 --hint='hd0,msdos1' d1bf360f50b5-459d-92f5-195aa5215f54
85
else
86
search --no-floppy --fs-uuid --set=root d1bf360f-50b5-459d-92f5-195aa5215f54
87
fi
88
linux16 /vmlinuz-3.2.3 root=UUID=92dd65a3-6293-4f7c-ac60-8cc0599cfe87 ro
crashkernel=auto rhgb quiet LANG=en_US.UT
F-8 systemd.debug
89
initrd16 /initramfs-3.2.3.img
90 }

120

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


Menu khởi động


Kiểm tra kernel mới



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×