歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux換源+編譯內核總結

Linux換源+編譯內核總結

日期:2017/3/1 12:20:33   编辑:關於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"
Copyright © Linux教程網 All Rights Reserved