ubuntu 20.04编译linux-5.4.213内核

虚机 8核4G HDD

uname -a
Linux li-ubuntu2004 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

apt-get install gcc libncurses5-dev build-essential kernel-package libssl-dev kernel-source-** libc6-dev tk8.* fakeroot bin86 flex bison dwarves
#For CentOS
#yum install gcc gcc-c++
#yum install "Development Tools"
#yum install ncurses-devel

挂载新虚拟磁盘(可选,编译过程需30GB磁盘空间)
#fdisk -l
lsblk
mkfs -t ext4 /dev/sdb
mount /dev/sdb /opt
永久性挂载:
得到这个分区的UUID:
blkid /dev/sdb
vi /etc/fstab
最后一行后面追加:
UUID=cf9aa31c-9800-4ce3-bacf-13bc0599c128 /opt ext4 defaults 0 2
使之生效:
mount -a
重启服务器,就会自动挂载了
#如需卸载分区:
#umount /dev/sdb

Download:
https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.4.213.tar.xz
tar -xvf linux-5.4.213.tar.xz
cd linux-5.4.213

make menuconfig
在选项上按下shift+?可以获得帮助信息

查看已保存的配置:
vi .config

修改:
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
#如果CONFIG_SYSTEM_REVOCATION_KEYS的值不为空的话,也将其赋空值
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
To:
CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_REVOCATION_KEYS=""

#For some old version kernel
make dep

make -j8
#耗时36分钟
make module -j8
make INSTALL_MOD_STRIP=1 modules_install -j8
#耗时6分钟
make install -j8

reboot

选择Advanced options
选择5.4.213内核



删除多余内核:
检查当前内核
uname -a
查看所有内核
dpkg --get-selections | grep linux
移除冗余内核
apt-get purge \
linux-headers-5.4.0-88 \
linux-headers-5.4.0-88-generic \
linux-image-5.4.0-88-generic \
linux-modules-5.4.0-88-generic \
linux-modules-extra-5.4.0-88-generic
卸载后重新检查
dpkg --get-selections | grep linux
更新系统引导
删除内核后需要更新grub移除失效的启动项
#根据情况选择grub/grub2
update-grub2


#下面内容For CentOS:
CentOS编译2.6.39.4内核报错:
ERROR: modinfo: could not find module vmware_balloon
这个模块在后面的版本中,已经更名为 vmw_balloon
解决方法:
cd /lib/modules/2.6.39.4/kernel/drivers/misc/
ln -s vmw_balloon.ko vmware_balloon.ko
安装完毕后
vi /boot/grub/grub.conf
default=0