標籤:linux 核心 kernel
1、查看核心版本
實驗環境
[[email protected] src]#uname -r
2.6.32-358.el6.x86_64
2、安裝圖形依賴包
yum install -y ncurses ncurses-devel
3、下載核心
[[email protected]src]# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.16.2.tar.xz
解壓
[[email protected] src]# tar-xf linux-3.16.2.tar.xz -C /usr/src/
4、編譯安裝
[[email protected] src]# cd/usr/src/linux-3.16.2
[[email protected]linux-3.16.2]# make mrproper
[[email protected]linux-3.16.2]#make menuconfig
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/49/B1/wKioL1QZCAfBFthVAAIBCXcqICE234.jpg" title="未命名圖片.png" alt="wKioL1QZCAfBFthVAAIBCXcqICE234.jpg" />
設定好,儲存並退出。
……
*** End of theconfiguration.
*** Execute ‘make‘to start the build or try ‘make help‘.
[[email protected]linux-3.16.2]# make
……
/bin/sh:bc: command not found
make[1]: ***[kernel/timeconst.h] Error 127
make: *** [kernel]Error 2
報錯:缺少bc
[[email protected] src]# yuminstall -y bc
再次運行
[[email protected]linux-3.16.2]# make
相當於:make dep(建立相依的屬性關聯性),make clean(將舊的資料去除掉),make bzImage(開始編譯核心),makemodules(開始編譯模組)
該過程大概要1、2小時。
報錯:
drivers/tty/serial/built-in.o:final close failed: No space left on device
make[3]: ***[drivers/tty/serial/built-in.o] Error 1
make[2]: ***[drivers/tty/serial] Error 2
make[1]: ***[drivers/tty] Error 2
make: *** [drivers]Error 2
原因是磁碟空間不足,需要清理磁碟或者擴充磁碟
[[email protected]linux-3.16.2]# make modules_install
安裝模組到/lib/modules/,以後程式運行時從這個目錄載入模組。
[[email protected]linux-3.16.2]# make install
安裝核心
把make all產生的vmlinuz和System.map複製到/boot目錄下同時修改grub /boot/grub/menu.lst. 修改menu.lst不用手動修改。
sh./arch/x86/boot/install.sh 3.16.2 arch/x86/boot/bzImage \
System.map"/boot"
ERROR: modinfo:could not find module snd_page_alloc
ERROR: modinfo:could not find module vmware_balloon
報錯
早已載入這兩個模組的:
[[email protected]linux-3.16.2]# lsmod |grep snd_page_alloc
snd_page_alloc 8470 1 snd_pcm
[[email protected]linux-3.16.2]# lsmod |grep vmware_balloon
vmware_balloon 7199 0
查看下grub
[[email protected]linux-3.16.2]# cat /boot/grub/grub.conf
#
# Note that you donot have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths arerelative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version roroot=/dev/mapper/VolGroup-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title RedHat Enterprise Linux Server (3.16.2)
root (hd0,0)
kernel /vmlinuz-3.16.2 ro root=/dev/mapper/VolGroup-lv_rootrd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swapSYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgbquiet
initrd /initramfs-3.16.2.img
title Red HatEnterprise Linux (2.6.32-358.el6.x86_64)
root(hd0,0)
kernel/vmlinuz-2.6.32-358.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKSLANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd/initramfs-2.6.32-358.el6.x86_64.img
已經多了新的內容。那麼之前有兩個報錯的模組我們可以忽略。
那麼修改default=1為default=0
5、重啟
[[email protected] ~]#uname -a
Linux kernel 3.16.2 #1 SMP Wed Sep 17 04:18:19 CST2014 x86_64 x86_64 x86_64 GNU/Linux
編譯成功
關於報錯:
[[email protected]linux-3.16.2]# make modules_install
sh./arch/x86/boot/install.sh 3.16.2 arch/x86/boot/bzImage \
System.map"/boot"
ERROR: modinfo:could not find module snd_page_alloc
ERROR: modinfo:could not find module vmware_balloon
如果你的 CentOS 是安裝在 VMware上的話,在最後 make install 這一步的時候有可能會看到這樣的警告:
ERROR: modinfo: could notfind module vmware_balloon
從字面上來看,是找不到 vmware_balloon模組,這個 vmware_balloon 實際上被稱之為記憶體釋放或者氣球膨脹(參見這篇文章),可能的原因有2個:
首先,確認你的 .config檔案裡面有 CONFIG_VMWARE_BALLOON=m 這一行,或者你可以用 make menuconfig 進去核心編譯菜單,選中 DeviceDrivers -> MISC devices -> VMware Balloon Driver 為 M 或者 *
其次,而這個模組在後面的版本中,已經更名為vmw_balloon,所以 可以用下面的命令來解決:
cd /lib/modules/3.x.xx/kernel/drivers/misc #將版本號碼改成你自己的ln -s vmw_balloon.ko vmware_balloon.ko #建立軟串連
Tips:
如果你最後 make install 的時候有很多could not find module xxxx 的錯誤,而你又不知道其對應的是 .config 中哪一項的時候,可以用這條命令:
grep -R --include=Makefile ‘\bNAME\.o\b‘
以上解決方案來自:http://winotes.net/centos-64-upgrade-to-kernel-3x.html
本文出自 “習慣” 部落格,請務必保留此出處http://xiguanmin.blog.51cto.com/4857855/1553714
linux編譯核心步驟與錯誤解決