Skip to content

Commit

Permalink
update kernel compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Jan 24, 2022
1 parent 03d16a0 commit eabe120
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 162 deletions.
8 changes: 4 additions & 4 deletions compile-kernel/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@

- ### 本地编译

1. 请在你的盒子中安装 Armbian 系统,并安装以下依赖环境。
1. 安装必要的软件包(脚本仅在 Ubuntu_20.04-x86_64 下做过测试)

```yaml
sudo apt-get update -y
sudo apt-get full-upgrade -y
sudo apt-get install -y $(curl -fsSL git.io/armbian-kernel-server)
sudo apt-get install -y $(curl -fsSL git.io/ubuntu-2004-server)
```

2. 克隆仓库到本地 `git clone --depth 1 https://github.com/ophub/amlogic-s9xxx-armbian.git`

3. 首先在 `~/amlogic-s9xxx-armbian/compile-kernel` 目录下创建 `kernel` 目录,用于存放编译的内核源码。如采用 [kernel.org](https://cdn.kernel.org/pub/linux/kernel/v5.x/) 的源码进行编译,请下载对应的内核如 `linux-5.4.170.tar.xz` 并解压到对应的 `compile-kernel/kernel/linux-5.4.170` 目录下;如采用 [unifreq](https://github.com/unifreq) 的源码进行编译,请克隆指定内核系列的源码如 `git clone --depth 1 https://github.com/unifreq/linux-5.4.y compile-kernel/kernel/linux-5.4.y` 到对应的目录下。完成后进入对应的内核如 `compile-kernel/kernel/linux-5.4.170` 的目录下,复制对应的内核系列的 [.config](tools/config) 模板到当前内核目录(如复制 config-5.4.170 文件,并重命名为 `.config`),并运行个性化配置选择命令 `make menuconfig` 进行自定义选择,完成后保存,会在内核目录下生成自定义的内核 `.config` 配置文件。

4. 进入 `~/amlogic-s9xxx-armbian` 根目录,然后运行 `sudo ./recompile -d -k 5.4.170 -r unifreq -a false` 等指定参数命令即可编译内核。打包好的内核文件保存在 `compile-kernel/output` 目录里。
4. 进入 `~/amlogic-s9xxx-armbian` 根目录,然后运行 `sudo ./recompile -d -k 5.4.170` 等指定参数命令即可编译内核。打包好的内核文件保存在 `compile-kernel/output` 目录里。

- ### 使用 GitHub Action 进行编译

Expand All @@ -50,7 +50,7 @@ sudo apt-get install -y $(curl -fsSL git.io/armbian-kernel-server)

2. 如果本地的内核目录如 `compile-kernel/kernel/linux-5.4.170` 中没有 [.config](tools/config) 文件,将自动从 unifreq 分享的模板中复制相同内核系列的配置文件。

3. 目前在 `Armbian` 系统下编译内核是最好的选择,强烈推荐。在 `x86_64` 环境下编译内核时,会自动下载 Armbian 系统,并通过 chroot 实现 `uInitrd` 文件的生成。内核编译完成后,将会按照 `unifreq` 分享的内核文件的组织方式自动打包成 6 个内核文件,并存放在 `compile-kernel/output` 目录下。这些内核文件会自动从当前内核编译的系统中自动清除。如果你想在当前 Armbian 系统安装,可进入对应的内核目录如 `compile-kernel/output/5.4.170` 下,执行 `armbian-update` 命令进行内核安装。内核中的 `headers` 文件默认安装在 `/use/local/include` 目录下。
3. 内核编译完成后,将会按照 `unifreq` 分享的内核文件的组织方式自动打包成 6 个内核文件,并存放在 `compile-kernel/output` 目录下。这些内核文件会自动从当前内核编译的系统中自动清除。如果你想在当前 Armbian 系统安装,可进入对应的内核目录如 `compile-kernel/output/5.4.170` 下,执行 `armbian-update` 命令进行内核安装。内核中的 `headers` 文件默认安装在 `/use/local/include` 目录下。

4. 如果当前 `Armbian` 系统中已经安装了相同名称的内核如 `5.4.170-meson64-dev` ,将会自动停止编译,因为打包时会删除本地相同名称的内核文件,这么做会造成系统瘫痪。

Expand Down
8 changes: 4 additions & 4 deletions compile-kernel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ Compile a custom kernel as needed. This kernel can be used in [Armbian](https://

- ### Local compilation

1. Please install the Armbian system in your box and install the following dependent environment.
1. Install the necessary packages (The script has only been tested on Ubuntu_20.04-x86_64)

```yaml
sudo apt-get update -y
sudo apt-get full-upgrade -y
sudo apt-get install -y $(curl -fsSL git.io/armbian-kernel-server)
sudo apt-get install -y $(curl -fsSL git.io/ubuntu-2004-server)
```

2. Clone the repository to local: `git clone --depth 1 https://github.com/ophub/amlogic-s9xxx-armbian.git`

3. First create a `kernel` directory under the `~/amlogic-s9xxx-armbian/compile-kernel` directory to store the compiled kernel source code. For example, use the source code of [kernel.org](https://cdn.kernel.org/pub/linux/kernel/v5.x/) to compile, Please download the corresponding kernel such as `linux-5.4.170.tar.xz` and unzip it to the `compile-kernel/kernel/linux-5.4.170` corresponding directory; If you use the source code of [unifreq](https://github.com/unifreq) to compile, Please clone the source code of the specified kernel series such as `git clone --depth 1 https://github.com/unifreq/linux-5.4.y compile-kernel/kernel/linux-5.4.y` to the corresponding directory. After completion, enter the corresponding kernel such as `compile-kernel/kernel/linux-5.4.170` directory, Copy the [.config](tools/config) template of the corresponding kernel series to the current kernel directory (For example, copy the config-5.4.170 file and rename it to `.config`), Then run the personalized configuration selection command `make menuconfig` to Make a custom selection, save it after completion, A custom kernel `.config` configuration file will be generated in the kernel directory.

4. Enter the root directory of `~/amlogic-s9xxx-armbian`, and then run `sudo ./recompile -d -k 5.4.170 -r unifreq -a false` and other specified parameter commands to compile the kernel. The packaged kernel file is stored in the `compile-kernel/output` directory.
4. Enter the root directory of `~/amlogic-s9xxx-armbian`, and then run `sudo ./recompile -d -k 5.4.170` and other specified parameter commands to compile the kernel. The packaged kernel file is stored in the `compile-kernel/output` directory.

- ### Compile with GitHub Action

Expand All @@ -50,7 +50,7 @@ sudo apt-get install -y $(curl -fsSL git.io/armbian-kernel-server)

2. If there is no [.config](tools/config) file in the local kernel directory such as `compile-kernel/kernel/linux-5.4.170`, the file will be automatically copied from template.

3. Currently, compiling the kernel under the `Armbian` system is the best choice, and it is highly recommended. When compiling the kernel under the `x86_64` environment, the Armbian system will be automatically downloaded, and the `uInitrd` file will be generated through chroot. After the kernel is compiled, it will be automatically packaged into 6 kernel files according to the organization of the kernel files shared by `unifreq` and stored in the `compile-kernel/output` directory. These kernel files will be automatically cleared from the system compiled with the current kernel. If you want to install on the current Armbian system, you can enter the corresponding kernel directory such as `compile-kernel/output/5.4.170` and execute the `armbian-update` command to install the kernel. The `headers` files in the kernel is installed in the `/use/local/include` directory.
3. After the kernel is compiled, it will be automatically packaged into 6 kernel files according to the organization of the kernel files shared by `unifreq` and stored in the `compile-kernel/output` directory. These kernel files will be automatically cleared from the system compiled with the current kernel. If you want to install on the current Armbian system, you can enter the corresponding kernel directory such as `compile-kernel/output/5.4.170` and execute the `armbian-update` command to install the kernel. The `headers` files in the kernel is installed in the `/use/local/include` directory.

4. If a kernel with the same name such as `5.4.170-meson64-dev` is already installed in the current `Armbian` system, the compilation will automatically stop, because the local kernel file with the same name will be deleted during packaging, which will cause the system to crash.

Expand Down
11 changes: 3 additions & 8 deletions compile-kernel/tools/script/generate_uinitrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,19 @@ chroot_generate_uinitrd() {
echo -e "${STEPS} Generate uInitrd file."
#echo -e "${INFO} File status in the /boot directory before the update: \n$(ls -l .) \n"

# Backup the original uInitrd file
[ -f uInitrd ] && mv -f uInitrd uInitrd.bak 2>/dev/null
[ ! -f zImage ] && cp -f vmlinuz-${chroot_kernel_version} zImage 2>/dev/null && sync
cp -f vmlinuz-${chroot_kernel_version} zImage 2>/dev/null && sync

# Generate uInitrd file directly under armbian system
update-initramfs -c -k ${chroot_kernel_version} 2>/dev/null

if [ -f uInitrd ]; then
echo -e "${SUCCESS} The uInitrd file is Successfully generated."
echo -e "${SUCCESS} The initrd.img and uInitrd file is Successfully generated."
mv -f uInitrd uInitrd-${chroot_kernel_version} 2>/dev/null && sync
else
echo -e "${WARNING} The uInitrd file not updated."
echo -e "${WARNING} The initrd.img and uInitrd file not updated."
fi

echo -e "${INFO} File situation in the /boot directory after update: \n$(ls -l *${chroot_kernel_version}) \n"

# Restore the original uInitrd
[ -f uInitrd.bak ] && mv -f uInitrd.bak uInitrd 2>/dev/null
}

#chroot_env_init
Expand Down
Loading

0 comments on commit eabe120

Please sign in to comment.