Ubuntu Build Original Linux Kernel

最好的方式應該是這一篇文章

不要再用什麼 fakeroot 去編了, 失敗率超高, 尤其是在 ARM 平台

https://wiki.ubuntu.com/KernelTeam/GitKernelBuild

來個範例, 在 ARM64 上編了 4.10~4.17 其中幾個版本, 每次都成功

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
git checkout -b 4.17 v4.17
cp /boot/config-`uname -r` .config
yes '' | make oldconfig
make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-custom

不知道為什麼,Ubuntu 22.04 Linux kernel 5.19 上這個方法又不行了,可能是因為取用 vanilla Linux kernel git source 的關係

copy /boot/config-5.19 到 Linux 時要注意要移掉認證的 .pem ,要不然會編不過,可能不用移全部,但是懶得試了,patch 如下

@@ -12842,10 +12874,15 @@
 CONFIG_MODULE_SIG_KEY_TYPE_RSA=y
 # CONFIG_MODULE_SIG_KEY_TYPE_ECDSA is not set
 CONFIG_SYSTEM_TRUSTED_KEYRING=y
-CONFIG_SYSTEM_TRUSTED_KEYS=""
-# CONFIG_SYSTEM_EXTRA_CERTIFICATE is not set
-# CONFIG_SECONDARY_TRUSTED_KEYRING is not set
-# CONFIG_SYSTEM_BLACKLIST_KEYRING is not set
+CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
+CONFIG_SYSTEM_EXTRA_CERTIFICATE=y
+CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE=4096
+CONFIG_SECONDARY_TRUSTED_KEYRING=y
+CONFIG_SYSTEM_BLACKLIST_KEYRING=y
+CONFIG_SYSTEM_BLACKLIST_HASH_LIST=""
+CONFIG_SYSTEM_REVOCATION_LIST=y
+CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
+# CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE is not set
 # end of Certificates for signature checking

接下來下面這一段就可以編了,在我的系統上沒問題

fakeroot debian/rules clean
cp /boot/config-`uname -r` .config
yes '' | make oldconfig
make clean
#remove the non git files
git clean -f
rm vmlinux-gdb.py
#make sure there is no linux*.tar too
rm ../linux*.gz

#cherry pick RC6 hack
git cherry-pick 0c6b6fa52c6ad54332eed64acb6aebc59f75e0b2

#
make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-custom
cd ..

不過這是包成 package ,如果只是單純的要改參數開發時開機用,那就直接 make install 就好了,但是抄 ubutnu 的 kernel configure file 檔案會太大,應該是包了 debug info,這時要 strip modules ,以免 ramdisk 太大

make -j `nproc` && make INSTALL_MOD_STRIP=1 modules_install && make install 

ref. ubuntu build kernel from git with a source change, how to ignore ‘unrepresentable changes to source’ error
Why is my initial ramdisk so big?

Related posts

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>