-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bo YU <tsu.yubo@gmail.com>
- Loading branch information
Showing
8 changed files
with
203 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
FROM debian:sid as builder | ||
MAINTAINER Bo YU "tsu.yubo@gmail.com" | ||
|
||
ENV KERNEL_VERSION=${KERNEL_VERSION} | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN --mount=type=cache,sharing=shared,target=/var/cache \ | ||
--mount=type=cache,sharing=shared,target=/var/lib/apt/lists \ | ||
--mount=type=tmpfs,target=/usr/share/man \ | ||
--mount=type=tmpfs,target=/usr/share/doc \ | ||
apt-get update \ | ||
&& apt-get install -y eatmydata \ | ||
&& eatmydata apt-get install -y debootstrap qemu-user-static \ | ||
binfmt-support debian-ports-archive-keyring gdisk kpartx \ | ||
parted \ | ||
autoconf automake autotools-dev bc binfmt-support \ | ||
build-essential cpio curl \ | ||
dosfstools e2fsprogs fdisk flex gawk \ | ||
git gperf kmod libexpat-dev \ | ||
libgmp-dev libmpc-dev libmpfr-dev libssl-dev \ | ||
libtool mmdebstrap multistrap openssl parted \ | ||
patchutils python3 python3-dev python3-distutils \ | ||
python3-setuptools qemu-user-static swig \ | ||
systemd-container texinfo zlib1g-dev wget | ||
|
||
# build rootfs | ||
FROM builder as build_rootfs | ||
WORKDIR /build | ||
COPY rootfs/multistrap_nvme.conf multistrap.conf | ||
|
||
RUN --mount=type=cache,sharing=shared,target=/var/cache \ | ||
--mount=type=cache,sharing=shared,target=/var/lib/apt/lists \ | ||
--mount=type=tmpfs,target=/usr/share/man \ | ||
--mount=type=tmpfs,target=/usr/share/doc \ | ||
eatmydata multistrap -f multistrap.conf | ||
|
||
|
||
FROM builder as build_image | ||
WORKDIR /builder | ||
COPY --from=build_rootfs /build/rv64-sid/ ./rv64-port/ | ||
COPY create_image.sh build.sh ./ | ||
COPY rootfs/setup_rootfs.sh ./rv64-port/ | ||
|
||
CMD eatmydata /builder/build.sh ${KERNEL_VERSION} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
# It woule be good to test it outside of Docker | ||
OUT_DIR="$1" | ||
KERNEL_VERSION="$2" | ||
|
||
ROOTFS_IMG="${OUT_DIR}/vf2-rootfs.img" | ||
SD_DD_OPTS="bs=4k iflag=fullblock oflag=direct conv=fsync status=progress" | ||
|
||
function make_image(){ | ||
|
||
if [ -f ${ROOTFS_IMG} ]; then | ||
echo "deleting nvme rootfs image..." | ||
rm ${ROOTFS_IMG} | ||
fi | ||
|
||
dd if=/dev/zero of="${ROOTFS_IMG}" bs=1M count=4096 | ||
|
||
echo "Creating Blank ${ROOTFS_IMG}" | ||
|
||
sgdisk -g --clear --set-alignment=1 \ | ||
-g --clear --new=1:0:+16M: --new=2:0:+100M: -t 2:EF00 --new=3:0:-1M: --attributes 3:set:2 -d 1 ${ROOTFS_IMG} | ||
|
||
|
||
part_id=$(kpartx -av ${ROOTFS_IMG} | awk '{print $3}' | awk 'NR==1 {print $1}'| awk -F 'p' '{print $2}') | ||
echo "the output is $part_id" | ||
|
||
LOOP_X_P2="loop${part_id}p2" | ||
LOOP_X_P3="loop${part_id}p3" | ||
|
||
echo "formatting loopback device ${LOOP_X_P2}" | ||
|
||
mkfs.vfat "/dev/mapper/${LOOP_X_P2}" | ||
|
||
mkfs.ext4 -m 0 -L root "/dev/mapper/${LOOP_X_P3}" | ||
|
||
# Copy Files, first the rootfs partition | ||
echo "Mounting partitions ${LOOPDEV}" | ||
ROOTFS_POINT=/nvme_rootfs | ||
mkdir -p "${ROOTFS_POINT}" | ||
|
||
mount "/dev/mapper/${LOOP_X_P3}" "${ROOTFS_POINT}" | ||
|
||
#mount ${LOOPDEV} /mnt | ||
#debootstrap --arch=riscv64 --keyring /usr/share/keyrings/debian-ports-archive-keyring.gpg --include=debian-ports-archive-keyring,ca-certificates unstable ${ROOTFS_POINT} https://mirror.iscas.ac.cn/debian-ports | ||
# | ||
copy_rootfs | ||
|
||
kpartx -d ${ROOTFS_IMG} | ||
} | ||
|
||
function get_kernel_deb(){ | ||
vf2_image_repo="https://github.com/yuzibo/vf2-linux" | ||
kernel_deb_url="${vf2_image_repo}/releases/download/${KERNEL_VERSION}/vf2-mainline-kernel-gcc-13.tar.gz" | ||
|
||
wget --no-check-certificate ${kernel_deb_url} | ||
|
||
tar -zxvf vf2-mainline-kernel-gcc-13.tar.gz -C /tmp | ||
|
||
} | ||
|
||
function copy_rootfs(){ | ||
|
||
echo "copy rootfs" | ||
# from docker image has been defined | ||
cp -av /builder/rv64-port/* "${ROOTFS_POINT}" | ||
|
||
# Copy the rootfs | ||
cp -v /usr/bin/qemu-riscv64-static ${ROOTFS_POINT}/usr/bin/ | ||
|
||
# should judge deb if exist | ||
get_kernel_deb | ||
|
||
cp -v /tmp/vf2_kernel_deb/*.deb ${ROOTFS_POINT}/tmp | ||
chroot "${ROOTFS_POINT}" qemu-riscv64-static /bin/sh /setup_rootfs.sh | ||
rm "${ROOTFS_POINT}/setup_rootfs.sh" "${ROOTFS_POINT}/usr/bin/qemu-riscv64-static" | ||
|
||
umount "${ROOTFS_POINT}" | ||
|
||
rm -rf "${ROOTFS_POINT}" | ||
|
||
} | ||
|
||
make_image | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "make_image executed successfully." | ||
# Now compress the image | ||
echo "Compressing the image: ${ROOTFS_IMG}" | ||
cd "${OUT_DIR}" && xz -T0 "${ROOTFS_IMG}" | ||
else | ||
kpartx -d ${ROOTFS_IMG} | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters