---
tags: Raspberry
---
# Raspberry Pi study:有關Kernel 的兩三事......
linux
https://www.raspberrypi.org/documentation/linux/
kernel:
https://www.raspberrypi.org/documentation/linux/kernel/
https://ithelp.ithome.com.tw/articles/10238166
---
## File system hierarchy:
- bin: 執行檔(ls,mv,gzip...)存放的地方
- boot: 開機相關檔案
- dev: 裝置有關的檔案
- etc: 系統在開機過程中需要讀取的檔案均在這個目錄中,例如:人員的帳號與密碼,系統的主要設定,http 架站的參數內容,你所要開啟的服務項目等等.
/etc/rc.d: 記錄一些開關機過程中的 scripts 檔案
- home
- lib: Linux 執行或編譯核心的時候,均會使用到一些函式庫(library),就在這個目錄下
- lost+found: 系統不正常產生錯誤時,會將一些遺失的片段放置於此目錄下,通常這個目錄會自動出現在裝置目錄下.例如你加裝一棵硬碟於 /disk 中,那在這個目錄下就會自動產生一個這樣的目錄 /disk/lost+found.
- media:
- mnt: 這是軟碟與光碟接掛點的地方通常軟碟掛在 /mnt/floppy 下,而光碟掛在 /mnt/cdrom 下.
- opt:
- proc: 系統核心與執行程序的一些資訊
- root: 系統管理員的家目錄
- sbin: 放置一些系統管理常用的程式,例如: fdisk,mke2fs,fsck,mkswap,mount 等等
- selinux:
- srv:
- sys:虛擬檔案系統(sysfs)
- tmp:這是讓一般使用者暫時存放檔案的地方,例如你在安裝 Linux 下的軟體時,可能軟體預設的工作目錄就是 /tmp,所以你要定期的清理一下,重要資料最好不要放在這裡.
- usr:裡面含有相當多的系統資訊,內有許多目錄,用來存放程式與指令
usr/bin: 放置可執行檔
usr/include: C的header檔
usr/lib: 內含許多程式與子程式所需的函式庫
usr/local: 在你安裝完了 Linux 之後,基本上所有的配備你都有了,但是軟體總是可以升級的,
例如:你要升級你的 proxy 服務,則通常軟體預設的安裝地方就是在 /usr/local 中
(local 是『當地』的意思),同時,安裝完畢之後所得到的執行檔,為了與系統原先
的執行檔有分別,因此升級後的執行檔通 常擺在 /usr/local/bin 這個地方
/usr/doc
/usr/man: 說明檔
/usr/src:原始檔預設目錄
- var:這是系統在工作時,預設的工作目錄,例如這架主機使用者的登錄檔案資訊,尚未寄出的郵件存放地,接收的郵件放置處等等
---
## update soft-ware
- sudo apt update
- sudo apt full-upgrade
Also be aware that downloaded package files (.deb files) are kept in /var/cache/apt/archives. You can remove these in order to free up space with sudo apt clean (sudo apt-get clean in older releases of apt).
doing this regularly will keep your installation up to date for the particular major Raspberry Pi OS release you are using (e.g. Stretch). It will not update from one major release to another, for example, Stretch to Buster.
---
## Kernel
### updte kernel and firmware
To upgrade, first modify the files /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list. In both files, change every occurrence of the word stretch to buster. (Both files will require sudo to edit.)
- sudo apt update
- sudo apt -y dist-upgrade
Finally, if you are not using PulseAudio for anything other than Bluetooth audio, remove it from the image by entering: apt-get -y purge "pulseaudio"
@@@
the rpi-update script is supplied by a third party, "Hexxeh", and also supported by Raspberry Pi engineers
- sudo rpi-update
- sudo reboot
If you have done an rpi-update and things are not working as you wish, if your Raspberry Pi is still bootable you can return to the stable release using:
- sudo apt-get update
- sudo apt install --reinstall libraspberrypi0 libraspberrypi-{bin,dev,doc} raspberrypi-bootloader raspberrypi-kernel
@@@
use Raspberry Pi Kernel respoitory
https://www.raspberrypi.org/documentation/linux/kernel/building.md
### building a new kernel
https://www.raspberrypi.org/documentation/linux/kernel/building.md
### configuring the kernel
https://www.raspberrypi.org/documentation/linux/kernel/configuring.md
### Applying patches to the kernel
https://www.raspberrypi.org/documentation/linux/kernel/patching.md
### getting the kernel headers
https://www.raspberrypi.org/documentation/linux/kernel/headers.md
---
## 編譯核心
### 查看核心組態
- sudo modprobe configs
- zcat /proc/config.gz > ./config
- cat ./config
使用 cat ./config | grep BPF 找到所需組態
### 編譯
First install Git and the build dependencies:
- sudo apt install git bc bison flex libssl-dev make
get the sources, which will take some time:
- git clone --depth=1 https://github.com/raspberrypi/linux
如果在 GitHub 上看到某個專案很有趣,想要下載回來看看,只要使用 Clone 指令就可以把整個專案複製一份回來了
Kernel configuration
- cd linux
- KERNEL=kernel7
- make bcm2709_defconfig
調整核心組態
暴力修改.config檔或使用memuconfig
- sudo apt install libncurses-dev (安裝 libcurses )
- make menuconfig
-
按 / 可搜尋,所需修改的地方(找紅色框字的地方)

去 General Setup 中的 Local Version 改一個喜歡的版本儲存
- make -j4 zImage modules dtbs 要跑好幾個小時
@@@
換上新核心
- sudo make modules_install
- sudo cp arch/arm/boot/dts/*.dtb /boot/
- sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
- sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
編完的核心是那個 arch/arm/boot/zImage
- udo cp arch/arm/boot/zImage /boot/kernelebpf.img (名字換成 kernelebpf.img)
修改 /boot/config.txt 中的 kernel 選項,把他改成新的核心
- sudo vim /boot/config.txt

- sudo reboot
失敗....再來要如何編譯呢??