Use the tool to create a new centos-7 initramfs image with on click. and we also can customize the pre-installed software by configuring ./bin/repolist.
Signed-off-by: Wang Chenglong 18509160991@163.com --- rootfs/initramfs/centos/aarch64/7/README.md | 12 ++++++ rootfs/initramfs/centos/aarch64/7/bin/creat | 38 +++++++++++++++++++ rootfs/initramfs/centos/aarch64/7/bin/dellist | 8 ++++ rootfs/initramfs/centos/aarch64/7/bin/lib | 30 +++++++++++++++ .../initramfs/centos/aarch64/7/bin/repolist | 2 + rootfs/initramfs/centos/aarch64/7/build | 29 ++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 rootfs/initramfs/centos/aarch64/7/README.md create mode 100755 rootfs/initramfs/centos/aarch64/7/bin/creat create mode 100644 rootfs/initramfs/centos/aarch64/7/bin/dellist create mode 100755 rootfs/initramfs/centos/aarch64/7/bin/lib create mode 100644 rootfs/initramfs/centos/aarch64/7/bin/repolist create mode 100755 rootfs/initramfs/centos/aarch64/7/build
diff --git a/rootfs/initramfs/centos/aarch64/7/README.md b/rootfs/initramfs/centos/aarch64/7/README.md new file mode 100644 index 0000000..1e47e11 --- /dev/null +++ b/rootfs/initramfs/centos/aarch64/7/README.md @@ -0,0 +1,12 @@ +# Use the tool to create a new centos-7 initramfs image. + +Usage: + ./build + +Some configuration items: +./bin/repolist + If you want to pre-install the software, you can write the package names in ./bin/repolist. + +./bin/dellist + If you want remove some unnecessary files, you can write the names in ./bin/dellist + diff --git a/rootfs/initramfs/centos/aarch64/7/bin/creat b/rootfs/initramfs/centos/aarch64/7/bin/creat new file mode 100755 index 0000000..4dacbdf --- /dev/null +++ b/rootfs/initramfs/centos/aarch64/7/bin/creat @@ -0,0 +1,38 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +# Configure rootfs +make_rootfs() +{ + yum repolist + yum -y install --skip-broken $(</root/bin/repolist) + yum clean all + rm -rf $(</root/bin/dellist) + ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime + cd /root/modules + zcat modules-5.8.0.1.cgz | cpio -idm +} + +# Config password +pre_config_rootfs() { + [ -n "$ROOT_NEW_PASSWD" ] && { + echo "Changing root password" + passwd_md5=$(openssl passwd -1 "$ROOT_NEW_PASSWD") + sed -i -r "s/^root:[^:]*:(.*)/root:${passwd_md5////\/}:\1/" "$ROOTFS_DIR/etc/shadow" # Change the password in shadow + sed -i 's/[# ]PermitRootLogin.*/PermitRootLogin yes/' "$ROOTFS_DIR/etc/ssh/sshd_config" # Configure ssh service + } +} + +# Pack cgz package +pack_cgz() +{ + echo "Packing package. Please wait." + cd / + find ./ ! -path "./${image_name}" ! -path "./root/modules/modules-5.8.0.1.cgz" | cpio -o -Hnewc | gzip -9 > /${image_name} + chmod 644 /${image_name} +} + +make_rootfs +pre_config_rootfs +pack_cgz diff --git a/rootfs/initramfs/centos/aarch64/7/bin/dellist b/rootfs/initramfs/centos/aarch64/7/bin/dellist new file mode 100644 index 0000000..ce079b9 --- /dev/null +++ b/rootfs/initramfs/centos/aarch64/7/bin/dellist @@ -0,0 +1,8 @@ +/.dockerenv +/lib/modules +/usr/share/doc +/usr/share/man +/usr/share/info +/usr/share/i18n +/usr/share/locale +/usr/share/terminfo diff --git a/rootfs/initramfs/centos/aarch64/7/bin/lib b/rootfs/initramfs/centos/aarch64/7/bin/lib new file mode 100755 index 0000000..1bf0b5d --- /dev/null +++ b/rootfs/initramfs/centos/aarch64/7/bin/lib @@ -0,0 +1,30 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +DIR="$(dirname $(realpath $0))" +name="$(echo $DIR |awk -F "/" '{print $(NF - 2)}')" +version="$(echo $DIR |awk -F "/" '{print $NF}')" +image="${name}:${version}" +image_name="${name}-${version}-$(date +"%Y%m%d").cgz" + +# Check password file +check_passwd_file() { + root_pwd_file="$HOME/.config/compass-ci/rootfs.passwd" + export ROOT_NEW_PASSWD= + [ -f "$root_pwd_file" ] || { + echo "[INFO] Please set the password file." + echo "$HOME/.config/compass-ci/rootfs.passwd" + exit 1 + } + + export ROOT_NEW_PASSWD=$(cat "$root_pwd_file") +} + +# Pull docker image +pull_docker() +{ + docker pull $image || return + echo "finish downloading image" +} + diff --git a/rootfs/initramfs/centos/aarch64/7/bin/repolist b/rootfs/initramfs/centos/aarch64/7/bin/repolist new file mode 100644 index 0000000..5d31c40 --- /dev/null +++ b/rootfs/initramfs/centos/aarch64/7/bin/repolist @@ -0,0 +1,2 @@ +openssh-server +openssl diff --git a/rootfs/initramfs/centos/aarch64/7/build b/rootfs/initramfs/centos/aarch64/7/build new file mode 100755 index 0000000..5e1a0a0 --- /dev/null +++ b/rootfs/initramfs/centos/aarch64/7/build @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +. ./bin/lib +. $CCI_SRC/container/defconfig.sh + +check_passwd_file "$root_pwd_file" + +DIR=$(dirname $(realpath $0)) +cmd=( + docker run + --name init_docker + -v $DIR/bin/:/root/bin + -v /srv/initrd/modules/:/root/modules:ro + -e ROOT_NEW_PASSWD=$ROOT_NEW_PASSWD + -e image_name=$image_name + $image + /root/bin/creat +) + +pull_docker + +docker_rm init_docker +${cmd[@]} + +docker cp -a init_docker:/${image_name} ./ +echo "build finished!!!" +
On Sat, Oct 10, 2020 at 09:11:40PM +0800, Wang Chenglong wrote:
Use the tool to create a new centos-7 initramfs image with on click.
on => one
"click" indicates GUI and mouse, not suitable here. "command"?
and we also can customize the pre-installed software by configuring ./bin/repolist.
Signed-off-by: Wang Chenglong 18509160991@163.com
rootfs/initramfs/centos/aarch64/7/README.md | 12 ++++++ rootfs/initramfs/centos/aarch64/7/bin/creat | 38 +++++++++++++++++++ rootfs/initramfs/centos/aarch64/7/bin/dellist | 8 ++++ rootfs/initramfs/centos/aarch64/7/bin/lib | 30 +++++++++++++++ .../initramfs/centos/aarch64/7/bin/repolist | 2 + rootfs/initramfs/centos/aarch64/7/build | 29 ++++++++++++++
The rootfs/initramfs/centos/aarch64/7/* files should typically be symlinks.
creat => create It's too generic name btw, as something not for direct call by human.
dellist/repolist names can be improved.
This patch is mostly about running code in docker, please create a subdir in container/ for them.
Thanks, Fengguang
On Sun, Oct 11, 2020 at 10:35:13AM +0800, Wu Fengguang wrote:
On Sat, Oct 10, 2020 at 09:11:40PM +0800, Wang Chenglong wrote:
Use the tool to create a new centos-7 initramfs image with on click.
on => one
"click" indicates GUI and mouse, not suitable here. "command"?
Ok, i will fix it.
and we also can customize the pre-installed software by configuring ./bin/repolist.
Signed-off-by: Wang Chenglong 18509160991@163.com
rootfs/initramfs/centos/aarch64/7/README.md | 12 ++++++ rootfs/initramfs/centos/aarch64/7/bin/creat | 38 +++++++++++++++++++ rootfs/initramfs/centos/aarch64/7/bin/dellist | 8 ++++ rootfs/initramfs/centos/aarch64/7/bin/lib | 30 +++++++++++++++ .../initramfs/centos/aarch64/7/bin/repolist | 2 + rootfs/initramfs/centos/aarch64/7/build | 29 ++++++++++++++
The rootfs/initramfs/centos/aarch64/7/* files should typically be symlinks.
您的意思是指,相关代码放在其他地方,这里只保留一个build的链接对吗?
creat => create It's too generic name btw, as something not for direct call by human.
OK.
dellist/repolist names can be improved.
How about delete-list/software-list?
This patch is mostly about running code in docker, please create a subdir in container/ for them.
Ok, i will create.
Thanks, Chenglong
Thanks, Fengguang
On Sun, Oct 11, 2020 at 09:17:41PM +0800, Wang Chenglong wrote:
On Sun, Oct 11, 2020 at 10:35:13AM +0800, Wu Fengguang wrote:
On Sat, Oct 10, 2020 at 09:11:40PM +0800, Wang Chenglong wrote:
Use the tool to create a new centos-7 initramfs image with on click.
on => one
"click" indicates GUI and mouse, not suitable here. "command"?
Ok, i will fix it.
and we also can customize the pre-installed software by configuring ./bin/repolist.
Signed-off-by: Wang Chenglong 18509160991@163.com
rootfs/initramfs/centos/aarch64/7/README.md | 12 ++++++ rootfs/initramfs/centos/aarch64/7/bin/creat | 38 +++++++++++++++++++ rootfs/initramfs/centos/aarch64/7/bin/dellist | 8 ++++ rootfs/initramfs/centos/aarch64/7/bin/lib | 30 +++++++++++++++ .../initramfs/centos/aarch64/7/bin/repolist | 2 + rootfs/initramfs/centos/aarch64/7/build | 29 ++++++++++++++
The rootfs/initramfs/centos/aarch64/7/* files should typically be symlinks.
您的意思是指,相关代码放在其他地方,这里只保留一个build的链接对吗?
对的. 因为很快会有很多os variants, 不可能每个地方都放一份拷贝.
creat => create It's too generic name btw, as something not for direct call by human.
OK.
dellist/repolist names can be improved.
How about delete-list/software-list?
Another option is
packages-to-install packages-to-remove
This patch is mostly about running code in docker, please create a subdir in container/ for them.
Ok, i will create.
Thanks, Fengguang
On Mon, Oct 12, 2020 at 09:34:52AM +0800, Wu Fengguang wrote:
On Sun, Oct 11, 2020 at 09:17:41PM +0800, Wang Chenglong wrote:
On Sun, Oct 11, 2020 at 10:35:13AM +0800, Wu Fengguang wrote:
On Sat, Oct 10, 2020 at 09:11:40PM +0800, Wang Chenglong wrote:
Use the tool to create a new centos-7 initramfs image with on click.
on => one
"click" indicates GUI and mouse, not suitable here. "command"?
Ok, i will fix it.
and we also can customize the pre-installed software by configuring ./bin/repolist.
Signed-off-by: Wang Chenglong 18509160991@163.com
rootfs/initramfs/centos/aarch64/7/README.md | 12 ++++++ rootfs/initramfs/centos/aarch64/7/bin/creat | 38 +++++++++++++++++++ rootfs/initramfs/centos/aarch64/7/bin/dellist | 8 ++++ rootfs/initramfs/centos/aarch64/7/bin/lib | 30 +++++++++++++++ .../initramfs/centos/aarch64/7/bin/repolist | 2 + rootfs/initramfs/centos/aarch64/7/build | 29 ++++++++++++++
The rootfs/initramfs/centos/aarch64/7/* files should typically be symlinks.
您的意思是指,相关代码放在其他地方,这里只保留一个build的链接对吗?
对的. 因为很快会有很多os variants, 不可能每个地方都放一份拷贝.
Ok. I got it
creat => create It's too generic name btw, as something not for direct call by human.
OK.
dellist/repolist names can be improved.
How about delete-list/software-list?
Another option is
packages-to-install packages-to-remove
got it
Thanks, Chenglong
This patch is mostly about running code in docker, please create a subdir in container/ for them.
Ok, i will create.
Thanks, Fengguang