想学习linux驱动编程,LDD3说最好自己编内核建立起编译环境,所以编译了一把linux内核,但是内核编出来后,这个内核启动不起来,大概是因为内核的配置没搞好吧。发现用Ubuntu的内核代码路径也可以编驱动程序,所以先折腾到这里吧,今后了解更多东西后再来把内核编译搞搞好。
在Ubuntu 8.04 Desktop建的虚拟机中折腾的
先从kernel.org把内核代码下下来,下的是linux-2.6.38.6
编译步骤:
1. make mrproper
清除原先此目录下残留的.config和.o(object文件)
2. make menuconfig
几个重要的配置
1)文件系统
请务必要选中ext3文件系统
File systems--->
[*] Ext3 journalling file system support
[*] Ext3 Security Labels
[*] JBD (ext3) debugging support
以上三项一定要选上,而且要内建(即标*). 这个非常重要,在配置完后一定要检查一下.config文件有没有"CONFIG_EXT3_FS=y"这一项. 如果不是"CONFIG_EXT3_FS=y"而是"CONFIG_EXT3_FS=m"
2)网卡驱动
请务必把自己网卡对应的驱动编译进内核,比较普遍的网卡是realtek 8139,以下就是这种网卡的配置,以供参考
Device Drivers--->
Networking support--->
Ethernet (10 or 100Mbit) --->
<*> RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL)
<*> RealTek RTL-8139 PCI Fast Ethernet Adapter support
3)声卡驱动
Device Drivers --->
Sound --->
<*> Sound card support
Advanced Linux Sound Architecture --->
<*> Advanced Linux Sound Architecture
<*> Sequencer support
< > Sequencer dummy client
<*> OSS Mixer API
<*> OSS PCM (digital audio) API[*] OSS Sequencer API
<*> RTC Timer support
PCI devices --->
<*> Intel i8x0/MX440, SiS 7012; Ali 5455; NForce Audio; AMD768/8111
Open Sound System --->
< > Open Sound System (DEPRECATED)
3. make bzImage
make modules
make modules_install
make install
这之后/boot下vmlinuz和System.map都会被更新
4. mkinitramfs 2.6.38.6 -o /boot/initrd.img
其中2.6.38.6为/lib/modules下的目录名称
5. 修改/boot/grub/menu.lst的内容
然后重启,重启时,按Esc其实是可以手动选择启动哪一个内核的