Linux内核编译测试


内核编译:

Step 1:配置内核编译选项。

make menuconfig

Optional Step :排除编译结果文件(.o)等之间的依赖性。

make mrproper

Optional Step:清除历史编译结果。

make clean

Step 2:编译内核。

make bzImage #编译内核

make modules #编译各内核模块,如驱动等。

make modules_install #将编译好的模块安装至 /lib/modules/x.xx.x 目录下。

Step 3:生成初始盘镜像 initrd.img。


cd linux-source-x.xx.x/.config #复制配置文件至/boot目录

sudo cp .config /boot/config-x.xx.x

#x.xx.x 对应 /lib/modules/x.xx.x 目录。

# -o 指示了镜像的输出目录。

sudo mkinitramfs -o /boot/initrd.img-x.xx.x x.xx.x 

Step 4:修改Grub配置。

在/boot/grub/grub.cfg中复制一段已有的启动项条目,将其中的内核相关文件地址修改至新内核相关文件所在位置。

如:

复制下段:

menuentry'Ubuntu,Linux 3.2.0-36-generic-pae' --class ubuntu --class gnu-linux --class gnu --class os {

        recordfail

        gfxmode $linux_gfx_mode

        insmod gzio

        insmod part_msdos

        insmod ext2

        set root='(hd0,msdos1)'

        search --no-floppy --fs-uuid --set=root 7b4e922c-d943-4b84-9c75-4fdc57cf1a3f

        linux   /boot/vmlinuz-3.2.0-36-generic-pae root=UUID=7b4e922c-d943-4b84-9c75-4fdc57cf1a3f ro   quiet splash $vt_handoff

        initrd  /boot/initrd.img-3.2.0-36-generic-pae

}

修改为:

menuentry 'Test,Linux 3.7.4' --class ubuntu --class gnu-linux --class gnu --class os {

        recordfail

        gfxmode $linux_gfx_mode

        insmod gzio

        insmod part_msdos

        insmod ext2

        set root='(hd0,msdos1)'

        search --no-floppy --fs-uuid --set=root 7b4e922c-d943-4b84-9c75-4fdc57cf1a3f

        linux  /boot/core/vmlinuz-3.7.4root=UUID=7b4e922c-d943-4b84-9c75-4fdc57cf1a3f  ro   quiet splash $vt_handoff

        initrd  /boot/core/initrd.img-3.7.4

}

Step 5:测试

在虚拟机启动时按Esc,强制进入Grub启动菜单。

在菜单中选择’Test,Linux 3.7.4,使用刚编译的内核初始化系统,查看启动过程,看是否存在异常,如一切正常,则表明内核编译正确,反之则需要继续修改编译选项。

相关内容