100 lines
2.8 KiB
Bash
100 lines
2.8 KiB
Bash
|
|
#!/bin/bash
|
|||
|
|
|
|||
|
|
# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|||
|
|
# kata_integration is licensed under the Mulan PSL v2.
|
|||
|
|
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|||
|
|
# You may obtain a copy of Mulan PSL v2 at:
|
|||
|
|
# http://license.coscl.org.cn/MulanPSL2
|
|||
|
|
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|||
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|||
|
|
# PURPOSE.
|
|||
|
|
# See the Mulan PSL v2 for more details.
|
|||
|
|
# Description: make kuasar initrd
|
|||
|
|
|
|||
|
|
script_dir="$(dirname $(readlink -f $0))"
|
|||
|
|
rpmlist=${script_dir}/make-initrd-rpm.list
|
|||
|
|
|
|||
|
|
IMAGE_NAME=${IMAGE_NAME:-kuasar.initrd}
|
|||
|
|
ROOTFS_DIR=${ROOTFS_DIR:-/tmp/kuasar-rootfs}
|
|||
|
|
|
|||
|
|
# create a temp dir to store rootfs
|
|||
|
|
rm -rf ${ROOTFS_DIR}
|
|||
|
|
mkdir -p ${ROOTFS_DIR}/lib \
|
|||
|
|
${ROOTFS_DIR}/lib64 \
|
|||
|
|
${ROOTFS_DIR}/lib/modules
|
|||
|
|
|
|||
|
|
mkdir -m 0755 -p ${ROOTFS_DIR}/dev \
|
|||
|
|
${ROOTFS_DIR}/sys \
|
|||
|
|
${ROOTFS_DIR}/sbin \
|
|||
|
|
${ROOTFS_DIR}/bin \
|
|||
|
|
${ROOTFS_DIR}/tmp \
|
|||
|
|
${ROOTFS_DIR}/proc \
|
|||
|
|
${ROOTFS_DIR}/etc
|
|||
|
|
|
|||
|
|
if [ ! -f "${script_dir}/vmm-task" ];then
|
|||
|
|
echo "vmm-task doesn't exist!"
|
|||
|
|
exit 1
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
touch ${ROOTFS_DIR}/etc/resolv.conf
|
|||
|
|
|
|||
|
|
# busybox
|
|||
|
|
cp /sbin/busybox ${ROOTFS_DIR}/sbin/
|
|||
|
|
cp ${script_dir}/vmm-task ${ROOTFS_DIR}/init
|
|||
|
|
# glibc-devel glibc
|
|||
|
|
cp /lib64/libnss_dns* ${ROOTFS_DIR}/lib64
|
|||
|
|
cp /lib64/libnss_files* ${ROOTFS_DIR}/lib64
|
|||
|
|
|
|||
|
|
# cp run request files in initrd
|
|||
|
|
cat $rpmlist | while read rpm
|
|||
|
|
do
|
|||
|
|
if [ "${rpm:0:1}" != "#" ]; then
|
|||
|
|
rpm -ql $rpm > /dev/null 2>&1
|
|||
|
|
if [ $? -ne 0 ]; then
|
|||
|
|
continue
|
|||
|
|
fi
|
|||
|
|
array=($(rpm -ql $rpm| grep -v "share" | grep -v ".build-id"))
|
|||
|
|
echo array
|
|||
|
|
for file in ${array[@]};
|
|||
|
|
do
|
|||
|
|
source=$file
|
|||
|
|
dts_file=${ROOTFS_DIR}$file
|
|||
|
|
dts_folder=${dts_file%/*}
|
|||
|
|
if [ ! -d "$dts_folder" ];then
|
|||
|
|
mkdir -p $dts_folder
|
|||
|
|
fi
|
|||
|
|
cp -r -f -d $source $dts_folder
|
|||
|
|
done
|
|||
|
|
fi
|
|||
|
|
done
|
|||
|
|
|
|||
|
|
#create symlinks to busybox
|
|||
|
|
BUSYBOX_BINARIES=(/bin/sh /bin/mount /bin/umount /bin/ls /bin/ps /bin/file /bin/ldd /bin/tar /bin/hwclock /sbin/modprobe /sbin/depmod /bin/ip /bin/modinfo /bin/insmod /bin/rmmod)
|
|||
|
|
for bin in ${BUSYBOX_BINARIES[@]}
|
|||
|
|
do
|
|||
|
|
mkdir -p ${ROOTFS_DIR}/`dirname ${bin}`
|
|||
|
|
ln -sf /sbin/busybox ${ROOTFS_DIR}/${bin}
|
|||
|
|
done
|
|||
|
|
|
|||
|
|
LDD_BINARIES=(/init /sbin/busybox /usr/bin/bash /usr/bin/runc)
|
|||
|
|
for bin in ${LDD_BINARIES[@]}
|
|||
|
|
do
|
|||
|
|
ldd ${ROOTFS_DIR}${bin} | while read line
|
|||
|
|
do
|
|||
|
|
arr=(${line// / })
|
|||
|
|
|
|||
|
|
for lib in ${arr[@]}
|
|||
|
|
do
|
|||
|
|
echo $lib
|
|||
|
|
if [ "${lib:0:1}" = "/" ]; then
|
|||
|
|
dir=${ROOTFS_DIR}`dirname $lib`
|
|||
|
|
mkdir -p "${dir}"
|
|||
|
|
cp -f $lib $dir
|
|||
|
|
fi
|
|||
|
|
done
|
|||
|
|
done
|
|||
|
|
done
|
|||
|
|
|
|||
|
|
cp ${ROOTFS_DIR}/usr/bin/bash ${ROOTFS_DIR}/bin/bash
|
|||
|
|
(cd ${ROOTFS_DIR} && find . | cpio -H newc -o | gzip -9 ) > ${script_dir}/${IMAGE_NAME}
|