怎样编译ubuntu的内核

原文:https://blog.csdn.net/CaspianSea/article/details/43014525

方法一:

1. Use apt-get source to download the Ubuntu version of the kernel

apt-get source linux-image-$(uname -r)

gives a folder that contains, for example:

linux-3.2.0                linux_3.2.0-26.41.dsc
linux_3.2.0-26.41.diff.gz  linux_3.2.0.orig.tar.gz

The bolded diff includes all the Ubuntu/Debian customizations.

2. To build a stock kernel with your own .config, use the “old-fashioned” Debian make-kpkg method

sudo apt-get install kernel-package

If you are compiling a kernel for the first time:

sudo apt-get build-dep linux-image-$(uname -r)

Then cd into the source directory (here, linux-3.2.0), and either run make oldconfig to create .config file with your running kernel’s configuration, or copy a third-part .config to this directory.
Depending on whether you want a text or graphical config, install:
(Text)

sudo apt-get install libncurses5 libncurses5-dev

(Graphical)

sudo apt-get install qt3-dev-tools libqt3-mt-dev

And then run:
(Text)

make menuconfig

(Graphical)

make xconfig

When done, just run

make-kpkg
make-kpkg -j N --initrd --append-to-version=my-very-own-kernel kernel-image kernel-headers

where N is how many jobs to run in parallel (usually the number of CPUs you have), and my-very-own-kernel is a custom string to identify this build.
When done, the kernel image and header files will be ready as debs in the parent directory; you can simply install them with sudo dpkg -i, which will also take care of adding GRUB entries, etc.

方法二:

1. download kernel code(linux.3.16.1.tar.xz), untar the file, then run

make; make modules;

2. install the modules by running:

sudo make modules_install

Install the kernel itself by:

sudo make install

That puts vmlinuz-3.16.1 (a copy of vmlinuz), config-3.16.1 (a text file storing kernel configuration parameters), and System.map-3.16.1 (the kernel symbol lookup table) in /boot. For more details, see this comp.os.linux.misc post by Hadron and man installkernel.

Final setup, so the kernel can be started and boot the system:
This section is partly based on information in Kernel/Compile.

With the kernel now where it needs to be, it needs:

an entry in the boot loader’s configuration, so you can select and boot from it.

an initial RAM filesystem, the environment from which the kernel loads drivers and mounts the / filesystem.

(If you’re installing an old kernel or have configured your kernel to use devfs instead of the newer udev, you may need or wish to set up an initial ramdisk instead. If you know you need that instead, see man initrd.)

Generate your initramfs with mkinitramfs:

cd /boot
sudo mkinitramfs -ko initrd.img-3.16.1 3.16.1

or:

sudo update-initramfs -u -k 3.16.1
or:
sudo update-initramfs -c -k 3.0.0

When you update the configuration of the GRUB2 boot loader–which has been the default in Ubuntu since 9.10–should automatically detect the new kernel and add an option to boot from it.

sudo update-grub

It could be possible that the create initrd.img is very large (over 100MB), and the boot partiiton maybe don’t have enough free space. In this case, apply the strip parameter when installing modules:
make INSTALL_MOD_STRIP=1 modules_install
Similarly, for building the deb packages:

make INSTALL_MOD_STRIP=1 deb-pkg
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值