Linux換源+編譯內核總結

  • 換源:css

     

    我用的是CentOS,因此下面以其爲例,其它OS作法相似,可做參考;html

     

    在主機能聯網的狀況下linux

     

    進入存放源配置的文件夾shell

    cd /etc/yum.repos.dwindows

    備份默認源centos

    mv ./CentOS-Base.repo ./CentOS-Base.repo.bak緩存

    使用wget下載163的源 http://mirrors.163.com/.help/centos.htmlide

    wget http://mirrors.163.com/.help/CentOS6-Base-163.repo函數

    把下載下來的文件CentOS-Base-163.repo設置爲默認源ui

    mv CentOS6-Base-163.repo CentOS-Base.repo

    經過上述操做就把默認源修改成163的了。固然上述的第3、四步能夠合併爲以下:

    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 .

    錯誤分析:

    一、根文件系統找不到掛載點 ,修改grub.conf文件爲 root=/dev/ * 

    二、硬盤驅動未能找到,請看看你機器的硬盤是都是 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 .

    若是真的跪了,繼續看好了~

     

    二、硬盤驅動未能成功找到,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"

相關文章
相關標籤/搜索