https://blog.csdn.net/yejingx/article/details/6525405
一. 最小系统要求
1. 接受键盘输入,能显示字符信息
2. 能处理普通linux发行版中的大部分基本命令,如:ls, mv...
3. 具有网络功能
4. 不使用ramdisk, 所需驱动全部编译进内核
二. 主机环境
1. VMware 7.0 / windows 7
2. 主机系统Ubuntu 10.04 x86 (kernel version 2.6.32)
3. 最小系统内核版本 linux-2.6.38
三. 详细构建过程
1. 下载linux-2.6.38内核
[c-sharp] view plain copy
#cd /usr/src
#wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.tar.gz
#tar xvf linux-2.6.38.tar.gz
#cd linux-2.6.38
2.编译内核
这一步主要就是内核的配置,如果配置错了可能导致系统无法启动,因此需要非常仔细。
[c-sharp] view plain copy
#make mrproper
#make allnoconfig
#make menuconfig
首先利用lspci查看硬件信息:
[c-sharp] view plain copy
#lspci
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
................... ......................... .......................
00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
02:00.0 USB Controller: Intel Corporation 82371AB/EB/MB PIIX4 USB
02:01.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)
02:02.0 Multimedia audio controller: Ensoniq ES1371 [AudioPCI-97] (rev 02)
02:03.0 USB Controller: VMware USB2 EHCI Controller
根据查到的硬件型号配置.config文件
以下详细介绍内核的配置(除以下选项外其它都可以不选)
General setup --->
[*] System V IPC
[*] Enable loadable module support --->
Processor type and features --->
Processor family (Pentium Pro) --->
[*] Generuc x86 support
Bus options (PCI etc.) --->
[*] PCI support
PCI access mode (Any) --->
Executable file formats / Emulations --->
[*] Kernel support for ELF binaries
[*] Write ELF core dumps with partial segments
[*] Networking support --->
Networking options --->
<*> Packet socket
<*> Unix domain sockets (NEW)
[*] TCP/IP networking
<*> IP: IPsec transport mode (NEW)
<*> IP: IPsec tunnel mode (NEW)
<*> IP: IPsec BEET mode (NEW)
<*> Large Receive Offload (ipv4/tcp) (NEW)
<*> INET: socket monitoring interface (NEW)
Device Drivers --->
[*] Block devices --->
<*> Loopback device support
SCSI device support --->
<*> SCSI device support
[*] legacy /proc/scsi/ support (NEW)
<*> SCSI disk support
[*] SCSI low-level drivers (NEW) --->
<*> BusLogic SCSI support
[*] Fusion MPT device support --->
<*> Fusion MPT ScsiHost drivers for SPI
<*> Fusion MPT ScsiHost drivers for FC
<*> Fusion MPT ScsiHost drivers for SAS
<*> Fusion MPT misc device (ioctl) driver
[*] Network device support --->
[*] Ethernet (10 or 100Mbit) --->
[*] EISA, VLB, PCI and on board controllers
<*> AMD PCnet32 PCI support
Graphics support --->
<*> Support for frame buffer devices --->
File systems --->
<*> Second extended fs support
[*] Ext2 extended attributes
[*] Ext2 POSIX Access Control Lists
[*] Ext2 Security Labels
[*] Ext2 execute in place support
<*> Ext3 journalling file system support
[*] Default to 'data=ordered' in ext3 (NEW)
[*] Ext3 extended attributes (NEW)
[*] Ext3 POSIX Access Control Lists
[*] Ext3 Security Labels
CD-ROM/DVD Filesystems --->
<*> ISO 9660 CDROM file system support
<*> Native language support --->
<*> Codepage 437 (United States, Canada)
<*> Simplified Chinese charset (CP936, GB2312)
配置完成后就可以开始编译了:
[c-sharp] view plain copy
#make bzImage
注意:在make menuconfig的时候一定要选对磁盘驱动,否则会出现
kernel panic -- VFS error: unable to mount …
这里我用的是SCSI的磁盘,IDE的要做相应修改。
3. 制作根文件系统
为简单起见,我们利用busybox制用根文件系统。
[c-sharp] view plain copy
#wget http://busybox.net/downloads/busybox-1.18.4.tar.bz2
#tar xvf busybox-1.18.4.tar.bz2
#cd busybox-1.18.4
#make menuconfig
下面是需要编译进busybox的功能选项。
General Configuration应该选的选项
Don't use /usr
这个选项一定要选,否则make install 后busybox将安装在原系统的/usr下,这将覆盖掉系统原有的命令。
Build Options
Build BusyBox as a static binary (no shared libs)
这个选项也是一定要选择的,这样才能把busybox编译成静态链接的可执行文件,运行时才独立于其他函数库.否则必需要其他库文件才能运行,在单一个linux内核不能使它正常工作。
其它选项都是一些linux基本命令选项,自己需要哪些命令就编译进去,一般用默认的就可以了,配置好后退出并保存。
编译并安装busybox
[c-sharp] view plain copy
#make
#make install
make install后会在busybox目录下生成一个叫_install的目录,里面有busybox和指向它的链接。
接下来给虚拟机添加一块SCSI磁盘并分区,假设根分区为sdb1
[c-sharp] view plain copy
#mount /dev/sdb1 /mnt 将根分区挂载到/mnt
#cp _install/* /mnt/ 将_install下的文件全复制到sdb1
#rm -f linuxrc
#cp -r ./examples/bootfloppy/etc /mnt 将etc下的配置文件拷到sdb1下
#cd /mnt/
#mkdir proc mnt usr var tmp dev sys 创建目录
#cp -a /dev/{console,tty,tty2} dev/
4. 更新grub
这步既可以在ubuntu的grub中引导也可以在sdb上装上grub,从sdb1进行引导。
为简单起见我们就用ubuntu中的grub来引导。
修改/boot/grub/grub.cfg
[c-sharp] view plain copy
#gedit /boot/grub/grub.cfg
新添加
menuentry "My Linux-2.6.38" {
insmod ext2
set root='(hd1,1)'
linux /bzImage ro root=/dev/sdb1
}
5. 最后重启一下(启动时按住shift,否则不进入grub2引导菜单)
[c-sharp] view plain copy
#reboot
选择My Linux-2.6.38
如果一切顺利,就会出现下图的信息, ----- 启动成功。
---------------------
作者:yejingx
来源:CSDN
原文:https://blog.csdn.net/yejingx/article/details/6525405
版权声明:本文为博主原创文章,转载请附上博文链接!
网友评论