From 9cabfba0c9770f46f1c3fe83aa33a4e636a2f221 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Sun, 29 Sep 2024 11:39:40 +0000 Subject: [PATCH] riscv64: Update container build workflow Replace `9p` rootfs with `virtio-blk`, the new dev-riscv image will contain a `rootfs.img` to be used as `virtio-blk`. Effectively resolve the problems encountered while running unit-tests of `linux-loader` and `vm-memory`. Signed-off-by: Ruoqing He --- .github/workflows/docker-publish.yml | 20 ++++++++++++++++++++ Dockerfile.riscv64 | 4 ++++ riscv64/convert.sh | 24 ++++++++++++++++++++++++ riscv64/start_in_qemu.sh | 15 ++++++++------- 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100755 riscv64/convert.sh diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 95a9b6d..e0b680a 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -117,6 +117,26 @@ jobs: echo "VERSION=${NEXT_VERSION}" >> $GITHUB_ENV echo "Next version to be published is: ${NEXT_VERSION}" + - name: Build RISC-V rootfs + id: build-riscv-rootfs + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.rootfs.riscv64 + push: false + load: true + platforms: linux/amd64 + tags: rootfs + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Convert rootfs to raw image + run: | + mkdir -p ./extracted + docker run --privileged --rm --volume ./riscv64/convert.sh:/convert.sh \ + --volume ./extracted:/to_extract --entrypoint /convert.sh rootfs + docker system prune --all --force --volumes + - name: Build and push Docker image for RISC-V id: build-and-push-riscv uses: docker/build-push-action@v6 diff --git a/Dockerfile.riscv64 b/Dockerfile.riscv64 index 01e68dd..c0ae8ef 100644 --- a/Dockerfile.riscv64 +++ b/Dockerfile.riscv64 @@ -28,11 +28,15 @@ ARG QEMU_DIR=/opt/qemu ARG KERNEL_DIR=/opt/kernel ARG OPENSBI_DIR=/opt/opensbi ARG ROOTFS_DIR=/opt/rootfs +ARG EXTRACT_DIR=extracted COPY --from=qemu_builder $OUTPUT $QEMU_DIR COPY --from=kernel_builder $OUTPUT $KERNEL_DIR COPY --from=opensbi_builder $OUTPUT $OPENSBI_DIR +COPY $EXTRACT_DIR/rootfs.img $ROOTFS_DIR/rootfs.img +COPY $EXTRACT_DIR/.ssh /root/.ssh + COPY riscv64/build_finalize.sh /opt/src/scripts/finalize.sh RUN /opt/src/scripts/finalize.sh diff --git a/riscv64/convert.sh b/riscv64/convert.sh new file mode 100755 index 0000000..c7d8f5f --- /dev/null +++ b/riscv64/convert.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -ex + +apt-get update + +DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ + qemu-utils + +TMP_MOUNT_DIR=tmp_mount_dir +ROOTFS_DIR=/opt/rootfs +EXTRACT_DIR=/to_extract + +# Move rootfs into image with raw format +qemu-img create $EXTRACT_DIR/rootfs.img 5G && mkfs.ext4 $EXTRACT_DIR/rootfs.img +mkdir $TMP_MOUNT_DIR +# This operation need `privileged` docker container +mount -o loop $EXTRACT_DIR/rootfs.img $TMP_MOUNT_DIR +mv $ROOTFS_DIR/* $TMP_MOUNT_DIR +umount $TMP_MOUNT_DIR +rmdir $TMP_MOUNT_DIR + +mv /root/.ssh $EXTRACT_DIR +# Enable docker builx to transfer into container +chmod 777 $EXTRACT_DIR/.ssh diff --git a/riscv64/start_in_qemu.sh b/riscv64/start_in_qemu.sh index 7f4ac3c..ecb64e9 100755 --- a/riscv64/start_in_qemu.sh +++ b/riscv64/start_in_qemu.sh @@ -20,12 +20,13 @@ $QEMU_DIR/bin/qemu-system-riscv64 \ -smp $CORES -m $MEM \ -bios $OPENSBI_DIR/fw_jump.elf \ -kernel $KERNEL_DIR/Image \ - -device virtio-net-device,netdev=usernet -netdev user,id=usernet,hostfwd=tcp::2222-:22 \ - -virtfs local,path=$ROOTFS_DIR,mount_tag=rootfs,security_model=none,id=rootfs \ - -append "root=rootfs rw rootfstype=9p rootflags=trans=virtio,cache=mmap,msize=512000 console=ttyS0 earlycon=sbi nokaslr rdinit=/sbin/init" 2>&1 & - -# Copy WORKDIR to ROOTFS_DIR -cp -a $WORKDIR $ROOTFS_DIR/root + -device virtio-net-device,netdev=usernet \ + -netdev user,id=usernet,hostfwd=tcp::2222-:22 \ + -drive file=$ROOTFS_DIR/rootfs.img,format=raw,id=rootfs \ + -device virtio-blk-device,drive=rootfs \ + -fsdev local,security_model=passthrough,id=fsdev0,path=/workdir \ + -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=workdir \ + -append "root=/dev/vda rw console=ttyS0 earlycon=sbi nokaslr rdinit=/sbin/init" 2>&1 & HOST=riscv-qemu @@ -36,4 +37,4 @@ done # Issue command COMMAND=$@ -ssh $HOST "export PATH=\"\$PATH:/root/.cargo/bin\" && cd workdir && $COMMAND" +ssh $HOST "cd workdir && $COMMAND"