<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path> </svg> <p>(已验证)</p>
讯享网
讯享网
sudo apt-get install build-essential kernel-package libncurses5-dev fakeroot
ubuntu 20.0还需要安装sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install libssl-dev
\( apt-cache search linux-source<br /> #apt search linux-source<br /> linux-source - Linux kernel source with Ubuntu patches<br /> linux-source-3.2.0 - Linux kernel source for version 3.2.0 with Ubuntu patches<br /> linux-source-4.2.0 - Linux kernel source for version 4.2.0 with Ubuntu patches<br /> /<br /> root@www-Vostro-2420:/home/www/work# apt search linux-source<br /> 正在排序… 完成<br /> 全文搜索… 完成<br /> linux-source/未知,未知 4.2.0.42.45 all<br /> Linux kernel source with Ubuntu patches</p> <p>linux-source-3.2.0/precise-updates,precise-security,now 3.2.0-126.169 all [已安装]<br /> Linux kernel source for version 3.2.0 with Ubuntu patches</p> <p>linux-source-4.2.0/未知,未知 4.2.0-42.49 all<br /> Linux kernel source for version 4.2.0 with Ubuntu patches</p> <p>2.下载源码<br /> #apt install linux-source-3.2.0<br /> 下载完成后,在/usr/src目录中,可以看到压缩包<br /> \) ls
linux-source-3.2.0
linux-source-3.2.0.tar.bz2
/
解压内核源码包:进入 /usr/src/ 目录,能找到 linux-source-3.13.0.tar.bz2 文件,用解压命令 sudo tar xjvf linux-source-3.13.0.tar.bz2 解压。要注意上面目录下的 linux-source-3.13.0.tar.bz2 文件并不是软件压缩包文件,而是一个软链接,不能直接使用 tar 进行解压。//
3.编译
$ sudo tar -xjvf linux-source-2.6.35.tar.bz2
进入 linux-source-3.13.0 文件夹,发现真正的 tar 源码压缩包,解压
配置内核
root@www-Vostro-2420:/usr/src/linux-source-3.2.0# ls arch/x86/configs/
i386_defconfig x86_64_defconfig
root@www-Vostro-2420:/usr/src/linux-source-3.2.0# make x86_64_defconfig
\( sudo make menuconfig<br /> 缺少ncurses库,安装<br /> \) sudo apt-get install libncurses5-dev

重新编译成功。也可以使用系统原来的配置来编译,oldconfig
\( sudo make oldconfig #编译内核<br /> 编译内核<br /> root@www-Vostro-2420:/usr/src/linux-source-3.2.0# make bzImage -j4<br /> 编译模块make modules</p> <p>出现错误Makefile:974: * “Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel”。 停止。<br /> 解决办法apt-get install libelf-dev</p> <p>使用 sudo make modules_install 命令安装模块,执行完后,会在 /lib/modules 目录下生成一个新的目录 /lib/modules/3.13.0/ 。至此,内核就编译完成了。</p> <ol start="4"><li>安装内核</li></ol> <p>安装内核的过程就快的很多了,这和一般的软件安装包的安装软件 是相似的。</p> <p>先安装模块<br /> root@T-L430:linux-source-4.15.0# make modules_install</p> <p>INSTALL drivers/thermal/x86_pkg_temp_thermal.ko<br /> INSTALL fs/efivarfs/efivarfs.ko<br /> INSTALL net/ipv4/netfilter/ipt_MASQUERADE.ko<br /> INSTALL net/ipv4/netfilter/iptable_nat.ko<br /> INSTALL net/ipv4/netfilter/nf_log_arp.ko<br /> INSTALL net/ipv4/netfilter/nf_log_ipv4.ko<br /> INSTALL net/ipv4/netfilter/nf_nat_ipv4.ko<br /> INSTALL net/ipv4/netfilter/nf_nat_masquerade_ipv4.ko<br /> INSTALL net/ipv6/netfilter/nf_log_ipv6.ko<br /> INSTALL net/netfilter/nf_log_common.ko<br /> INSTALL net/netfilter/nf_nat.ko<br /> INSTALL net/netfilter/nf_nat_ftp.ko<br /> INSTALL net/netfilter/nf_nat_irc.ko<br /> INSTALL net/netfilter/nf_nat_sip.ko<br /> INSTALL net/netfilter/xt_LOG.ko<br /> INSTALL net/netfilter/xt_addrtype.ko<br /> INSTALL net/netfilter/xt_mark.ko<br /> INSTALL net/netfilter/xt_nat.ko<br /> INSTALL ubuntu/vbox/vboxguest/vboxguest.ko<br /> INSTALL ubuntu/vbox/vboxsf/vboxsf.ko<br /> INSTALL ubuntu/xr-usb-serial/xr_usb_serial_common.ko<br /> DEPMOD 4.15.18<br /> root@T-L430:linux-source-4.15.0# ls /lib/modules/<br /> 4.13.0-21-generic 4.13.0-45-generic 4.15.0-23-generic 4.15.18<br /> 多出的4.15.18目录就是刚make modules_install时搞出来的。</p> <p>再安装内核<br /> root@T-L430:linux-source-4.15.0# make install<br /> sh https://blog.csdn.net/wenfengliaoshuzhai/article/details/arch/x86/boot/install.sh 4.15.18 arch/x86/boot/bzImage <br /> System.map “/boot”<br /> run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.15.18 /boot/vmlinuz-4.15.18<br /> run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.15.18 /boot/vmlinuz-4.15.18<br /> update-initramfs: Generating /boot/initrd.img-4.15.18<br /> run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.15.18 /boot/vmlinuz-4.15.18<br /> run-parts: executing /etc/kernel/postinst.d/update-notifier 4.15.18 /boot/vmlinuz-4.15.18<br /> run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.15.18 /boot/vmlinuz-4.15.18<br /> Generating grub configuration file …<br /> Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.<br /> Found linux image: /boot/vmlinuz-4.15.18<br /> Found initrd image: /boot/initrd.img-4.15.18<br /> Found linux image: /boot/vmlinuz-4.15.0-23-generic<br /> Found initrd image: /boot/initrd.img-4.15.0-23-generic<br /> Found linux image: /boot/vmlinuz-4.13.0-45-generic<br /> Found initrd image: /boot/initrd.img-4.13.0-45-generic<br /> Found linux image: /boot/vmlinuz-4.13.0-21-generic<br /> Found initrd image: /boot/initrd.img-4.13.0-21-generic<br /> Found memtest86+ image: /boot/memtest86+.elf<br /> Found memtest86+ image: /boot/memtest86+.bin<br /> done</p> <p>完成安装之后,会在/boot内生成对应的内核相关文件,重启之后,在启动引导页面,会让我们选择启动的内核,这时我们可以选择是当前默认的4.13内核还是刚刚编译安装的更新的4.15内核。</p> <p>root@T-L430:linux-source-4.15.0# ls /boot/<br /> abi-4.13.0-21-generic initrd.img-4.13.0-45-generic System.map-4.13.0-45-generic<br /> abi-4.13.0-45-generic initrd.img-4.15.0-23-generic System.map-4.15.0-23-generic<br /> abi-4.15.0-23-generic initrd.img-4.15.18 System.map-4.15.18<br /> config-4.13.0-21-generic memtest86+.bin vmlinuz-4.13.0-21-generic<br /> config-4.13.0-45-generic memtest86+.elf vmlinuz-4.13.0-45-generic<br /> config-4.15.0-23-generic memtest86+_multiboot.bin vmlinuz-4.15.0-23-generic<br /> config-4.15.18 retpoline-4.13.0-45-generic vmlinuz-4.15.18<br /> grub retpoline-4.15.0-23-generic<br /> initrd.img-4.13.0-21-generic System.map-4.13.0-21-generic</p> <p>其中make install命令是在/boot创建出了<br /> config-4.15.18 initrd.img-4.15.18 System.map-4.15.18 vmlinuz-4.15.18</p> <p>五、更改启动grub</p> <p>#cat /boot/grub/grub.cfg<br /> menuentry ‘Ubuntu, with Linux 4.15.0-23-generic (recovery mode)’ --class ubuntu --class gnu-linux --class gnu --class os \)menuentry_id_option ‘gnulinux-4.15.0-23-generic-recovery-c2d82672-ae0f-42a2-97ba-6ec4e59b45d5’
vim /boot/grub/grub.cfg
8.检查无误后,重启以便使用新内核
1.png
上图选择未出现,直接开机了
root@T-L430:www# uname -r
4.15.18
root@T-L430:www# cat /proc/version
Linux version 4.15.18 (root@T-L430) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #1 SMP Sat Sep 29 10:48:46 CST 2018
重启动就变成4.15.18了

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/172331.html