ubuntu 内核源码(ubuntu 内核源码在哪里)

ubuntu 内核源码(ubuntu 内核源码在哪里)已验证 如何查看自己的 ubuntu 系统中是否已经有了内核源码树了 直接去查看 lib modules 目录下是否存在 build 目录 如果存在 则表示我们自己的系统已经拥有内核源码树了 但为了熟悉整个的过程 我们也重新下载对应自己的编译环境的 内核源码 并对其进行编译 构造内核源码树 1 安装编译内核所需的软件 要用 make menuconfig



(已验证)

 
  

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
#apt search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.2.0 - Linux kernel source for version 3.2.0 with Ubuntu patches
linux-source-4.2.0 - Linux kernel source for version 4.2.0 with Ubuntu patches
/
root@www-Vostro-2420:/home/www/work# apt search linux-source
正在排序… 完成
全文搜索… 完成
linux-source/未知,未知 4.2.0.42.45 all
Linux kernel source with Ubuntu patches









2.下载源码
#apt install linux-source-3.2.0
下载完成后,在/usr/src目录中,可以看到压缩包
$ 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
缺少ncurses库,安装
$ sudo apt-get install libncurses5-dev

重新编译成功。也可以使用系统原来的配置来编译,oldconfig

$ sudo make oldconfig #编译内核
编译内核
root@www-Vostro-2420:/usr/src/linux-source-3.2.0# make bzImage -j4
编译模块make modules


使用 sudo make modules_install 命令安装模块,执行完后,会在 /lib/modules 目录下生成一个新的目录 /lib/modules/3.13.0/ 。至此,内核就编译完成了。

  1. 安装内核

安装内核的过程就快的很多了,这和一般的软件安装包的安装软件 是相似的。

INSTALL drivers/thermal/x86_pkg_temp_thermal.ko
INSTALL fs/efivarfs/efivarfs.ko
INSTALL net/ipv4/netfilter/ipt_MASQUERADE.ko
INSTALL net/ipv4/netfilter/iptable_nat.ko
INSTALL net/ipv4/netfilter/nf_log_arp.ko
INSTALL net/ipv4/netfilter/nf_log_ipv4.ko
INSTALL net/ipv4/netfilter/nf_nat_ipv4.ko
INSTALL net/ipv4/netfilter/nf_nat_masquerade_ipv4.ko
INSTALL net/ipv6/netfilter/nf_log_ipv6.ko
INSTALL net/netfilter/nf_log_common.ko
INSTALL net/netfilter/nf_nat.ko
INSTALL net/netfilter/nf_nat_ftp.ko
INSTALL net/netfilter/nf_nat_irc.ko
INSTALL net/netfilter/nf_nat_sip.ko
INSTALL net/netfilter/xt_LOG.ko
INSTALL net/netfilter/xt_addrtype.ko
INSTALL net/netfilter/xt_mark.ko
INSTALL net/netfilter/xt_nat.ko
INSTALL ubuntu/vbox/vboxguest/vboxguest.ko
INSTALL ubuntu/vbox/vboxsf/vboxsf.ko
INSTALL ubuntu/xr-usb-serial/xr_usb_serial_common.ko
DEPMOD 4.15.18
root@T-L430:linux-source-4.15.0# ls /lib/modules/
4.13.0-21-generic 4.13.0-45-generic 4.15.0-23-generic 4.15.18
多出的4.15.18目录就是刚make modules_install时搞出来的。























再安装内核
root@T-L430:linux-source-4.15.0# make install
sh https://blog.csdn.net/wenfengliaoshuzhai/article/details/arch/x86/boot/install.sh 4.15.18 arch/x86/boot/bzImage
System.map “/boot”
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.15.18 /boot/vmlinuz-4.15.18
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.15.18 /boot/vmlinuz-4.15.18
update-initramfs: Generating /boot/initrd.img-4.15.18
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.15.18 /boot/vmlinuz-4.15.18
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.15.18 /boot/vmlinuz-4.15.18
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.15.18 /boot/vmlinuz-4.15.18
Generating grub configuration file …
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.15.18
Found initrd image: /boot/initrd.img-4.15.18
Found linux image: /boot/vmlinuz-4.15.0-23-generic
Found initrd image: /boot/initrd.img-4.15.0-23-generic
Found linux image: /boot/vmlinuz-4.13.0-45-generic
Found initrd image: /boot/initrd.img-4.13.0-45-generic
Found linux image: /boot/vmlinuz-4.13.0-21-generic
Found initrd image: /boot/initrd.img-4.13.0-21-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done





















完成安装之后,会在/boot内生成对应的内核相关文件,重启之后,在启动引导页面,会让我们选择启动的内核,这时我们可以选择是当前默认的4.13内核还是刚刚编译安装的更新的4.15内核。

root@T-L430:linux-source-4.15.0# ls /boot/
abi-4.13.0-21-generic initrd.img-4.13.0-45-generic System.map-4.13.0-45-generic
abi-4.13.0-45-generic initrd.img-4.15.0-23-generic System.map-4.15.0-23-generic
abi-4.15.0-23-generic initrd.img-4.15.18 System.map-4.15.18
config-4.13.0-21-generic memtest86+.bin vmlinuz-4.13.0-21-generic
config-4.13.0-45-generic memtest86+.elf vmlinuz-4.13.0-45-generic
config-4.15.0-23-generic memtest86+_multiboot.bin vmlinuz-4.15.0-23-generic
config-4.15.18 retpoline-4.13.0-45-generic vmlinuz-4.15.18
grub retpoline-4.15.0-23-generic
initrd.img-4.13.0-21-generic System.map-4.13.0-21-generic








五、更改启动grub

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了




今天的文章 ubuntu 内核源码(ubuntu 内核源码在哪里)分享到此就结束了,感谢您的阅读。
编程小号
上一篇 2025-04-15 10:46
下一篇 2025-07-26 09:01

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/32856.html