§2023-10-31
How to get linux kernel source
?
- 機器: odroid-n2, running Ubuntu Jammy 22.04
nano /etc/apt/sources.list
- uncomment the following lines
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ jammy main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports jammy-security universe
deb http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse
sudo apt update
3)apt-cache search linux-source
$ apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-5.15.0 - Linux kernel source for version 5.15.0 with Ubuntu patches
linux-source-5.19.0 - Linux kernel source for version 5.19.0 with Ubuntu patches
linux-source-6.2.0 - Linux kernel source for version 6.2.0 with Ubuntu patches
alexlai@n2JamGen:~/build/src$ apt source linux-source-5.15.0
<-- no sudo
$ mkdir -p build/src && cd $_
$ sudo apt install dpkg-dev
$ apt source linux-source-5.15.0 <-- no sudo
alexlai@n2JamGen:~/build/src$ ls -l
total 201216
drwxrwxr-x 28 alexlai alexlai 4096 Nov 12 09:48 linux-5.15.0
-rw-r--r-- 1 alexlai alexlai 11055970 Oct 5 20:19 linux_5.15.0-88.98.diff.gz
-rw-r--r-- 1 alexlai alexlai 7735 Oct 5 20:19 linux_5.15.0-88.98.dsc
-rw-r--r-- 1 alexlai alexlai 194969557 Nov 18 2021 linux_5.15.0.orig.tar.gz
$ sudo apt install dpkg-dev apt-get source linux-source-$(uname -r) <-- OK
alexlai@n2JamGen:~/build/src$ ls -l
total 196068
drwxrwxr-x 27 alexlai alexlai 4096 Oct 31 16:35 linux-5.15.0 <-- this is the kernel directory
-rw-r--r-- 1 alexlai alexlai 5785458 Apr 1 2022 linux_5.15.0-25.25.diff.gz
-rw-r--r-- 1 alexlai alexlai 7228 Apr 1 2022 linux_5.15.0-25.25.dsc
-rw-r--r-- 1 alexlai alexlai 194969557 Nov 18 2021 linux_5.15.0.orig.tar.gz
-
sudo apt-get build-dep linux linux-image-$(uname -r)
make kernel required packages -
make
cd linux-5.15.0 cp -v /boot/config-$(uname -r) .config
alexlai@n2JamGen:~/build/src/linux-5.15.0$ chmod a+x scripts/pahole-flags.sh
alexlai@n2JamGen:~/build/src/linux-5.15.0$ chmod a+x scripts/pahole-version.sh
$ sudo apt install libncurses-dev
$ make oldconfig
$ make menuconfig
$ time make -j6
real 056m3.925s
user 299m38.394s
sys 31m41.040s
- make modules_install
alexlai@n2JamGen:~/build/src/linux-5.15.0$ ls /lib/modules
5.15.0-odroid-arm64
alexlai@n2JamGen:~/build/src/linux-5.15.0$ sudo make modules_install
...
INSTALL /lib/modules/5.15.126/kernel/sound/usb/misc/snd-ua101.ko
INSTALL /lib/modules/5.15.126/kernel/sound/usb/snd-usb-audio.ko
INSTALL /lib/modules/5.15.126/kernel/sound/usb/snd-usbmidi-lib.ko
DEPMOD /lib/modules/5.15.126
alexlai@n2JamGen:~/build/src/linux-5.15.0$ ls /lib/modules
5.15.0-odroid-arm64 5.15.126
- make install
alexlai@n2JamGen:~/build/src/linux-5.15.0$ ls -l /boot/
total 28356
-rw-r--r-- 1 root root 4516 Nov 12 09:33 boot.scr
-rw-r--r-- 1 root root 4490 Nov 12 08:37 boot.scr.bak
-rw-r--r-- 1 root root 4444 Nov 12 09:33 boot.script
-rw-r--r-- 1 root root 4490 Nov 12 09:32 boot.scr.ori
-rw-r--r-- 1 root root 220943 Jun 23 17:13 config-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 237 Nov 12 08:30 config.ini
lrwxrwxrwx 1 root root 58 Nov 12 08:37 dtb -> dtbs/5.15.0-odroid-arm64/amlogic/meson64_odroidn2_plus.dtb
lrwxrwxrwx 1 root root 58 Nov 12 08:37 dtb-5.15.0-odroid-arm64 -> dtbs/5.15.0-odroid-arm64/amlogic/meson64_odroidn2_plus.dtb
drwxr-xr-x 3 root root 4096 Nov 12 08:31 dtbs
lrwxrwxrwx 1 root root 30 Nov 12 08:31 initrd.img -> initrd.img-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 11759126 Nov 12 08:37 initrd.img-5.15.0-odroid-arm64
lrwxrwxrwx 1 root root 30 Nov 12 08:31 initrd.img.old -> initrd.img-5.15.0-odroid-arm64
drwx------ 2 root root 16384 Nov 12 08:24 lost+found
lrwxrwxrwx 1 root root 41 Nov 12 08:37 overlays -> dtbs/5.15.0-odroid-arm64/amlogic/overlays
-rw-r--r-- 1 root root 5487786 Jun 23 17:13 System.map-5.15.0-odroid-arm64
lrwxrwxrwx 1 root root 27 Nov 12 08:31 vmlinuz -> vmlinuz-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 11508233 Jun 23 17:13 vmlinuz-5.15.0-odroid-arm64
lrwxrwxrwx 1 root root 27 Nov 12 08:31 vmlinuz.old -> vmlinuz-5.15.0-odroid-arm64
alexlai@n2JamGen:~/build/src/linux-5.15.0$ ls -l /boot/
total 28356
-rw-r--r-- 1 root root 4516 Nov 12 09:33 boot.scr
-rw-r--r-- 1 root root 4490 Nov 12 08:37 boot.scr.bak
-rw-r--r-- 1 root root 4444 Nov 12 09:33 boot.script
-rw-r--r-- 1 root root 4490 Nov 12 09:32 boot.scr.ori
-rw-r--r-- 1 root root 220943 Jun 23 17:13 config-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 237 Nov 12 08:30 config.ini
lrwxrwxrwx 1 root root 58 Nov 12 08:37 dtb -> dtbs/5.15.0-odroid-arm64/amlogic/meson64_odroidn2_plus.dtb
lrwxrwxrwx 1 root root 58 Nov 12 08:37 dtb-5.15.0-odroid-arm64 -> dtbs/5.15.0-odroid-arm64/amlogic/meson64_odroidn2_plus.dtb
drwxr-xr-x 3 root root 4096 Nov 12 08:31 dtbs
lrwxrwxrwx 1 root root 30 Nov 12 08:31 initrd.img -> initrd.img-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 11759126 Nov 12 08:37 initrd.img-5.15.0-odroid-arm64
lrwxrwxrwx 1 root root 30 Nov 12 08:31 initrd.img.old -> initrd.img-5.15.0-odroid-arm64
drwx------ 2 root root 16384 Nov 12 08:24 lost+found
lrwxrwxrwx 1 root root 41 Nov 12 08:37 overlays -> dtbs/5.15.0-odroid-arm64/amlogic/overlays
-rw-r--r-- 1 root root 5487786 Jun 23 17:13 System.map-5.15.0-odroid-arm64
lrwxrwxrwx 1 root root 27 Nov 12 08:31 vmlinuz -> vmlinuz-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 11508233 Jun 23 17:13 vmlinuz-5.15.0-odroid-arm64
lrwxrwxrwx 1 root root 27 Nov 12 08:31 vmlinuz.old -> vmlinuz-5.15.0-odroid-arm64
alexlai@n2JamGen:~/build/src/linux-5.15.0$ sudo make install
sh ./arch/arm64/boot/install.sh 5.15.126 \
arch/arm64/boot/Image System.map "/boot"
run-parts: executing /etc/kernel/postinst.d/dkms 5.15.126 /boot/vmlinuz-5.15.126
* dkms: running auto installation service for kernel 5.15.126 [ OK ]
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 5.15.126 /boot/vmlinuz-5.15.126
update-initramfs: Generating /boot/initrd.img-5.15.126
Using DTB: amlogic/meson64_odroidn2_plus.dtb
Couldn't find DTB meson64_odroidn2_plus.dtb in /usr/lib/linux-image-5.15.126 or /etc/flash-kernel/dtbs
Couldn't find DTB files in /usr/lib/linux-image-5.15.126/amlogic
run-parts: /etc/initramfs/post-update.d//flash-kernel exited with return code 1
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
make: *** [arch/arm64/Makefile:163: install] Error 1
alexlai@n2JamGen:~/build/src/linux-5.15.0$ ls -l /boot
total 72660
-rw-r--r-- 1 root root 4516 Nov 12 09:33 boot.scr
-rw-r--r-- 1 root root 4490 Nov 12 08:37 boot.scr.bak
-rw-r--r-- 1 root root 4444 Nov 12 09:33 boot.script
-rw-r--r-- 1 root root 4490 Nov 12 09:32 boot.scr.ori
-rw-r--r-- 1 root root 220943 Jun 23 17:13 config-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 221407 Nov 12 11:14 config-5.15.126
-rw-r--r-- 1 root root 237 Nov 12 08:30 config.ini
lrwxrwxrwx 1 root root 58 Nov 12 08:37 dtb -> dtbs/5.15.0-odroid-arm64/amlogic/meson64_odroidn2_plus.dtb
lrwxrwxrwx 1 root root 58 Nov 12 08:37 dtb-5.15.0-odroid-arm64 -> dtbs/5.15.0-odroid-arm64/amlogic/meson64_odroidn2_plus.dtb
drwxr-xr-x 3 root root 4096 Nov 12 08:31 dtbs
lrwxrwxrwx 1 root root 30 Nov 12 08:31 initrd.img -> initrd.img-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 11759126 Nov 12 08:37 initrd.img-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 11781474 Nov 12 11:14 initrd.img-5.15.126
lrwxrwxrwx 1 root root 30 Nov 12 08:31 initrd.img.old -> initrd.img-5.15.0-odroid-arm64
drwx------ 2 root root 16384 Nov 12 08:24 lost+found
lrwxrwxrwx 1 root root 41 Nov 12 08:37 overlays -> dtbs/5.15.0-odroid-arm64/amlogic/overlays
-rw-r--r-- 1 root root 5487786 Jun 23 17:13 System.map-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 5498600 Nov 12 11:14 System.map-5.15.126
lrwxrwxrwx 1 root root 16 Nov 12 11:14 vmlinuz -> vmlinuz-5.15.126
-rw-r--r-- 1 root root 11508233 Jun 23 17:13 vmlinuz-5.15.0-odroid-arm64
-rw-r--r-- 1 root root 27854856 Nov 12 11:14 vmlinuz-5.15.126
lrwxrwxrwx 1 root root 27 Nov 12 08:31 vmlinuz.old -> vmlinuz-5.15.0-odroid-arm64
- modify boot.scripts
if test -z "${fk_kvers}"; then
# setenv fk_kvers "5.15.0-odroid-arm64"
setenv fk_kvers "5.15.126"
alexlai@n2JamGen:/boot$ sudo mkimage -A arm -T script -C none -n "Ubuntu boot script" -d boot.script boot.scr
Image Name: Ubuntu boot script
Created: Sun Nov 12 11:19:21 2023
Image Type: ARM Linux Script (uncompressed)
Data Size: 4484 Bytes = 4.38 KiB = 0.00 MiB
Load Address: 00000000
Entry Point: 00000000
Contents:
Image 0: 4476 Bytes = 4.37 KiB = 0.00 MiB