Skip to content

Commit

Permalink
Add compression format options for initrd: -c
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Mar 11, 2024
1 parent d34a8bb commit 3db4851
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/compile-kernel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ on:
options:
- clang
- gcc
compress_format:
description: "Set the initrd compression format"
required: false
default: "xz"
type: choice
options:
- xz
- gzip
- zstd
- lzma
kernel_sign:
description: "Set the kernel custom signature"
required: false
Expand Down Expand Up @@ -136,6 +146,7 @@ jobs:
kernel_package: ${{ inputs.kernel_package }}
kernel_sign: ${{ inputs.kernel_sign }}
kernel_toolchain: ${{ inputs.kernel_toolchain }}
compress_format: ${{ inputs.compress_format }}

- name: Upload Kernel to Release
uses: ncipollo/release-action@main
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ inputs:
description: "Set whether to use kernel patches"
required: false
default: "false"
compress_format:
description: "Set the initrd compression format"
required: false
default: "xz"

runs:
using: "composite"
Expand Down Expand Up @@ -220,6 +224,7 @@ runs:
[[ -n "${{ inputs.auto_patch }}" ]] && make_command="${make_command} -p ${{ inputs.auto_patch }}"
[[ -n "${{ inputs.kernel_sign }}" ]] && make_command="${make_command} -n ${{ inputs.kernel_sign }}"
[[ -n "${{ inputs.kernel_toolchain }}" ]] && make_command="${make_command} -t ${{ inputs.kernel_toolchain }}"
[[ -n "${{ inputs.compress_format }}" ]] && make_command="${make_command} -c ${{ inputs.compress_format }}"
sudo ./recompile ${make_command}
cd ${GITHUB_ACTION_PATH}
Expand Down
2 changes: 2 additions & 0 deletions compile-kernel/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sudo apt-get install -y $(cat compile-kernel/tools/script/ubuntu2204-build-armbi
| -p | AutoPatch | 设置是否使用自定义内核补丁。当设置为 `true` 时将使用 [tools/patch](tools/patch) 目录下的内核补丁,详细说明参考[内核补丁添加方法](../documents/README.cn.md#9-编译-armbian-内核)。默认值:`false` |
| -n | CustomName | 设置内核自定义签名。当设置为 `-ophub` ,生成的内核名称为 `5.15.100-ophub` 。设置自定义签名时请勿包含空格。默认值:`-ophub` |
| -t | Toolchain | 设置编译内核的工具链。可选项:`clang / gcc`。默认值:`gcc` |
| -c | Compress | 设置内核中 initrd 使用的压缩格式。可选项:`xz / gzip / zstd / lzma`。默认值:`xz` |

- `sudo ./recompile` : 使用默认配置编译内核。
- `sudo ./recompile -k 5.15.100` : 使用默认配置,并通过 `-k` 进行指定需要编译的内核版本,多个版本同时编译时使用 `_` 进行连接。
Expand Down Expand Up @@ -92,6 +93,7 @@ uses: YOUR-REPO/amlogic-s9xxx-armbian@main
| kernel_config | false | 默认使用 [tools/config](tools/config) 目录下的配置模板。你可以设置编译内核的配置文件在你仓库中的存放目录,如 `kernel/config_path` 。该目录下存储的配置模板必须以内核的主版本命名,如`config-5.10`、`config-5.15`等。 |
| kernel_patch | false | 设置自定义内核补丁目录。 |
| auto_patch | false | 设置是否使用自定义内核补丁。默认值为 `false`。功能参考 `-p` |
| compress_format | xz | 设置内核中 initrd 使用的压缩格式。默认值为 `xz`。功能参考 `-c` |

- ### GitHub Action 输出变量说明

Expand Down
3 changes: 3 additions & 0 deletions compile-kernel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ sudo apt-get install -y $(cat compile-kernel/tools/script/ubuntu2204-build-armbi
| -p | AutoPatch | Sets whether to use custom kernel patches. When set to `true`, it will use the kernel patches in the [tools/patch](tools/patch) directory. For detailed instructions, refer to [how to add kernel patches](../documents/README.md#9-compiling-armbian-kernel). Default value: `false` |
| -n | CustomName | Sets the custom signature of the kernel. When set to `-ophub`, the generated kernel name is `5.15.100-ophub`. Please do not include spaces when setting custom signatures. Default value: `-ophub` |
| -t | Toolchain | Sets the toolchain for compiling the kernel. Options: `clang / gcc`. Default value: `gcc` |
| -c | Compress | Set the compression format used for initrd in the kernel. Options: `xz / gzip / zstd / lzma`. Default value: `xz` |


- `sudo ./recompile`: Compile the kernel using the default configuration.
- `sudo ./recompile -k 5.15.100`: Use the default configuration and specify the kernel version to be compiled through `-k`. Multiple versions are connected using `_` for simultaneous compilation.
Expand Down Expand Up @@ -93,6 +95,7 @@ These parameters correspond to the `local compilation commands`. Please refer to
| kernel_config | false | By default, use the configuration template in the [tools/config](tools/config) directory. You can set the directory for storing the kernel configuration file in your repository, such as `kernel/config_path`. The configuration templates stored in this directory must be named after the main version of the kernel, such as `config-5.10`, `config-5.15`, etc. |
| kernel_patch | false | Sets the directory for custom kernel patches. |
| auto_patch | false | Sets whether to use custom kernel patches. Default value is `false`. Refer to `-p` for functionality. |
| compress_format | xz | Set the compression format used for initrd in the kernel. Default value is `xz`. Refer to `-c` for functionality. |

- ### GitHub Action Output Variables

Expand Down
15 changes: 13 additions & 2 deletions compile-kernel/tools/script/armbian_compile_kernel_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ auto_patch="false"
custom_name="-ophub"
# Set the kernel compile object, options: [ dtbs / all ]
package_list="all"
# Set the compression format, options: [ gzip / bzip2 / lz4 / lzma / lzop / xz / zstd ]
compress_format="xz"

# Compile toolchain download mirror, run on Armbian
dev_repo="https://github.com/ophub/kernel/releases/download/dev"
Expand Down Expand Up @@ -102,7 +104,7 @@ init_var() {
echo -e "${STEPS} Start Initializing Variables..."

# If it is followed by [ : ], it means that the option requires a parameter value
get_all_ver="$(getopt "k:a:n:m:p:r:t:" "${@}")"
get_all_ver="$(getopt "k:a:n:m:p:r:t:c:" "${@}")"

while [[ -n "${1}" ]]; do
case "${1}" in
Expand Down Expand Up @@ -166,6 +168,14 @@ init_var() {
error_msg "Invalid -t parameter [ ${2} ]!"
fi
;;
-c | --Compress)
if [[ -n "${2}" ]]; then
compress_format="${2}"
shift
else
error_msg "Invalid -c parameter [ ${2} ]!"
fi
;;
*)
error_msg "Invalid option [ ${1} ]!"
;;
Expand Down Expand Up @@ -517,7 +527,7 @@ generate_uinitrd() {
# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ]
compress_initrd_file="/etc/initramfs-tools/initramfs.conf"
sed -i "/^COMPRESS=/d" ${compress_initrd_file}
echo "COMPRESS=xz" >>${compress_initrd_file}
echo "COMPRESS=${compress_format}" >>${compress_initrd_file}

cd /boot
echo -e "${STEPS} Generate uInitrd file..."
Expand Down Expand Up @@ -701,6 +711,7 @@ echo -e "${INFO} Kernel patch: [ ${auto_patch} ]"
echo -e "${INFO} Kernel Package: [ ${package_list} ]"
echo -e "${INFO} kernel signature: [ ${custom_name} ]"
echo -e "${INFO} Latest kernel version: [ ${auto_kernel} ]"
echo -e "${INFO} kernel initrd compress: [ ${compress_format} ]"
echo -e "${INFO} Kernel List: [ $(echo ${build_kernel[*]} | xargs) ] \n"

# Show server start information
Expand Down
15 changes: 13 additions & 2 deletions recompile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ auto_patch="false"
custom_name="-ophub"
# Set the kernel compile object, options: [ dtbs / all ]
package_list="all"
# Set the compression format, options: [ gzip / bzip2 / lz4 / lzma / lzop / xz / zstd ]
compress_format="xz"

# Cross compile toolchain download mirror
dev_repo="https://github.com/ophub/kernel/releases/download/dev"
Expand Down Expand Up @@ -129,7 +131,7 @@ init_var() {
echo -e "${STEPS} Start Initializing Variables..."

# If it is followed by [ : ], it means that the option requires a parameter value
get_all_ver="$(getopt "k:a:n:m:p:r:t:" "${@}")"
get_all_ver="$(getopt "k:a:n:m:p:r:t:c:" "${@}")"

while [[ -n "${1}" ]]; do
case "${1}" in
Expand Down Expand Up @@ -193,6 +195,14 @@ init_var() {
error_msg "Invalid -t parameter [ ${2} ]!"
fi
;;
-c | --Compress)
if [[ -n "${2}" ]]; then
compress_format="${2}"
shift
else
error_msg "Invalid -c parameter [ ${2} ]!"
fi
;;
*)
error_msg "Invalid option [ ${1} ]!"
;;
Expand Down Expand Up @@ -562,7 +572,7 @@ generate_uinitrd() {
# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ]
compress_initrd_file="${tag_rootfs}/etc/initramfs-tools/initramfs.conf"
sed -i "/^COMPRESS=/d" ${compress_initrd_file}
echo "COMPRESS=xz" >>${compress_initrd_file}
echo "COMPRESS=${compress_format}" >>${compress_initrd_file}

[[ -f "/usr/bin/${qemu_binary_arm64}" ]] && cp -f /usr/bin/${qemu_binary_arm64} ${tag_rootfs}/usr/bin/
#echo -e "${INFO} The [ ${qemu_binary_arm64} ] file copy results: \n$(ls -l ${tag_rootfs}/usr/bin/${qemu_binary_arm64}) \n"
Expand Down Expand Up @@ -738,6 +748,7 @@ echo -e "${INFO} Kernel patch: [ ${auto_patch} ]"
echo -e "${INFO} Kernel Package: [ ${package_list} ]"
echo -e "${INFO} kernel signature: [ ${custom_name} ]"
echo -e "${INFO} Latest kernel version: [ ${auto_kernel} ]"
echo -e "${INFO} kernel initrd compress: [ ${compress_format} ]"
echo -e "${INFO} Kernel List: [ $(echo ${build_kernel[@]} | xargs) ] \n"

# Show server start information
Expand Down

0 comments on commit 3db4851

Please sign in to comment.