Skip to content

Commit f96f2c6

Browse files
committed
building: extra common scriptes for image building
Signed-off-by: Zhang Tianyang <[email protected]>
1 parent e826a96 commit f96f2c6

File tree

3 files changed

+152
-136
lines changed

3 files changed

+152
-136
lines changed

vmm/scripts/image/build_image.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ AGENT_INIT=${AGENT_INIT:-yes}
6262

6363
# Align image to (size in MB) according to different architecture.
6464
case "$(uname -m)" in
65-
aarch64) readonly mem_boundary_mb=16 ;;
65+
aarch64) readonly mem_boundary_mb=128 ;;
6666
*) readonly mem_boundary_mb=128 ;;
6767
esac
6868

@@ -339,7 +339,7 @@ create_disk() {
339339
# The partition is the rootfs content
340340
info "Creating partitions"
341341
parted -s -a optimal "${image}" -- \
342-
mklabel gpt \
342+
mklabel msdos \
343343
mkpart primary "${fs_type}" "${part_start}"M "${rootfs_end}"M
344344

345345
OK "Partitions created"

vmm/scripts/image/centos/build_rootfs.sh

+2-134
Original file line numberDiff line numberDiff line change
@@ -19,144 +19,12 @@ golang_version="1.20.5"
1919
cert_file_path="/kuasar/proxy.crt"
2020
ARCH=$(uname -m)
2121

22-
make_vmm_task() {
23-
local repo_dir="$1"
24-
25-
yum install -y cmake make gcc-c++ wget
26-
27-
# update cert file under internal proxy scenario
28-
if [ -f "${cert_file_path}" ]; then
29-
cp ${cert_file_path} /etc/pki/ca-trust/source/anchors/
30-
update-ca-trust extract
31-
fi
32-
33-
# install rust to compile vmm-task
34-
pushd ${repo_dir}
35-
36-
source vmm/scripts/image/install_rust.sh
37-
38-
make bin/vmm-task ARCH=${ARCH}
39-
popd
40-
}
41-
42-
install_golang() {
43-
pushd /home/
44-
arch_name=""
45-
if [ "${ARCH}" == "aarch64" ]; then
46-
arch_name="arm64"
47-
elif [ "${ARCH}" == "x86_64" ]; then
48-
arch_name="amd64"
49-
else
50-
echo "Unsupported arch: ${ARCH}"
51-
exit 1
52-
fi
53-
rm -f go${golang_version}.linux-${arch_name}.tar.gz
54-
wget -q "https://go.dev/dl/go${golang_version}.linux-${arch_name}.tar.gz"
55-
rm -rf /usr/local/go && tar -C /usr/local -xzf "go${golang_version}.linux-${arch_name}.tar.gz"
56-
echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile
57-
source /etc/profile
58-
go version
59-
popd
60-
}
61-
62-
build_runc() {
63-
local repo_dir="$1"
64-
mkdir -p /tmp/gopath
65-
GOPATH=/tmp/gopath go install github.com/opencontainers/[email protected]
66-
cp /tmp/gopath/bin/runc ${repo_dir}/bin/
67-
}
68-
69-
create_tmp_rootfs() {
70-
local rootfs_dir="$1"
71-
rm -rf ${rootfs_dir}/*
72-
mkdir -p ${rootfs_dir}/lib \
73-
${rootfs_dir}/lib64 \
74-
${rootfs_dir}/lib/modules
75-
76-
mkdir -m 0755 -p ${rootfs_dir}/dev \
77-
${rootfs_dir}/sys \
78-
${rootfs_dir}/sbin \
79-
${rootfs_dir}/bin \
80-
${rootfs_dir}/tmp \
81-
${rootfs_dir}/proc \
82-
${rootfs_dir}/etc \
83-
${rootfs_dir}/run \
84-
${rootfs_dir}/var
85-
86-
ln -s ../run ${rootfs_dir}/var/run
87-
touch ${rootfs_dir}/etc/resolv.conf
88-
}
89-
90-
install_and_copy_rpm() {
91-
set +e
92-
local rpm_list_file="$1"
93-
local rootfs_dir="$2"
94-
cat ${rpm_list_file} | while read rpm; do
95-
if [ "${rpm:0:1}" != "#" ]; then
96-
rpm -ql $rpm >/dev/null 2>&1
97-
if [ $? -ne 0 ]; then
98-
yum install -y $rpm >/dev/null 2>&1
99-
if [ $? -ne 0 ]; then
100-
echo "Can not install $rpm by yum"
101-
continue
102-
fi
103-
rpm -ql $rpm >/dev/null 2>&1 || continue
104-
fi
105-
array=($(rpm -ql $rpm | grep -v "share" | grep -v ".build-id"))
106-
for file in ${array[@]}; do
107-
source=$file
108-
dst_file=${rootfs_dir}$file
109-
dst_folder=${dst_file%/*}
110-
if [ ! -d "$dst_folder" ] && [ ! -L "$dst_folder" ]; then
111-
mkdir -p $dst_folder
112-
fi
113-
cp -r -f -d $source $dst_folder
114-
done
115-
fi
116-
done
117-
set -e
118-
}
119-
120-
copy_binaries() {
121-
local binaries_list_file="$1"
122-
local rootfs_dir="$2"
123-
cat $binaries_list_file | while read line; do
124-
if [ -n "${line}" ] && [ "${line:0:1}" != "#" ]; then
125-
source=$(echo "${line}" | awk '{print $1}')
126-
des=$(echo "${line}" | awk '{print $2}')
127-
if [ ! -d "$des" ]; then
128-
mkdir -p $des
129-
fi
130-
cp -r -d $source ${rootfs_dir}/$des
131-
fi
132-
done
133-
}
134-
135-
copy_libs() {
136-
local binaries_list_file="$1"
137-
local rootfs_dir="$2"
138-
binaries_list=$(cat $binaries_list_file | grep -v "#" | awk '{print $1}')
139-
binaries_list=(${binaries_list[@]} ${rootfs_dir}/sbin/init)
140-
for bin in ${binaries_list[@]}; do
141-
ldd ${bin} | while read line; do
142-
arr=(${line// / })
143-
144-
for lib in ${arr[@]}; do
145-
echo $lib
146-
if [ "${lib:0:1}" = "/" ]; then
147-
dir=${rootfs_dir}/$(dirname $lib)
148-
mkdir -p "${dir}"
149-
cp -f $lib $dir
150-
fi
151-
done
152-
done
153-
done
154-
}
22+
current_dir=$(dirname "$(realpath "$0")")
23+
source $current_dir/../common.sh
15524

15625
main() {
15726
local rootfs_dir=${ROOTFS_DIR:-/tmp/kuasar-rootfs}
15827
local repo_dir=${REPO_DIR:-/kuasar}
159-
local current_dir="$(dirname $(readlink -f $0))"
16028
make_vmm_task ${repo_dir}
16129
install_golang
16230
build_runc ${repo_dir}

vmm/scripts/image/common.sh

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/bin/bash
2+
# Copyright 2024 The Kuasar Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
make_vmm_task() {
17+
local repo_dir="$1"
18+
19+
yum install -y cmake make gcc-c++ wget
20+
21+
# update cert file under internal proxy scenario
22+
if [ -f "${cert_file_path}" ]; then
23+
cp ${cert_file_path} /etc/pki/ca-trust/source/anchors/
24+
update-ca-trust extract
25+
fi
26+
27+
# install rust to compile vmm-task
28+
pushd ${repo_dir}
29+
30+
source vmm/scripts/image/install_rust.sh
31+
32+
make bin/vmm-task ARCH=${ARCH}
33+
popd
34+
}
35+
36+
install_golang() {
37+
pushd /home/
38+
arch_name=""
39+
if [ "${ARCH}" == "aarch64" ]; then
40+
arch_name="arm64"
41+
elif [ "${ARCH}" == "x86_64" ]; then
42+
arch_name="amd64"
43+
else
44+
echo "Unsupported arch: ${ARCH}"
45+
exit 1
46+
fi
47+
rm -f go${golang_version}.linux-${arch_name}.tar.gz
48+
wget -q "https://go.dev/dl/go${golang_version}.linux-${arch_name}.tar.gz"
49+
rm -rf /usr/local/go && tar -C /usr/local -xzf "go${golang_version}.linux-${arch_name}.tar.gz"
50+
echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile
51+
source /etc/profile
52+
go version
53+
popd
54+
}
55+
56+
build_runc() {
57+
local repo_dir="$1"
58+
mkdir -p /tmp/gopath
59+
GOPATH=/tmp/gopath go install github.com/opencontainers/[email protected]
60+
cp /tmp/gopath/bin/runc ${repo_dir}/bin/
61+
}
62+
63+
create_tmp_rootfs() {
64+
local rootfs_dir="$1"
65+
rm -rf ${rootfs_dir}/*
66+
mkdir -p ${rootfs_dir}/lib \
67+
${rootfs_dir}/lib64 \
68+
${rootfs_dir}/lib/modules
69+
70+
mkdir -m 0755 -p ${rootfs_dir}/dev \
71+
${rootfs_dir}/sys \
72+
${rootfs_dir}/sbin \
73+
${rootfs_dir}/bin \
74+
${rootfs_dir}/tmp \
75+
${rootfs_dir}/proc \
76+
${rootfs_dir}/etc \
77+
${rootfs_dir}/run \
78+
${rootfs_dir}/var
79+
80+
ln -s ../run ${rootfs_dir}/var/run
81+
touch ${rootfs_dir}/etc/resolv.conf
82+
}
83+
84+
install_and_copy_rpm() {
85+
set +e
86+
local rpm_list_file="$1"
87+
local rootfs_dir="$2"
88+
cat ${rpm_list_file} | while read rpm; do
89+
if [ "${rpm:0:1}" != "#" ]; then
90+
rpm -ql $rpm >/dev/null 2>&1
91+
if [ $? -ne 0 ]; then
92+
yum install -y $rpm >/dev/null 2>&1
93+
if [ $? -ne 0 ]; then
94+
echo "Can not install $rpm by yum"
95+
continue
96+
fi
97+
rpm -ql $rpm >/dev/null 2>&1 || continue
98+
fi
99+
array=($(rpm -ql $rpm | grep -v "share" | grep -v ".build-id"))
100+
for file in ${array[@]}; do
101+
source=$file
102+
dst_file=${rootfs_dir}$file
103+
dst_folder=${dst_file%/*}
104+
if [ ! -d "$dst_folder" ] && [ ! -L "$dst_folder" ]; then
105+
mkdir -p $dst_folder
106+
fi
107+
cp -r -f -d $source $dst_folder
108+
done
109+
fi
110+
done
111+
set -e
112+
}
113+
114+
copy_binaries() {
115+
local binaries_list_file="$1"
116+
local rootfs_dir="$2"
117+
cat $binaries_list_file | while read line; do
118+
if [ -n "${line}" ] && [ "${line:0:1}" != "#" ]; then
119+
source=$(echo "${line}" | awk '{print $1}')
120+
des=$(echo "${line}" | awk '{print $2}')
121+
if [ ! -d "$des" ]; then
122+
mkdir -p $des
123+
fi
124+
cp -r -d $source ${rootfs_dir}/$des
125+
fi
126+
done
127+
}
128+
129+
copy_libs() {
130+
local binaries_list_file="$1"
131+
local rootfs_dir="$2"
132+
binaries_list=$(cat $binaries_list_file | grep -v "#" | awk '{print $1}')
133+
binaries_list=(${binaries_list[@]} ${rootfs_dir}/sbin/init)
134+
for bin in ${binaries_list[@]}; do
135+
ldd ${bin} | while read line; do
136+
arr=(${line// / })
137+
138+
for lib in ${arr[@]}; do
139+
echo $lib
140+
if [ "${lib:0:1}" = "/" ]; then
141+
dir=${rootfs_dir}/$(dirname $lib)
142+
mkdir -p "${dir}"
143+
cp -f $lib $dir
144+
fi
145+
done
146+
done
147+
done
148+
}

0 commit comments

Comments
 (0)