Linux換源+編譯核心總結,linux編譯核心總結

來源:互聯網
上載者:User

Linux換源+編譯核心總結,linux編譯核心總結

換源:

我用的是CentOS,所以下面以其為例,其它OS做法類似,可作參考;

在主機能連網的情況下

進入存放源配置的檔案夾
cd /etc/yum.repos.d
備份預設源
mv ./CentOS-Base.repo ./CentOS-Base.repo.bak
使用wget下載163的源 http://mirrors.163.com/.help/centos.html
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
把下載下來的檔案CentOS-Base-163.repo設定為預設源
mv CentOS6-Base-163.repo CentOS-Base.repo
通過上述操作就把預設源修改為163的了。當然上述的第三、四步可以合并為如下:
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O CentOS-Base.repo
運行yum makecache產生緩衝
yum makecache
全部更新
yum update
  在主機不能連網的情況下現在windows上下載好源設定http://mirrors.163.com/.help/CentOS6-Base-163.repo 進入存放源配置的檔案夾
cd /etc/yum.repos.d
上傳下載下來的源
rz
刪除原來的源
rm CentOS-Base.repo
把下載下來的檔案CentOS-Base-163.repo設定為預設源
mv CentOS6-Base-163.repo CentOS-Base.repo
運行yum makecache產生緩衝
yum makecache
全部更新
yum update
 編譯升級核心:從www.kernel.org下載所需版本的核心檔案:下面以檔案linux-3.19.3.tar.xz為例 使用xshell串連linux主機,或登入linux主機 使用rz命令上傳核心檔案
rz
解壓核心檔案
xz -dk linux-3.19.3.tar.xz//如果提示xz not found,請幫yum換源,再用yum install xz安裝
繼續解壓,得到檔案夾:linux-3.19.3
tar xvf linux-3.19.3.tar
進入剛得到的檔案夾
cd linux-3.19.3
使用yum安裝編譯需要的編譯環境
yum install -y gcc make bison ncurses-devel rpm-build
複製現有核心編譯的設定檔
cp /boot/config-`uname -r` .config
如果想使用舊核心配置,並自動接收每個新增選項的預設設定
sh -c 'yes "" | make oldconfig'
進入菜單配置
make menuconfig
根據需求,設定選項“[ ] 64-bit kernel" 是否選擇,按‘y’選擇,‘n’取消 進入General setup, 勾選 "Enable deprected sysfs features to support old userspace tools" 產生核心檔案,通常產生在/usr/src/arch/x86/boot目錄下 
make bzImage
編譯核心模組
make modules
安裝新核心模組,即把它們放到相應的位置
make modules_install//上面三步也可以寫成這樣://make bzImage && make modules && make modules_install
安裝核心
make install
設定系統引導管理器,以便從新的核心啟動
vi /etc/grub.conf   //將default=1改為default=0,儲存退出
重啟系統
reboot
驗證核心版本
uname -a
 !!!以上任一編譯過程出現錯誤需重新編譯!!! 先執行!清除安裝過程中的臨時檔案
make mrproper//make clean
再重複編譯步驟。 PS:下面的錯誤只遇到了兩個,其它是在解決過程中收集的,如若侵犯了你的權益,請勞煩告知刪除,謝謝~  錯誤一:In file included from /usr/include/sys/time.h:31,from /usr/include/linux/input.h:12,from samples/hidraw/hid-example.c:14:/usr/include/sys/select.h:78: 錯誤:與 ‘fd_set’ 類型衝突/usr/include/linux/types.h:12: 錯誤:‘fd_set’ 的上一個聲明在此In file included from /usr/include/linux/input.h:14,from samples/hidraw/hid-example.c:14:/usr/include/sys/types.h:62: 錯誤:與 ‘dev_t’ 類型衝突/usr/include/linux/types.h:13: 錯誤:‘dev_t’ 的上一個聲明在此/usr/include/sys/types.h:67: 錯誤:與 ‘gid_t’ 類型衝突/usr/include/linux/types.h:27: 錯誤:‘gid_t’ 的上一個聲明在此/usr/include/sys/types.h:72: 錯誤:與 ‘mode_t’ 類型衝突/usr/include/linux/types.h:15: 錯誤:‘mode_t’ 的上一個聲明在此/usr/include/sys/types.h:77: 錯誤:與 ‘nlink_t’ 類型衝突/usr/include/linux/types.h:16: 錯誤:‘nlink_t’ 的上一個聲明在此/usr/include/sys/types.h:82: 錯誤:與 ‘uid_t’ 類型衝突/usr/include/linux/types.h:26: 錯誤:‘uid_t’ 的上一個聲明在此In file included from /usr/include/sys/types.h:133,from /usr/include/linux/input.h:14,from samples/hidraw/hid-example.c:14:/usr/include/time.h:105: 錯誤:與 ‘timer_t’ 類型衝突/usr/include/linux/types.h:22: 錯誤:‘timer_t’ 的上一個聲明在此In file included from /usr/include/linux/input.h:14,from samples/hidraw/hid-example.c:14:/usr/include/sys/types.h:235: 錯誤:與 ‘blkcnt_t’ 類型衝突/usr/include/linux/types.h:114: 錯誤:‘blkcnt_t’ 的上一個聲明在此samples/hidraw/hid-example.c:15:26: 錯誤:linux/hidraw.h:沒有那個檔案或目錄samples/hidraw/hid-example.c: In function ‘main’:samples/hidraw/hid-example.c:48: 錯誤:‘rpt_desc’ 的儲存大小未知samples/hidraw/hid-example.c:49: 錯誤:‘info’ 的儲存大小未知samples/hidraw/hid-example.c:65: 錯誤:‘HIDIOCGRDESCSIZE’ 未聲明 (在此函數內第一次使 用)samples/hidraw/hid-example.c:65: 錯誤:(即使在一個函數內多次出現,每個未聲明的標識符 在其samples/hidraw/hid-example.c:65: 錯誤:所在的函數內只報告一次。)samples/hidraw/hid-example.c:73: 錯誤:‘HIDIOCGRDESC’ 未聲明 (在此函數內第一次使用)samples/hidraw/hid-example.c:84: 警告:隱式聲明函數 ‘HIDIOCGRAWNAME’samples/hidraw/hid-example.c:91: 警告:隱式聲明函數 ‘HIDIOCGRAWPHYS’samples/hidraw/hid-example.c:98: 錯誤:‘HIDIOCGRAWINFO’ 未聲明 (在此函數內第一次使用)samples/hidraw/hid-example.c:49: 警告:未使用的變數 ‘info’samples/hidraw/hid-example.c:48: 警告:未使用的變數 ‘rpt_desc’samples/hidraw/hid-example.c: In function ‘bus_str’:samples/hidraw/hid-example.c:171:  錯誤:‘BUS_VIRTUAL’ 未聲明 (在此函數內第一次使用) make[2]: *** [samples/hidraw/hid-example] 錯誤 1 make[1]: *** [samples/hidraw] 錯誤 2 make: *** [vmlinux] 錯誤 2  解決方案:
cp include/linux/hidraw.h /usr/include/linux/cp include/linux/hid.h /usr/include/linux/vi samples/hidraw/hid-example.c
將13-15行的如下3行移動到33行以後。  
     13 #include <linux/types.h>     14 #include <linux/input.h>     15 #include <linux/hidraw.h>       29 #include <sys/ioctl.h>     30 #include <sys/types.h>     31 #include <sys/stat.h>     32 #include <fcntl.h>     33 #include <unistd.h>
 接下來繼續修改
vi /usr/include/linux/input.h
 定位到647行 #define BUS_PCI                 0x01#define BUS_ISAPNP              0x02#define BUS_USB                 0x03#define BUS_HIL                 0x04#define BUS_BLUETOOTH           0x05 /*新增以下這一行*/
#define BUS_VIRTUAL             0x06 
#define BUS_ISA                 0x10#define BUS_I8042               0x11#define BUS_XTKBD               0x12#define BUS_RS232               0x13#define BUS_GAMEPORT            0x14#define BUS_PARPORT             0x15#define BUS_AMIGA               0x16#define BUS_ADB                 0x17#define BUS_I2C                 0x18#define BUS_HOST                0x19#define BUS_GSC                 0x1A/*再新增兩行---聲明*/
#define BUS_ATARI               0x1B#define BUS_SPI                 0x1C
或者 進入設定菜單
make menuconfig
進入選項"kernel hacking"取消勾選:"sameple kernel code"因為它預設引用了include的標頭檔,不編譯即可!  錯誤二: 錯誤提示:編譯錯誤,未知儲存大小 解決辦法:這兩個標頭檔可以把錯誤與警告消除
vi samples/hidraw/hid-example.c
新增
#include <arpa/inet.h>#include <netinet/in.h> 
  錯誤三: 錯誤提示:Kernel panic—not syncing :vfs:unable to mount root fs on unkown—block (0,0)
錯誤分析:initrd-*.*.img檔案有問題;未能成功掛載真正的根檔案系統。
解決方案:請你 確認執行了make install 命令  錯誤四: 錯誤提示:Create root device  mkrootdev: label / not found 
                     Mountingrootfilesystem 
                     mount :error2 mounting ext3
                     mount :error 2mountingnone 
                     switch root mount failed:22
                     umount  /initrd/dev failed :2
                     kernel panic-not synicncing :Attempted to kill  init .
錯誤分析:
1、根檔案系統找不到掛載點 ,修改grub.conf檔案為 root=/dev/ * 
2、硬碟驅動未能找到,請看看你機器的硬碟是都是 SATA盤,是的話同樣恭喜你本文對你有協助。

錯誤解決:
1.、修改grub.conf檔案試試,具體修改點
root=/dev/*// * 指的是原系統中/分區的掛載點。
修改後,重啟進入新核心系統,很有會遇到如下錯誤提示:
Mounting root filesystem 
mount :error6 mounting ext3
mount :error 2 mountingnone 
switchroot mount failed:22
umount  /initrd/dev failed :2
kernel panic-not synicncing :Attempted tokil  linit .
如果真的跪了,繼續看好了~ 2、硬碟驅動未能成功找到,SCSI驅動有問題。
核心選項是這樣的
Device Drivers--------SCSI
device support------SCSI
low-level drivers----Serial ATA(SATA)support 選為 M
然後再選擇相應的子選項 Intel PIIX/ICH  SATA support (new)設定後機器就成功啟動了。

錯誤五:
錯誤提示:Enforcing mode requested but no policy loaded. Halting now.
kernel panic - not syncing: Attenpted to kill init!
錯誤分析:原核心中啟用了selinux,新核心未選擇selinux的選項,不能成功啟動。
解決方案:修改grub.conf檔案,在root=LABEL=/ 後加入 enforcing=0 

錯誤六:
編譯完重啟後出現:
switchroot:   mount   failed:   22 
umount   /initrd/dev   failed:   2 
kernel   panic   -   not   symcing:   Attempted   to   kill   init! 
的錯誤,

解決辦法:
重新make menuconfig, 使CONFIG_SYSFS_DEPRECATED_V2=y
也可以開啟檔案.config做修改和驗證;
再執行:
# make bzImage
# make modules
# make modules_install
# make install
# shutdown -r "now"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.