參考博客:Ubuntu20.04編譯內(nèi)核教程
sudo lsb_release -a
可以看到我當(dāng)前的系統(tǒng)是Ubuntu 20.04.4
,sudo uname -r
可以看到我的系統(tǒng)內(nèi)核版本是5.4.0-100-generic
。sudo apt-get install -y libncurses5-dev flex bison libssl-dev
安裝所需要的依賴。
sudo apt-get install linux-source
按兩下Tab,看一下可以下載的源碼。
然后輸入sudo apt-get install linux-source-5.4.0
就可以下載源碼。
sudo find / -name linux-source-5.4.0
看一下源碼下載位置,ls -l /usr/src/linux-source-5.4.0
看一下目錄下邊的內(nèi)容。
sudo tar xjf /usr/src/linux-source-5.4.0/linux-source-5.4.0.tar.bz2 -C /usr/src/linux-source-5.4.0/
把源碼壓縮包解壓到/usr/src/linux-source-5.4.0/
目錄下。
cd /usr/src/linux-source-5.4.0/linux-source-5.4.0/
進(jìn)入到源碼頂層目錄下。
sudo make menuconfig
進(jìn)入到配置頁(yè)面。
按↑↓鍵可以選擇目錄,←→鍵可以選擇選項(xiàng),比如<Select>,< Exit >等。
按↑↓鍵選擇 Device Drivers --->
,然后按Enter。
按↑↓鍵選擇Network device support --->
,然后按Enter。
按↑↓鍵選擇Universal TUN/TAP device driver support
,然后按m,在尖括號(hào)里邊要有M
。
按←→鍵,選擇 < Save >,然后按Enter。
按←→鍵,選擇 < ok >,然后按Enter。
然后再按Enter。
按←→鍵,選擇 < Exit >,然后按Enter。
按←→鍵,選擇 < Exit >,然后按Enter
按←→鍵,選擇 < Exit >,然后按Enter
最后退出到命令行。
重新配置一些參數(shù)。
sudo sed -i 's/CONFIG_MODULE_SIG=y/CONFIG_MODULE_SIG=n/g' .config # 把 CONFIG_MODULE_SIG=y 替換成 CONFIG_MODULE_SIG=n
sudo sed -i 's/CONFIG_MODULE_SIG_ALL=y/CONFIG_MODULE_SIG_ALL=n/g' .config
sudo sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYS="debian\/canonical-certs.pem"/CONFIG_SYSTEM_TRUSTED_KEYS=""/g' .config
sudo sed -i 's/CONFIG_SYSTEM_REVOCATION_KEYS="debian\/canonical-revoked-certs.pem"/CONFIG_SYSTEM_REVOCATION_KEYS=""/g' .config
sudo sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYRING=y/CONFIG_SYSTEM_TRUSTED_KEYRING=n/g' .config # 把 CONFIG_SYSTEM_TRUSTED_KEYRING=y 替換成 CONFIG_SYSTEM_TRUSTED_KEYRING=n
cat .config | grep "CONFIG_SYSTEM_TRUSTED_KEYRING=n" # 看一下 CONFIG_SYSTEM_TRUSTED_KEYRING 相關(guān)字符串是否成功替換。
sudo nohup make -j2 all &
在后臺(tái)運(yùn)行make
編譯過(guò)程,按一下回車鍵可以再次進(jìn)入命令輸出。
cat nohup.out
可以看一下文件里邊的內(nèi)容。
使用sudo ps -aux | grep nohup
可以看一下sudo nohup make -j2 all &
是否還在運(yùn)行。
sudo ps -aux | grep nohup
要是只有如下所示一條記錄,要么執(zhí)行完成,要么有問(wèn)題報(bào)錯(cuò)了。
cat nohup.out
看一下輸出文件,發(fā)現(xiàn)報(bào)錯(cuò)如下:
BTF: .tmp_vmlinux.btf: pahole (pahole) is not available
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make: *** [Makefile:1139: vmlinux] Error 1
sudo apt-get install -y dwarves
是為了解決上邊的報(bào)錯(cuò)而安裝依賴包。
sudo nohup make -j2 all &
執(zhí)行之后,nohup: ignoring input and appending output to 'nohup.out'
之后按一下回車鍵,接著讓系統(tǒng)進(jìn)行編譯吧。
ps -aux | grep 459469
和sudo ps -aux | grep nohup
發(fā)現(xiàn)這個(gè)459469
進(jìn)程已經(jīng)不執(zhí)行了。
sudo tail -n 20 nohup.out
看一下/usr/src/linux-source-5.4.0/linux-source-5.4.0/nohup.out
最后二十行內(nèi)容,發(fā)現(xiàn)沒有報(bào)錯(cuò)。結(jié)合上邊459469
已經(jīng)執(zhí)行結(jié)束,這說(shuō)明內(nèi)核已經(jīng)編譯成功了。sudo nohup make modules_install &
進(jìn)行內(nèi)核安裝,在nohup: ignoring input and appending output to 'nohup.out'
之后按一下回車鍵。
ps -aux | grep 555980
看一下555980
進(jìn)程是否還在執(zhí)行,發(fā)現(xiàn)已經(jīng)結(jié)束了。
sudo tail -n 30 nohup.out
看一下nohup.out
最后三十行輸出結(jié)果,發(fā)現(xiàn)沒有報(bào)錯(cuò),結(jié)合上邊555980
進(jìn)程已經(jīng)結(jié)束,所以內(nèi)核模塊已經(jīng)安裝完成。
sudo grep 'menuentry' /boot/grub/grub.cfg
可以看一下相關(guān)信息。
/etc/default/grub
里邊的原來(lái)內(nèi)容如下:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 nospectre_v2 nopti noibrs noibpb"
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
具體如何修改/etc/default/grub
,可以參考下邊兩篇博客:
Ubuntu 20.04 LTS修改內(nèi)核版本
Ubuntu20.04 如何降低內(nèi)核版本?
sudo vim /etc/default/grub
,我把內(nèi)容修改如下:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT="gnulinux-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3>gnulinux-5.4.0-26-generic-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3"
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 nospectre_v2 nopti noibrs noibpb"
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
就是把GRUB_DEFAULT=0
改為GRUB_DEFAULT="gnulinux-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3>gnulinux-5.4.0-26-generic-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3"
。
sudo update-grub
更新grub
,sudo reboot
進(jìn)行重啟。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-606062.html
重啟之后輸入sudo uname -r
可以看到內(nèi)核已經(jīng)變?yōu)?code>5.4.0-26-generic。
內(nèi)容來(lái)源于極客時(shí)間《Linux 實(shí)戰(zhàn)技能 100 講》。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-606062.html
到了這里,關(guān)于Linux學(xué)習(xí)之Ubuntu 20.04安裝內(nèi)核模塊的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!