前言
ubuntu系统安装内核头文件,执行以下命令即可:
apt-get install linux-headers-$(uname -r)
但是有的Ubuntu部分内核版本无法通过 apt-get install linux-headers-$(uname -r) 来进行安装,以下通过deb包安装内核头文件来安装内核头文件:
# cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
# uname -r
5.15.0-118-generic
# apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-headers-5.15.0-118-generic is already the newest version (5.15.0-118.128).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
linux-headers-5.15.0-118-generic : Depends: linux-headers-5.15.0-118 but it is not installable
linux-headers-5.15.0-124-generic : Depends: linux-headers-5.15.0-124 but it is not installable
linux-headers-5.15.0-125-generic : Depends: linux-headers-5.15.0-125 but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
# apt-get install linux-headers-5.15.0-118
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package linux-headers-5.15.0-118 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'linux-headers-5.15.0-118' has no installation candidate
一、Ubuntu16.04
Ubuntu16.04部分内核版本无法通过 apt-get install linux-headers-$(uname -r) 来进行安装:
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.5 LTS"
# uname -r
4.15.0-29-generic
# apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package linux-headers-4.15.0-29-generic is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'linux-headers-4.15.0-29-generic' has no installation candidate
# dpkg-query -s linux-headers-$(uname -r)
dpkg-query: package 'linux-headers-4.15.0-29-generic' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
# dpkg-query -l "linux-headers*"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=====================================-=======================-=======================-===============================================================
un linux-headers <none> <none> (no description available)
un linux-headers-3.0 <none> <none> (no description available)
ii linux-headers-4.15.0-29 4.15.0-29.31 all Header files related to Linux kernel version 4.15.0
un linux-headers-4.15.0-29-generic <none> <none> (no description available)
ii linux-headers-4.4.0-131 4.4.0-131.157 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-131-generic 4.4.0-131.157 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-generic 4.4.0.131.137 amd64 Generic Linux kernel headers
因此我们得去对应的官网找.deb来进行安装。
通过deb包安装内核头文件
官网找.deb来进行安装:
阿里云官网:https://mirrors.aliyun.com/ubuntu/pool/main/l/linux/找到以下安装包:
# dpkg -i *.deb
(Reading database ... 83994 files and directories currently installed.)
Preparing to unpack linux-headers-4.15.0-29_4.15.0-29.31_all.deb ...
Unpacking linux-headers-4.15.0-29 (4.15.0-29.31) over (4.15.0-29.31) ...
Selecting previously unselected package linux-headers-4.15.0-29-generic.
Preparing to unpack linux-headers-4.15.0-29-generic_4.15.0-29.31_amd64.deb ...
Unpacking linux-headers-4.15.0-29-generic (4.15.0-29.31) ...
Preparing to unpack linux-image-unsigned-4.15.0-29-generic_4.15.0-29.31_amd64.deb ...
Unpacking linux-image-unsigned-4.15.0-29-generic (4.15.0-29.31) over (4.15.0-29.31) ...
Preparing to unpack linux-modules-4.15.0-29-generic_4.15.0-29.31_amd64.deb ...
Unpacking linux-modules-4.15.0-29-generic (4.15.0-29.31) over (4.15.0-29.31) ...
Setting up linux-headers-4.15.0-29 (4.15.0-29.31) ...
dpkg: dependency problems prevent configuration of linux-headers-4.15.0-29-generic:
linux-headers-4.15.0-29-generic depends on libssl1.1 (>= 1.1.0); however:
Package libssl1.1 is not installed.
dpkg: error processing package linux-headers-4.15.0-29-generic (--install):
dependency problems - leaving unconfigured
Setting up linux-modules-4.15.0-29-generic (4.15.0-29.31) ...
Setting up linux-image-unsigned-4.15.0-29-generic (4.15.0-29.31) ...
Processing triggers for linux-image-unsigned-4.15.0-29-generic (4.15.0-29.31) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-29-generic
出现:
dpkg: dependency problems prevent configuration of linux-headers-4.15.0-29-generic:
linux-headers-4.15.0-29-generic depends on libssl1.1 (>= 1.1.0); however:
Package libssl1.1 is not installed.
去下载 libssl1.1 deb安装包进行安装:
http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/
# dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
# dpkg -i *.deb
......
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /vmlinuz-4.15.0-29-generic
Found kernel: /vmlinuz-4.4.0-131-generic
Found kernel: /vmlinuz-4.15.0-29-generic
Found kernel: /vmlinuz-4.4.0-131-generic
Updating /boot/grub/menu.lst ... done
/etc/kernel/postinst.d/zz-update-grub:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-29-generic
Found initrd image: /boot/initrd.img-4.15.0-29-generic
Found linux image: /boot/vmlinuz-4.4.0-131-generic
Found initrd image: /boot/initrd.img-4.4.0-131-generic
done
# dpkg-query -l "linux-headers*"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================-======================-======================-==========================================================================
un linux-headers <none> <none> (no description available)
un linux-headers-3.0 <none> <none> (no description available)
ii linux-headers-4.15.0-29 4.15.0-29.31 all Header files related to Linux kernel version 4.15.0
ii linux-headers-4.15.0-29-generic 4.15.0-29.31 amd64 Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-131 4.4.0-131.157 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-131-generic 4.4.0-131.157 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-generic 4.4.0.131.137 amd64 Generic Linux kernel headers
# dpkg --get-selections |grep linux
console-setup-linux install
libselinux1:amd64 install
linux-base install
linux-firmware install
linux-generic install
linux-headers-4.15.0-29 install
linux-headers-4.15.0-29-generic install
linux-headers-4.4.0-131 install
linux-headers-4.4.0-131-generic install
......
安装成功。
二、Ubuntu20.04
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
# apt-get install linux-headers-5.15.0-139-generic
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-5.15.0-139-generic
E: Couldn't find any package by glob 'linux-headers-5.15.0-139-generic'
E: Couldn't find any package by regex 'linux-headers-5.15.0-139-generic'
官网找.deb来进行安装:
阿里云官网:https://mirrors.aliyun.com/ubuntu/pool/main/l/linux/找到以下安装包:
# dpkg -i *.deb
Selecting previously unselected package linux-headers-5.4.0-139.
(Reading database ... 324694 files and directories currently installed.)
Preparing to unpack linux-headers-5.4.0-139_5.4.0-139.156_all.deb ...
Unpacking linux-headers-5.4.0-139 (5.4.0-139.156) ...
Selecting previously unselected package linux-headers-5.4.0-139-generic.
Preparing to unpack linux-headers-5.4.0-139-generic_5.4.0-139.156_amd64.deb ...
Unpacking linux-headers-5.4.0-139-generic (5.4.0-139.156) ...
Selecting previously unselected package linux-image-unsigned-5.4.0-139-generic.
Preparing to unpack linux-image-unsigned-5.4.0-139-generic_5.4.0-139.156_amd64.deb ...
Unpacking linux-image-unsigned-5.4.0-139-generic (5.4.0-139.156) ...
Selecting previously unselected package linux-modules-5.4.0-139-generic.
Preparing to unpack linux-modules-5.4.0-139-generic_5.4.0-139.156_amd64.deb ...
Unpacking linux-modules-5.4.0-139-generic (5.4.0-139.156) ...
Setting up linux-headers-5.4.0-139 (5.4.0-139.156) ...
Setting up linux-headers-5.4.0-139-generic (5.4.0-139.156) ...
Setting up linux-modules-5.4.0-139-generic (5.4.0-139.156) ...
Setting up linux-image-unsigned-5.4.0-139-generic (5.4.0-139.156) ...
I: /boot/vmlinuz.old is now a symlink to vmlinuz-5.4.0-164-generic
I: /boot/initrd.img.old is now a symlink to initrd.img-5.4.0-164-generic
I: /boot/vmlinuz is now a symlink to vmlinuz-5.4.0-139-generic
I: /boot/initrd.img is now a symlink to initrd.img-5.4.0-139-generic
Processing triggers for linux-image-unsigned-5.4.0-139-generic (5.4.0-139.156) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-139-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
......
Found linux image: /boot/vmlinuz-5.4.0-139-generic
Found initrd image: /boot/initrd.img-5.4.0-139-generic
......
done
(1)两个内核头文件:
# ls -l /usr/src/linux-headers-5.4.0-139
linux-headers-5.4.0-139/ linux-headers-5.4.0-139-generic/
(2)内核镜像:
/boot/vmlinuz-5.4.0-139-generic
/boot/initrd.img-5.4.0-139-generic
/boot/System.map-5.4.0-139-generic
/boot/config-5.4.0-139-generic
(3)内核模块:
# ls -l /lib/modules/5.4.0-139-generic/
total 1468
lrwxrwxrwx 1 root root 40 Jan 20 2023 build -> /usr/src/linux-headers-5.4.0-139-generic
drwxr-xr-x 2 root root 4096 Jan 20 2023 initrd
drwxr-xr-x 12 root root 4096 Nov 12 02:49 kernel
-rw-r--r-- 1 root root 146836 Nov 12 02:49 modules.alias
-rw-r--r-- 1 root root 157058 Nov 12 02:49 modules.alias.bin
-rw-r--r-- 1 root root 8105 Jan 20 2023 modules.builtin
-rw-r--r-- 1 root root 25062 Nov 12 02:49 modules.builtin.alias.bin
-rw-r--r-- 1 root root 10257 Nov 12 02:49 modules.builtin.bin
-rw-r--r-- 1 root root 64088 Jan 20 2023 modules.builtin.modinfo
-rw-r--r-- 1 root root 86599 Nov 12 02:49 modules.dep
-rw-r--r-- 1 root root 125246 Nov 12 02:49 modules.dep.bin
-rw-r--r-- 1 root root 268 Nov 12 02:49 modules.devname
-rw-r--r-- 1 root root 220047 Jan 20 2023 modules.order
-rw-r--r-- 1 root root 489 Nov 12 02:49 modules.softdep
-rw-r--r-- 1 root root 285493 Nov 12 02:49 modules.symbols
-rw-r--r-- 1 root root 333939 Nov 12 02:49 modules.symbols.bin
drwxr-xr-x 3 root root 4096 Nov 12 02:49 vdso
$ uname -r
5.4.0-139-generic
三、Ubuntu22.04
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.5 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
$ uname -r
6.8.0-45-generic
与上述相同:
官网找.deb来进行安装:
阿里云官网:https://mirrors.aliyun.com/ubuntu/pool/main/l/linux/找到以下安装包,这里已内核头文件例:
下载这两个.deb包后:
# dpkg -i *.deb
$ ls -l /usr/src/linux-headers-6.8.0-45
linux-headers-6.8.0-45/ linux-headers-6.8.0-45-generic/