查看本机硬件信息:
1、[root@localhost ~]# cat /proc/cpuinfo #显示CPU信息#
2、[root@localhost ~]# lsusb #显示USB接口信息#
3、[root@localhost ~]# lspci
4、[root@localhost ~]# hal-device
编译内核过程:
1、配置,常用命令:
make menuconfig
make gconfig
make kconfig
make oldconfig
make config
2、保存为.config文件
3、make
make modules_install
make install
4、模块安装位置: /lib/modules/KERNEL_VERSION
如何实现部分编译:
1、只编译某子目录下的相关代码:
make dir/
make arch/
make drives/net/
2、只编译部分模块
make M=drives/net/
3、只编译某一个模块
make drives/net/pcnet32.ko
4、将编译完成的结果放置于别的目录中
make o=/tmp/kernel
如何编译busybox:
1.添加一个IDE硬盘并划分两个分区分别挂载到/mnt/boot、/mnt/sysroot
[root@localhost busybox]# mount /dev/hdb1 /mnt/boot
[root@localhost busybox]# mount /dev/hdb2 /mnt/sysroot
2.下载busybox,解压缩文件:[root@localhost ~]#tar xf busybox-1.20.2.tar.bz2
3.配置Busybox ,[root@localhost busybox-1.20.2]# make menuconfig
进入Busybox Settings->Build Options选中Build Busybox as a static binary(no shared libs)(NEW)选项
4.由于Busybox是最新版本与目前使用的系统不一致,导致报错,解决方法:
1)获取最新的linux内核版本
2)解压缩最新的linux内核版本
[root@localhost ~]# xz -d linux-4.14.8.tar.xz
[root@localhost ~]# tar xf linux-4.14.8.tar
3)busybox-1.20.2 中的includ目录下创建一个mtd目录文件
4)将最新linux内核中的ubi-user.h文件拷贝到busybox-1.20.2 的includ目录下的mtd目录文件中;
[root@localhost ~]# cd busybox-1.20.2/
[root@localhost busybox-1.20.2]# cd include/
[root@localhost include]# mkdir mtd
[root@localhost busybox-1.20.2]# cp /root/linux-4.14.8/include/uapi/mtd/ubi-user.h include/mtd
5)编译安装busybox
[root@localhost busybox-1.20.2]# make install
6)创建init文件
[root@localhost busybox-1.20.2]# cp _install /tmp/busybox -a
[root@localhost busybox-1.20.2]# cd /tmp/busybox/
[root@localhost busybox]# ls
bin linuxrc sbin usr
[root@localhost busybox]# rm linuxrc
rm:是否删除 符号链接 “linuxrc”? y
[root@localhost busybox]# mkdir proc sys etc dev sysroot lib/modules -pv
[root@localhost busybox]# ls
bin dev etc lib proc sbin sys sysroot usr
[root@localhost busybox]# modinfo ext3
filename: /lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko
license: GPL
description: Second Extended Filesystem with journaling extensions
author: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others
srcversion: 26DC008FC415305C5F65313
depends: jbd
vermagic: 2.6.18-308.el5 SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1
module_sig: 883f3504f2326dddc995cc0b59af121112b66609f56f4d643dcbbde3384fc7aee2342f5b331f631b09d15ace08361a0e2dfa6ec1ec46718b122bde923
[root@localhost busybox]# modinfo jbd
filename: /lib/modules/2.6.18-308.el5/kernel/fs/jbd/jbd.ko
license: GPL
srcversion: 11842879E04FE2392B988CC
depends:
vermagic: 2.6.18-308.el5 SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1
module_sig: 883f3504f2326dcdc995cc0b59af121112a9509d1d376cb3f07503612b0236e17947cc804b2e6909e3d31e223c8ae8dc3083a2d932d5329bef38115a
[root@localhost busybox]# cp /lib/modules/2.6.18-308.el5/kernel/fs/jbd/jbd.ko lib/modules/
[root@localhost busybox]# cp /lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko lib/modules/
[root@localhost busybox]# mkdir mnt/sysroot -pv
[root@localhost busybox]# mkdir tmp
[root@localhost busybox]# ls
bin dev etc init lib mnt proc sbin sys sysroot usr tmp
[root@localhost busybox]# rm -rf sysroot/
[root@localhost busybox]# ls
bin dev etc init lib mnt proc sbin sys usr tmp
7)创建两个必要的设备文件
[root@localhost busybox]# mknod dev/console c 5 1
[root@localhost busybox]# mknod dev/null c 1 3
[root@localhost busybox]# tree dev/
dev/
|-- console
`-- null
8)编写init脚本
[root@localhost busybox]# vim init
#!/bin/sh
#
mount -t proc proc /proc #挂载/proc 文件系统#
mount -t sysfs sysfs /sys #挂载/sys文件系统#
insmod /lib/modules/jbd.ko
insmod /lib/modules/ext3.ko
mdev -s #探测额外硬件#
mount -t ext3 /dev/hda2 /mnt/sysroot #挂载根文件系统#
exec switch_root /mnt/sysroot /sbin/init #切换虚根到真正的根文件系统上#
[root@localhost busybox]# chmod +x init
[root@localhost busybox]# find . | cpio -H newc --quiet -o | gzip -9 > /mnt/boot/initrd.gz
[root@localhost busybox]# ls -lh /mnt/boot/initrd.gz
-rw-r--r-- 1 root root 951K 12-23 11:48 /mnt/boot/initrd.gz
9)准备内核
[root@localhost busybox]# cp /boot/vmlinuz-2.6.18-308.el5 /mnt/boot/vmlinuz
10)安装grub
[root@localhost busybox]# grub-install --root-directory=/mnt /dev/hdb
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mnt/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdb
(hd2) /dev/sda
[root@localhost busybox]# ls /mnt/boot
grub lost+found vmlinuz
10)编写grub配置文件
[root@localhost busybox]# vim /mnt/boot/grub/grub.conf
default=0
timeout=3
title MageEdu Linux (2.6.18)
root (hd0,0)
kernel /vmlinuz ro root=/dev/hda2
initrd /initrd.gz
11)准备sysroot
[root@localhost busybox-1.20.2]# cp _install/* /mnt/sysroot/ -a
[root@localhost busybox-1.20.2]# cd /mnt/sysroot/
[root@localhost sysroot]# ls
bin linuxrc lost+found sbin usr
[root@localhost sysroot]# rm linuxrc
rm:是否删除 符号链接 “linuxrc”? y
[root@localhost sysroot]# mkdir proc sys dev tmp var/{log,lock,run} lib/modules etc/rc.d/init.d root boot mnt media -pv
[root@localhost sysroot]# vim etc/inittab
::sysinit:/etc/rc.d/rc.sysinit
console::respawn:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
[root@localhost sysroot]# vim etc/fstab
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/hda1 /boot ext3 defaults 0 0
/dev/hda2 / ext3 defaults 1 1
[root@localhost sysroot]# sync
[root@localhost sysroot]# mknod dev/console c 5 1
[root@localhost sysroot]# mknod dev/null c 1 3
[root@localhost sysroot]# vim etc/rc.d/rc.sysinit
#!/bin/sh
echo -e "\tWelcome to \033[31mMageEdu\033[0m Linux"
echo -e "Remounting the root filesystem ...[ \033[32mOK\033[0m ]"
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -o remount,rw /
echo -e "Creating the files of device ...[ \033[32mOK\033[0m ]"
mdev -s
echo -e "Mounting the filesystem ...[ \033[32mOK\033[0m ]"
mount -a
swapon -a
[root@localhost sysroot]# chmod +x etc/rc.d/rc.sysinit
阅读(2042) | 评论(0) | 转发(0) |