我該如何編譯核心?
(這份操作說明假定我們正安裝的是2.6.0核心版本, 以你正在試著建構的版本取代所有的實例. 這些操作說明同樣也是x86特有; 其它架構的建構程序可能有所不同.)
- 從http://kernel.org首頁下載最新版本的壓縮檔. 如果你正使用FTP, 前往 ftp.kernel.org/pub/linux/kernel/[版本] -- 這些次目錄全部包含一個名為LATEST_IS_[版本]空白檔幫你找到最新的版本. kernel.org有幾乎完整到0.99版的核心檔案室如果你真的想冒險看看.
- 解開壓縮檔到家目錄. 如果你正打算大量編譯和安裝核心(和其它的好東西), 你可能想要閱讀此頁底下/usr/src的註記.
- tar xivf linux-2.6.0.tar.bz2
- (Replace xivf with xzvf if you downloaded the .gz)
- 改變路徑到Linux目錄底下. 現在你將需要設定核心選擇你想要的功能. 有數種方式可以達成 ..
- make config
- o 條列命令式問題.
- make oldconfig
- o (只有在保有從前一版核心建構的.config檔時有用. With the newest kernels, the .config of the currently-running kernel is used by default if it's available, so you usually won't need this feature.)
- make menuconfig
- o
- (ncurses based)
- o
- make menuconfig
- make gconfig
- o
- (GTK+ based X-Windows configuration)
- o
- make gconfig
- make xconfig
- o
- (QT based X-Windows configuration)
- o
- make xconfig
- make config
- Now we can build the kernel (for older kernel like 2.4.x first build the dependencies with "make dep").
- make
- Now we can build the kernel (for older kernel like 2.4.x first build the dependencies with "make dep").
- Wait. When its finished, it will have built both the kernel (bzImage) and the modules (for older kernels like 2.4.x, you need to run "make bzImage ; make modules").
- Become root to be able to install modules and kernel. Everything before this point can and should be done as a normal user, there is really no need to be root to compile a kernel. It's actually a very bad idea to do everything as root because root is too powerful, one single mistake is enough to ruin your system completely.
- Install the modules.
- make modules_install
- Install the modules.
- Install the new kernel..
- make install
- Install the new kernel..
If your distribution uses lilo:
- Edit /etc/lilo.conf, and add these lines...
- image = /boot/vmlinuz-2.6.0 label = 2.6.0
- Edit /etc/lilo.conf, and add these lines...
- Also copy your root=/dev/??? line here too.
- Run /sbin/lilo, reboot, and enjoy.
If your distribution uses grub:
- Edit /boot/grub/grub.conf:
- title=Linux 2.6.0 root (hd0,1) # or whatever your current root is kernel /boot/vmlinuz-2.6.0 root=/dev/hda1 # or whatever...
- Edit /boot/grub/grub.conf:
- If you're using Ubuntu, you will need to edit menu.lst instead of grub.conf
- If your menu.lst needs an initrd line, you can generate the necessary info by doing something like
- o
- update-initramfs -k 2.6.29.3 -c
- update-initramfs seems to be the replacement for mkinitrd (which is mentioned in the "more indepth tutorial" mentioned below.
- o
- If your menu.lst needs an initrd line, you can generate the necessary info by doing something like
- Most distributions have an installation routine that links a new /boot/vmlinuz-[version] to simply vmlinuz, so you may want to add a stanza like this to grub.conf:
- title=My very latest kernel install root (hd0,1) # or whatever your current root is kernel /boot/vmlinuz root=/dev/hda1 # or whatever...
- Most distributions have an installation routine that links a new /boot/vmlinuz-[version] to simply vmlinuz, so you may want to add a stanza like this to grub.conf:
- This will let you boot fresh kernels for testing without constantly editing grub.conf.
Note: This will work for lilo, too, but you still have to run /sbin/lilo after every install.
If you get modversion problems (symbols ending in _Rxxxxxxxx), have a look at this question in the linux-kernel mailing list FAQ to solve the problem.
Still not getting it? Try this more indepth tutorial
- Note on /usr/src
If you're just trying out this procedure, do the unpacking and building in your home directory as discussed above. In a professional environment, though, the source would be stored in /usr/src or /usr/local/src, where compiling would also be done. To allow this, and at the same time avoid becoming root for the entire procedure, use your favorite GNOME or KDE utilities to create a group "devel" (or "hack" or whatever) and add yourself to that group. Then change the group owner of /usr/src to the new group and grant write privileges to the group.
That way you can unpack the kernel tarball into /usr/src (or whatever) and configure and build there without doing everything as root. Of course, you'll still need to sudo or become root when you install the new kernel and edit the lilo/grub configuration files.
This will help keep the kernel source separate from your resume, diary, and jpegs of your Main Squeeze.
- CategoryFAQ
CategoryFAQ