现在的位置: 首页 > 综合 > 正文

Linux编译内核实验小结

2018年03月18日 ⁄ 综合 ⁄ 共 2377字 ⁄ 字号 评论关闭

近日按照《Linux内核的设计与实现》尝试编译内核,遇到很多问题,也学到不少经验。

 

1.  由于需要使用一个较老版本的内核,而后从别人处拷贝的tag.bz2是损坏的。原先并没有在http://www.kernel.org/看到所需要的内核,通过搜索知道较旧的内核可以从类似于http://www.kernel.org/pub/linux/kernel/v2.6/命名规则的页面下载。

2.  如果已经安装Win7且磁盘系统转换为NTFS,用EasyBCD硬盘安装Win7+Ubuntu双系统不可行

3.  2.6.13内核需要2.95.3版本的gcc

4.  练习内核编译时,可以使用比系统自带内核稍微新一些的,比如Ubuntu自带2.6.32.21,下载2.6.32.24进行练习比较简单。内核编译涉及的诸如gcc等程序的版本,过老的内核可能在新版gcc下无法编译通过。

5.  make config、make、make modules_install、make install后可能需要对grub进行配置:

 

  a.把源码根目录下System.map拷贝至/boot下并改名为System.map-2.6.32.24;

  b.把源码目录下arch/x86/boot/bzImage拷贝到/boot目录下;

  c.使用bzImage生成img文件initrd.img-2.6.32.24:

      update-initramfs -c -k 2.6.32.24

  d.把bzImage改名为vmlinuz-2.6.32.24;

  e.修改/boot/grub/grub.cfg,添加类似于下面的内容:

menuentry 'Ubuntu, with Linux 2.6.32-22' --class ubuntu --class gnu-linux --class gnu --class os {

   recordfail

   insmod ext2

   set root='(hd0,4)'

   search --no-floppy --fs-uuid --set b8fe4b7e-9135-4d33-a1bc-ff7590acdf2f

   linux /boot/vmlinuz-2.6.32.24 root=UUID=b8fe4b7e-9135-4d33-a1bc-ff7590acdf2f ro   quiet splash

   initrd   /boot/initrd.img-2.6.32.24

}

6.  重启后选择该内核,在终端中输入uname -a 查看内核版本。

7.  修改启动顺序的方法(来自于一个帖子

  grub2之前的,在/boot/grub/menu.lst或者grub.conf里面修改。把windows那块放在前面即可;

  grub2:把/etc/grub.d/目录下的os-prober前面的数字改小一些,小到比linux还小一级就行了。再update-grub,一劳永逸,以后升级也不怕了。

8.  附:在VMware Workstation中使用Red Hat 9.0进行2.4升级2.6.13的一些注意事项

(这部分内容主要来自于http://blog.csdn.net/lovesid/article/details/4652300http://blog.csdn.net/mlite/article/details/697455,已经写入实验报告中)

make menuconfig需要进行以下修改:

Device Drivers->SCSI device support-><*>SCSI device support

Device Drivers->SCSI device support-><*>SCSI disk support

Device Drivers->SCSI device support->SCSI low-level drivers-><*>BusLogic SCSI support

File systems-><*>Ext3 journalling file system support

File systems->[*]Ext3 Security Labels

File systems->[*]JBD (ext3) debugging support

Device Drivers->Network device support->Ethernet (10 or 100Mbit)-><*>AMD PCnet32 PCI support

Device Drivers->ATA/ATAPI/MFM/RLL support-><*>Include IDE/ATAPI CDROM support

 

make install的时候可能会出现如下错误信息:

No module BusLogic found for kernel 2.4.20

mkinitrd failed

 

解决方法:

把 /sbin/mkinitrd中

for n in $scsimodules; do

# for now allow scsi modules to come from anywhere. There are some

# RAID controllers with drivers in block/

findmodule $n

done

修改为

#for n in $scsimodules; do

# for now allow scsi modules to come from anywhere. There are some

# RAID controllers with drivers in block/

#findmodule $n

# done

  另外,在Red Hat9.0中安装VMTools时,不要更改gcc路径,屏幕分辨率选择安装Red Hat时选择的大小,否则容易出错。

9.  从Windows复制到虚拟机的Linux的代码可能总提示语法错误(即使没有),这时dos2unix filename也许能帮上忙。(写脚本程序时遇到的问题)

抱歉!评论已关闭.