Linux內核替換的一種簡單方法


前言

使用現有centos的鏡像,在海光機器上出現了無法運行的情況,grub引導后就只剩下光標一直在閃,無任何字符輸出。這種情況大概率是因為Linux的內核無法運行在海光的CPU上所導致的。

已得知Linux內核在4.20版本后支持海光CPU,而在之前的版本中,則需要為內核打專門的patch,並編譯內核。考慮到目前centos的軟件源中並沒有提供4.20版本以上的內核,而在其余開發環境中已有現成的5.15.11版本內核,故決定手動替換。

具體步驟

想要替換內核至5.15.11版本,至少需要從其他環境中復制如下文件:

  • /boot/vmlinuz-5.15.11-1.el7.x86_64
  • /boot/initramfs-5.15.11-1.el7.x86_64.img
  • /lib/modules/5.15.11-1.el7.x86_64/目錄

隨后更新grub配置,確認grub中包含新內核的引導:

grub2-mkconfig -o /boot/grub2/grub.cfg

如果initrd存在定制,那么還需要為新內核生成一個initrd:

dracut -v -f -N --kver 5.15.11-1.el7.x86_64

最后重啟驗證新內核是否能夠正常運行。

附錄

Linux對海光的支持

https://cdn.kernel.org/pub/linux/kernel/v4.x/ChangeLog-4.20

commit fec98069fb72fb656304a3e52265e0c2fc9adf87
Merge: 04ce7fae3d4e 995d5f64b62f
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Tue Oct 23 16:16:40 2018 +0100

    Merge branch 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
    
    Pull x86 cpu updates from Ingo Molnar:
     "The main changes in this cycle were:
    
       - Add support for the "Dhyana" x86 CPUs by Hygon: these are licensed
         based on the AMD Zen architecture, and are built and sold in China,
         for domestic datacenter use. The code is pretty close to AMD
         support, mostly with a few quirks and enumeration differences. (Pu
         Wen)
    
       - Enable CPUID support on Cyrix 6x86/6x86L processors"
    
    * 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
      tools/cpupower: Add Hygon Dhyana support
      cpufreq: Add Hygon Dhyana support
      ACPI: Add Hygon Dhyana support
      x86/xen: Add Hygon Dhyana support to Xen
      x86/kvm: Add Hygon Dhyana support to KVM
      x86/mce: Add Hygon Dhyana support to the MCA infrastructure
      x86/bugs: Add Hygon Dhyana to the respective mitigation machinery
      x86/apic: Add Hygon Dhyana support
      x86/pci, x86/amd_nb: Add Hygon Dhyana support to PCI and northbridge
      x86/amd_nb: Check vendor in AMD-only functions
      x86/alternative: Init ideal_nops for Hygon Dhyana
      x86/events: Add Hygon Dhyana support to PMU infrastructure
      x86/smpboot: Do not use BSP INIT delay and MWAIT to idle on Dhyana
      x86/cpu/mtrr: Support TOP_MEM2 and get MTRR number
      x86/cpu: Get cache info and setup cache cpumap for Hygon Dhyana
      x86/cpu: Create Hygon Dhyana architecture support file
      x86/CPU: Change query logic so CPUID is enabled before testing
      x86/CPU: Use correct macros for Cyrix calls

內核rpm包中包含的文件

以內核版本4.18.0為例,首先使用rpm命令查詢內核rpm包中包含有哪些文件,如下所示,rpm包中包含的文件有:

  • 內核文件:/boot/vmlinuz-4.18.0-348.7.1.el8_5.x86_64
  • initrd壓縮包:/boot/initramfs-4.18.0-348.7.1.el8_5.x86_64.img
  • 內核編譯文件(一般用不到):Module.symvers文件boot/symvers-4.18.0-348.7.1.el8_5.x86_64.gz、配置文件/boot/config-4.18.0-348.7.1.el8_5.x86_64、內核符號表/boot/System.map-4.18.0-348.7.1.el8_5.x86_64、內核完整性校驗文件/boot/.vmlinuz-4.18.0-348.7.1.el8_5.x86_64.hmac等
  • 動態庫加載配置文件:/etc/ld.so.conf.d/kernel-4.18.0-348.7.1.el8_5.x86_64.conf
  • 內核模塊:/lib/modules/4.18.0-348.7.1.el8_5.x86_64/目錄下的各種文件
  • 文檔、簽名、許可證等雜項:/usr/share/目錄下的文件
# rpm -ql kernel-core-4.18.0-348.7.1.el8_5.x86_64
/boot/.vmlinuz-4.18.0-348.7.1.el8_5.x86_64.hmac
/boot/System.map-4.18.0-348.7.1.el8_5.x86_64
/boot/config-4.18.0-348.7.1.el8_5.x86_64
/boot/initramfs-4.18.0-348.7.1.el8_5.x86_64.img
/boot/symvers-4.18.0-348.7.1.el8_5.x86_64.gz
/boot/vmlinuz-4.18.0-348.7.1.el8_5.x86_64
/etc/ld.so.conf.d/kernel-4.18.0-348.7.1.el8_5.x86_64.conf
/lib/modules
/lib/modules/4.18.0-348.7.1.el8_5.x86_64
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/.vmlinuz.hmac
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/System.map
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/bls.conf
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/build
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/config
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/kernel
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/kernel/arch
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/kernel/arch/x86
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/kernel/arch/x86/crypto
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/kernel/arch/x86/crypto/blowfish-x86_64.ko.xz
/lib/modules/4.18.0-348.7.1.el8_5.x86_64/kernel/arch/x86/crypto/camellia-aesni-avx-x86_64.ko.xz
...
/usr/share/doc/kernel-keys/4.18.0-348.7.1.el8_5.x86_64
/usr/share/doc/kernel-keys/4.18.0-348.7.1.el8_5.x86_64/kernel-signing-ca-20140212.cer
/usr/share/doc/kernel-keys/4.18.0-348.7.1.el8_5.x86_64/kernel-signing-ca-20200609.cer
/usr/share/doc/kernel-keys/4.18.0-348.7.1.el8_5.x86_64/kernel-signing-ca.cer
/usr/share/licenses/kernel-core
/usr/share/licenses/kernel-core/COPYING-4.18.0


免責聲明!

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



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