xuanhao 发表于 2018-5-9 07:50:22

ubuntu10.10编译内核3.0.1

  学习linux也有一段时间了,感觉是渐渐上手了。最开始是想看看驱动的自动加载(参考网上的内核代码树编译之类的文章,都是insmod手动加载驱动),然后我就很想知道类似wince的驱动是如何加载到系统中去的呢?
  所以决定深入的了解一下内核的编译以及更新。当然这些也被前辈们做烂了,但是对于自己还是一个新东西。简单的列一下具体步骤,原则是你按照我的文章基本上就可以重复我的工作。
  前提条件:windows系统安装vmware虚拟机,在安装ubuntu10.10,安装vmware-tools vim fictx。sudoapt-get install build-esstial防止编译出问题。
  1.下载内核代码:linux-3.0.1.tar.bz2
  2.解压到任何目录,这里是/opt/linux_kernel.
  3.cp /usr/src/linux-headers-2.6.35.-22-generic/.config /opt/linux_kernel/linux-3.0.1
  4.cd /opt/linux_kernel/linux-3.0.1
  5.我们添加了hello.c文件到/opt/linux_kernel/linux-3.0.1/drivers/char下面,修改Kconfig Makefile.内容如下:
  //hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(&quot;Dual BSD/GPL&quot;);
  static int hello_init(void)
{
printk(KERN_ALERT &quot;Hello, world/n&quot;);
return 0;
}
  static void hello_exit(void)
{
printk(KERN_ALERT&quot;Goodbye, cruel world/n&quot;);
}
  module_init(hello_init);
module_exit(hello_exit);
  Kconfig中添加
  config TE_HELLO
  bool &quot;this is a test for virtual device support&quot;
  default y
  help
  say Y there if you want to support the test.
  Makefile中添加:
  obj -$(CONFIG_TE_HELLO)   +=hello.o
  6.make menuconfig直接load在save即可。注意看看添加的hello是选中了。
  7.make大概3小时在源代码处生成相应的.o文件
  make bzImage 在/arch/x86/boot生成bzimage
  make modules 编译modules
  make modules_install 将上面编译好的模块都拷贝到/lib/modules/3.0.1下面
  make install拷贝System-wap-3.0.1 vmlinuz-3.0.1到/boot/目录下
  8.生成initrd.img这里注意网上有使用sudo mkinitramfs -o /boot/initrd.img-3.0.1,它会引起 could not load .../modules.dep的问题。
  使用sudo update-initramfs -c -k 3.0.1才正确。
  sudo update-grub出现下列信息表示正确了。
  Found linux image: /boot/vmlinuz-3.0.1
  Found linux image: /boot/initrd.img-3.0.1
  9.reboot系统,是否有hello的信息出现,有的话那就说明正确了。
  这里我们实现了linux驱动添加到linux内核,linux内核的更新。当然对于每一步为什么这么做我们还没有深究。
页: [1]
查看完整版本: ubuntu10.10编译内核3.0.1