Deepin內核升級方法


前奏

①、執行make menuconfig需要安裝庫libncurses5-dev,執行“sudo apt-get install libncurses5-dev”

②、執行make需要安裝庫libssl-dev,執行“sudo apt-get install libssl-dev”

③、編譯內核出現如下錯誤“kernel/bounds.c:1:0: error: code model kernel does not support PIC mode”

   修改頂層Makefile文件:

KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                   -fno-strict-aliasing -fno-common \
                   -Werror-implicit-function-declaration \
                   -Wno-format-security \
-                  -std=gnu89
+           -std=gnu89 -fno-pie

- KBUILD_AFLAGS   := -D__ASSEMBLY__
+ KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-pie

 ④、深度內核常識性介紹:https://wiki.deepin.org/wiki/Linux%E5%86%85%E6%A0%B8#.E5.AE.89.E8.A3.85

不進行內核編譯升級內核版本參考如下文檔:https://bbs.deepin.org/forum.php?mod=viewthread&tid=175411&extra=

手動進行內核獲取、編譯和內核替換升級

1、獲取當前內核版本

think@think-PC:~/Desktop$ sudo uname -r
4.15.0-30deepin-generic think@think-PC:~/Desktop$ sudo uname -a Linux think-PC 4.15.0-30deepin-generic #31 SMP Fri Nov 30 04:29:02 UTC 2018 x86_64 GNU/Linux

2、查看當前可用源碼包

think@think-PC:~/Desktop$ sudo apt-cache search linux-source
linux-source - Linux kernel source (meta-package) linux-source-4.15.0 - Linux kernel source for version 4.15.0 with Ubuntu patches linux-source-4.19 - Linux kernel source for version 4.19 with Debian patches linux-source-4.9 - Linux kernel source for version 4.9 with Debian patches

3、獲取內核源碼包

  1)、聯網獲取

sudo apt-get install linux-source-4.19

會在/usr/src目錄下得到"linux-source-4.19.tar.xz"和“linux-patch-4.19-rt.patch.xz”的源碼,前一個為內核源碼,后一個為當前Deepin系統的補丁文件。這兩個文件均采用兩層壓縮的方式,外層是xz壓縮,內層是tar壓縮。

  2)、從網絡下載的內核壓縮包

https://www.kernel.org/網站下載內核源碼,具體路徑:https://mirrors.edge.kernel.org/pub/linux/kernel/,下載之后上傳到Linux系統中進行解壓。

4、對源碼包進行解壓

# 解壓外層
think@think-PC:/usr/src$ xz -d linux-source-4.19.tar.xz # 解壓內層 think@think-PC:/usr/src$ tar -xf linux-source-4.19.tar 

5、編譯內核

# 打補丁,此過程為可選項。打補丁是為了升級內核,如果不升級內核不需要打補丁。
think@think-PC:/usr/src/linux-source-4.19$ sudo patch -p1 < ../linux-patch-4.19-rt.patch #配置內核(確保當前深度內核與將要編譯內核版本相同,使用該編譯方法會讀取當前系統版本內核配置文件,同時去掉當前系統未使用的模塊,優化內核編譯) think@think-PC:/usr/src/linux-source-4.19$ sudo make localmodconfig #編譯內核 think@think-PC:/usr/src/linux-source-4.19$ sudo make

6、在lib下創建內核版本目錄

think@think-PC:/lib/modules$ sudo mkdir 4.15.0
think@think-PC:/lib/modules$ ls
4.15.0  4.15.0-30deepin-generic

 7、安裝驅動到創建的4.15.0目錄下

think@think-PC:~/kernel/linux-4.15$ sudo make modules_install

8、安裝內核、文件系統、映射到/boot目錄。

  安裝過程主要包括:

  1)、復制System.map、Vmlinuz和config-4.15.0到/boot目錄。

  2)、執行"update-initramfs -c -k 4.15.0"命令,在/boot目錄中產生文件系統文件。

  3)、執行“update-grub”命令,更新/boot/grub/grub.cfg文件,產生4.15.0版本的引導項。

think@think-PC:~/kernel/linux-4.15$ sudo make install
sh ./arch/x86/boot/install.sh 4.15.0 arch/x86/boot/bzImage \
    System.map "/boot"
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.15.0 /boot/vmlinuz-4.15.0
run-parts: executing /etc/kernel/postinst.d/dkms 4.15.0 /boot/vmlinuz-4.15.0
Error!  Build of huawei-wmi.ko failed for: 4.15.0 (x86_64)
Consult the make.log in the build directory
/var/lib/dkms/huawei-wmi/1.0/build/ for more information.
Error!  Build of mincores.ko failed for: 4.15.0 (x86_64)
Consult the make.log in the build directory
/var/lib/dkms/mincores/0.2.0/build/ for more information.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.15.0 /boot/vmlinuz-4.15.0
update-initramfs: Generating /boot/initrd.img-4.15.0
WARNING: Setting CRYPTSETUP in /etc/initramfs-tools/initramfs.conf is deprecated and will stop working in the future. Use /etc/cryptsetup-initramfs/conf-hook instead.
loadkeys is missing. Please install the 'kbd' package.
W: plymouth: The plugin label.so is missing, the selected theme might not work as expected.
W: plymouth: You might want to install the plymouth-themes package to fix this.
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/reconfigure-dde-daemon 4.15.0 /boot/vmlinuz-4.15.0
fix systemd/logind config
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.15.0 /boot/vmlinuz-4.15.0
Generating grub configuration file ...
Found theme: /boot/grub/themes/deepin/theme.txt
Found linux image: /boot/vmlinuz-4.15.0-30deepin-generic
Found initrd image: /boot/initrd.img-4.15.0-30deepin-generic
Found linux image: /boot/vmlinuz-4.15.0
Found initrd image: /boot/initrd.img-4.15.0
done

 GRUB啟動說明

Grub啟動主要從兩個文件夾進行修改:/etc/default/grub和/etc/grub.d

1、/etc/default/grub文件

DEEPIN_GFXMODE_DETECT=1

#手動添加內核啟動參數         
GRUB_CMDLINE_LINUX=""

#添加內核啟動參數,這個為默認
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet "

#默認啟動項,這個值為0就是默認啟動第一個,為1默認啟動第二個
GRUB_DEFAULT=0

#獲得發行版本(此行將追加到所有的linux 定義內核行的后面,不論是救援模式還是一般模式)
GRUB_DISTRIBUTOR="`/usr/bin/lsb_release -d -s 2>/dev/null || echo Deepin`"

#啟動的分辨率
GRUB_GFXMODE=2560x1600,1920x1440,1856x1392,1792x1344,1920x1200,1600x1200,1680x1050,1400x1050,1280x1024,1440x900,1280x960,1360x768,1280x800,1152x864,1280x768,1024x768,auto

#啟動的主題,是各種圖片和各種顯示的字體
GRUB_THEME=/boot/grub/themes/deepin-fallback/theme.txt

#等待時間,5秒未操作直接進入默認系統。改為-1是一直等待。
GRUB_TIMEOUT=5

2、/etc/grub.d

00_header                         # 配置初始的顯示項目,如默認選項,時間限制等,一般由/etc/default/grub導入,一般不需要配置
05_debian_theme        #  配置引導畫面,文字顏色等主題
10_linux                            #定位當前操作系統使用中的root設備內核的位置,包含deepin 啟動項和advanced里面的啟動項
15_linux_bar                  # 救援模式的啟動項
20_linux_xen                 # 虛擬機監視器的東西,(暫時不知有什么用
30_uefi-firmware       # “system setup” 的啟動項
35_os-prober               #   windows的啟動項一般在這個里面
40_custom                   # 用來加入用戶自定義的啟動項,將會在執行update-grub時更新至grub.cfg中
41_custom                  # 判斷custom.cfg此配置文件是否存在,如果存在就加載它
前面的數字是對文件排列執行的順序進行排序,可進行更改,比如你想把windows啟動項調到第一個,就把35_os-prober前面那個數字改成5到10的數字,比如06、07、08、09.

 存在多個系統啟動項時選擇啟動選項

按照上述方案創建的多個系統啟動項會放置到啟動界面的Advanced options選項中,啟動時需要手動選擇啟動項。在實際應用中需要設定某一版本的系統自動啟動,此時需要更改啟動選項,更改步驟如下:

①、將需要自動啟動的內核啟動項從/boot/grub/grub.cfg文件的submenu中找到。

②、將其復制到/etc/grub.d/40_custom文件,修改之后文件內容如下所示。

③、修改/etc/default/grub文件的default值為2,執行update-grub命令。

 /etc/grub.d/40_custom文件內容如下:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry 'Deepin 15.10.1 GNU/Linux, with Linux 4.15.0' --class deepin --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-advanced-c270f13a-54cd-4258-b179-e0f36e41abba' {
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
                search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  c270f13a-54cd-4258-b179-e0f36e41abba
        else
                search --no-floppy --fs-uuid --set=root c270f13a-54cd-4258-b179-e0f36e41abba
        fi
        linux   /boot/vmlinuz-4.15.0 root=UUID=c270f13a-54cd-4258-b179-e0f36e41abba ro  splash quiet  DEEPIN_GFXMODE=$DEEPIN_GFXMODE
        initrd  /boot/initrd.img-4.15.0
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM