Use the tool to create a new centos-7 initramfs image with one command. and we also can customize the pre-installed software by configuring ./bin/install-list. --- container/osimage/centos-7/README.md | 13 +++++++ container/osimage/centos-7/bin/create-image | 38 +++++++++++++++++++ container/osimage/centos-7/bin/lib | 30 +++++++++++++++ .../osimage/centos-7/bin/packages-to-install | 2 + .../osimage/centos-7/bin/packages-to-remove | 8 ++++ container/osimage/centos-7/build | 29 ++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 container/osimage/centos-7/README.md create mode 100755 container/osimage/centos-7/bin/create-image create mode 100755 container/osimage/centos-7/bin/lib create mode 100644 container/osimage/centos-7/bin/packages-to-install create mode 100644 container/osimage/centos-7/bin/packages-to-remove create mode 100755 container/osimage/centos-7/build
diff --git a/container/osimage/centos-7/README.md b/container/osimage/centos-7/README.md new file mode 100644 index 0000000..d1a0317 --- /dev/null +++ b/container/osimage/centos-7/README.md @@ -0,0 +1,13 @@ +# Use the tool to create a new centos-7 initramfs image. + +Usage: + cd ${CCI_SRC/rootfs/initramfs/centos/aarch64/7} + ./build + +Some configuration items: +./bin/packages-to-install + If you want to pre-install the software, you can write the package names in ./bin/packages-to-install. + +./bin/packages-to-remove + If you want remove some unnecessary files, you can write the names in ./bin/packages-to-remove + diff --git a/container/osimage/centos-7/bin/create-image b/container/osimage/centos-7/bin/create-image new file mode 100755 index 0000000..214204f --- /dev/null +++ b/container/osimage/centos-7/bin/create-image @@ -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/packages-to-install) + yum clean all + rm -rf $(</root/bin/packages-to-remove) + 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/container/osimage/centos-7/bin/lib b/container/osimage/centos-7/bin/lib new file mode 100755 index 0000000..c3c470f --- /dev/null +++ b/container/osimage/centos-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="$(basename $(dirname $(realpath $0)))" +name="$(echo $DIR |awk -F "-" '{print $1}')" +version="$(echo $DIR |awk -F "-" '{print $2}')" +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/container/osimage/centos-7/bin/packages-to-install b/container/osimage/centos-7/bin/packages-to-install new file mode 100644 index 0000000..5d31c40 --- /dev/null +++ b/container/osimage/centos-7/bin/packages-to-install @@ -0,0 +1,2 @@ +openssh-server +openssl diff --git a/container/osimage/centos-7/bin/packages-to-remove b/container/osimage/centos-7/bin/packages-to-remove new file mode 100644 index 0000000..ce079b9 --- /dev/null +++ b/container/osimage/centos-7/bin/packages-to-remove @@ -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/container/osimage/centos-7/build b/container/osimage/centos-7/build new file mode 100755 index 0000000..5e46306 --- /dev/null +++ b/container/osimage/centos-7/build @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +. ${CCI_SRC}/container/osimage/centos-7/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/create-image +) + +pull_docker + +docker_rm init_docker +${cmd[@]} + +docker cp -a init_docker:/${image_name} ./ +echo "build finished!!!" +
On Mon, Oct 12, 2020 at 10:01:13AM +0800, Liu Yinsi wrote:
- If you want remove some unnecessary files, you can write the names in ./bin/packages-to-remove
delete blank line
ok
- echo "finish downloading image"
+}
ditto
ok
+echo "build finished!!!"
ditto
ok
Thanks, Chenglong
Thanks, Yinsi
On Mon, Oct 12, 2020 at 09:49:03AM +0800, Wang Chenglong wrote:
Use the tool to create a new centos-7 initramfs image with one command. and we also can customize the pre-installed software by configuring ./bin/install-list.
container/osimage/centos-7/README.md | 13 +++++++ container/osimage/centos-7/bin/create-image | 38 +++++++++++++++++++ container/osimage/centos-7/bin/lib | 30 +++++++++++++++ .../osimage/centos-7/bin/packages-to-install | 2 + .../osimage/centos-7/bin/packages-to-remove | 8 ++++ container/osimage/centos-7/build | 29 ++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 container/osimage/centos-7/README.md create mode 100755 container/osimage/centos-7/bin/create-image create mode 100755 container/osimage/centos-7/bin/lib create mode 100644 container/osimage/centos-7/bin/packages-to-install create mode 100644 container/osimage/centos-7/bin/packages-to-remove create mode 100755 container/osimage/centos-7/build
diff --git a/container/osimage/centos-7/README.md b/container/osimage/centos-7/README.md new file mode 100644 index 0000000..d1a0317 --- /dev/null +++ b/container/osimage/centos-7/README.md @@ -0,0 +1,13 @@ +# Use the tool to create a new centos-7 initramfs image.
+Usage:
- cd ${CCI_SRC/rootfs/initramfs/centos/aarch64/7}
- ./build
+Some configuration items: +./bin/packages-to-install
- If you want to pre-install the software, you can write the package names in ./bin/packages-to-install.
+./bin/packages-to-remove
- If you want remove some unnecessary files, you can write the names in ./bin/packages-to-remove
diff --git a/container/osimage/centos-7/bin/create-image b/container/osimage/centos-7/bin/create-image new file mode 100755 index 0000000..214204f --- /dev/null +++ b/container/osimage/centos-7/bin/create-image @@ -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/packages-to-install)
- yum clean all
- rm -rf $(</root/bin/packages-to-remove)
- 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/container/osimage/centos-7/bin/lib b/container/osimage/centos-7/bin/lib new file mode 100755 index 0000000..c3c470f --- /dev/null +++ b/container/osimage/centos-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="$(basename $(dirname $(realpath $0)))" +name="$(echo $DIR |awk -F "-" '{print $1}')" +version="$(echo $DIR |awk -F "-" '{print $2}')" +image="${name}:${version}" +image_name="${name}-${version}-$(date +"%Y%m%d").cgz"
+# Check password file
useless comment.
+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()
rename pull_docker_image and delete the comment. Thanks, Xueliang
+{
- docker pull $image || return
- echo "finish downloading image"
+}
diff --git a/container/osimage/centos-7/bin/packages-to-install b/container/osimage/centos-7/bin/packages-to-install new file mode 100644 index 0000000..5d31c40 --- /dev/null +++ b/container/osimage/centos-7/bin/packages-to-install @@ -0,0 +1,2 @@ +openssh-server +openssl diff --git a/container/osimage/centos-7/bin/packages-to-remove b/container/osimage/centos-7/bin/packages-to-remove new file mode 100644 index 0000000..ce079b9 --- /dev/null +++ b/container/osimage/centos-7/bin/packages-to-remove @@ -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/container/osimage/centos-7/build b/container/osimage/centos-7/build new file mode 100755 index 0000000..5e46306 --- /dev/null +++ b/container/osimage/centos-7/build @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+. ${CCI_SRC}/container/osimage/centos-7/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/create-image
+)
+pull_docker
+docker_rm init_docker +${cmd[@]}
+docker cp -a init_docker:/${image_name} ./ +echo "build finished!!!"
-- 2.23.0
+# Check password file
useless comment.
ok
+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()
rename pull_docker_image and delete the comment.
ok
Thanks, Chenglong
Thanks, Xueliang
+{
- docker pull $image || return
- echo "finish downloading image"
+}
diff --git a/container/osimage/centos-7/bin/packages-to-install b/container/osimage/centos-7/bin/packages-to-install new file mode 100644 index 0000000..5d31c40 --- /dev/null +++ b/container/osimage/centos-7/bin/packages-to-install @@ -0,0 +1,2 @@ +openssh-server +openssl diff --git a/container/osimage/centos-7/bin/packages-to-remove b/container/osimage/centos-7/bin/packages-to-remove new file mode 100644 index 0000000..ce079b9 --- /dev/null +++ b/container/osimage/centos-7/bin/packages-to-remove @@ -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/container/osimage/centos-7/build b/container/osimage/centos-7/build new file mode 100755 index 0000000..5e46306 --- /dev/null +++ b/container/osimage/centos-7/build @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+. ${CCI_SRC}/container/osimage/centos-7/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/create-image
+)
+pull_docker
+docker_rm init_docker +${cmd[@]}
+docker cp -a init_docker:/${image_name} ./ +echo "build finished!!!"
-- 2.23.0
On Mon, Oct 12, 2020 at 09:49:03AM +0800, Wang Chenglong wrote:
+Usage:
- cd ${CCI_SRC/rootfs/initramfs/centos/aarch64/7}
- ./build
1.build at here not link ${CCI_SRC/container/osimage/centos-7/build, create ln -s in our code.
2.point user touch file rootfs.passwd in READEME is also necessary, instead of user execute code to see message "Please set the password file".
+docker_rm init_docker +docker cp -a init_docker:/${image_name} ./
3.can't copy file from a container which is dead or marked for removal, docker cp should execute defore docker_rm.
Thanks, Yinsi
On Mon, Oct 12, 2020 at 10:57:35AM +0800, Liu Yinsi wrote:
On Mon, Oct 12, 2020 at 09:49:03AM +0800, Wang Chenglong wrote:
+Usage:
- cd ${CCI_SRC/rootfs/initramfs/centos/aarch64/7}
- ./build
1.build at here not link ${CCI_SRC/container/osimage/centos-7/build, create ln -s in our code.
./build 这个链接时用于调用container代码生成cgz镜像,而不是为了创建这个链接.
2.point user touch file rootfs.passwd in READEME is also necessary, instead of user execute code to see message "Please set the password file".
+docker_rm init_docker +docker cp -a init_docker:/${image_name} ./
Ok. i had fix it.
3.can't copy file from a container which is dead or marked for removal, docker cp should execute defore docker_rm.
ok. i had fix it.
Thanks, Chenglong
Thanks, Yinsi
On Mon, Oct 12, 2020 at 11:47:37AM +0800, Wang Chenglong wrote:
On Mon, Oct 12, 2020 at 10:57:35AM +0800, Liu Yinsi wrote:
On Mon, Oct 12, 2020 at 09:49:03AM +0800, Wang Chenglong wrote:
+Usage:
- cd ${CCI_SRC/rootfs/initramfs/centos/aarch64/7}
- ./build
1.build at here not link ${CCI_SRC/container/osimage/centos-7/build, create ln -s in our code.
./build 这个链接时用于调用container代码生成cgz镜像,而不是为了创建这个链接.
那cd到$CCI_SRC/rootfs/initramfs/centos/aarch64/7这个目录下执行的build,这个build文件是哪里来的
On Mon, Oct 12, 2020 at 12:41:38PM +0800, Liu Yinsi wrote:
On Mon, Oct 12, 2020 at 11:47:37AM +0800, Wang Chenglong wrote:
On Mon, Oct 12, 2020 at 10:57:35AM +0800, Liu Yinsi wrote:
On Mon, Oct 12, 2020 at 09:49:03AM +0800, Wang Chenglong wrote:
+Usage:
- cd ${CCI_SRC/rootfs/initramfs/centos/aarch64/7}
- ./build
1.build at here not link ${CCI_SRC/container/osimage/centos-7/build, create ln -s in our code.
./build 这个链接时用于调用container代码生成cgz镜像,而不是为了创建这个链接.
那cd到$CCI_SRC/rootfs/initramfs/centos/aarch64/7这个目录下执行的build,这个build文件是哪里来的
创建镜像cgz文件的代码在 ${CCI_SRC/container/osimage/centos/* , ${CCI_SRC}/rootfs/initramfs/centos/aarch64/7/build 只是一个链接
Thanks, Chenglong
1.build at here not link ${CCI_SRC/container/osimage/centos-7/build, create ln -s in our code.
那cd到$CCI_SRC/rootfs/initramfs/centos/aarch64/7这个目录下执行的build,这个build文件是哪里来的
创建镜像cgz文件的代码在 ${CCI_SRC/container/osimage/centos/* , ${CCI_SRC}/rootfs/initramfs/centos/aarch64/7/build 只是一个链接
ok, 现在rootfs目录下除了tools没有initramfs等文件夹,是从srv/initrd/osimage移过来吗?
Thanks, Chenglong
On Mon, Oct 12, 2020 at 03:58:43PM +0800, Liu Yinsi wrote:
1.build at here not link ${CCI_SRC/container/osimage/centos-7/build, create ln -s in our code.
那cd到$CCI_SRC/rootfs/initramfs/centos/aarch64/7这个目录下执行的build,这个build文件是哪里来的
创建镜像cgz文件的代码在 ${CCI_SRC/container/osimage/centos/* , ${CCI_SRC}/rootfs/initramfs/centos/aarch64/7/build 只是一个链接
ok, 现在rootfs目录下除了tools没有initramfs等文件夹,是从srv/initrd/osimage移过来吗?
这个是以前规划好的,新建的一个目录.
Thanks, Chenglong