From 610e0e9c2765c78741fe29fa25e4e6124bde982a Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Mon, 30 Sep 2024 10:39:53 +0000 Subject: [PATCH 1/2] riscv64: Mount `tmpfs` to support unit-tests expecting `/tmp` As `9p` rootfs documented [1], mount a `tmpfs` onto `/tmp` could avoid `E: Unable to determine file size for fd 7 - fstat (2: No such file or directory)`. And various unittests in `linux-loader`, `vm-memory` and etc. explicitly expect `/tmp` to exist, and were failing on riscv because no `tmpfs` was mounted. Modify `/etc/fstab` to apply the mount operation during boot. [1] https://wiki.qemu.org/Documentation/9p_root_fs#Let's_start_the_Installation Signed-off-by: Ruoqing He --- riscv64/build_finalize.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/riscv64/build_finalize.sh b/riscv64/build_finalize.sh index ba2d9ce..38669cc 100755 --- a/riscv64/build_finalize.sh +++ b/riscv64/build_finalize.sh @@ -7,6 +7,10 @@ DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ openssh-client libslirp-dev libfdt-dev libglib2.0-dev libssl-dev \ libpixman-1-dev netcat +# Modify fstab to mount `tmpfs` during boot +# See: https://wiki.qemu.org/Documentation/9p_root_fs#Let's_start_the_Installation +echo 'tmpfs /tmp tmpfs rw,nosuid,nodev,size=524288k,nr_inodes=204800 0 0' >> $ROOTFS_DIR/etc/fstab + # Setup container ssh config yes "" | ssh-keygen -P "" cat /root/.ssh/id_rsa.pub > $ROOTFS_DIR/root/.ssh/authorized_keys From 22eafe43295dd0dd7ff2c533e06697f1f1200fa4 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Mon, 30 Sep 2024 10:43:56 +0000 Subject: [PATCH 2/2] riscv64: Improve command forwarding Previous implementation uses `netcat` to test existence of pre-configured target port, but that port is occupied in advance of `sshd` inside VM is ready. Replace `netcat` with `ssh` with `ConnectTimeout` set to directly verify the connectivity of `sshd`. Signed-off-by: Ruoqing He --- riscv64/build_finalize.sh | 2 +- riscv64/start_in_qemu.sh | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/riscv64/build_finalize.sh b/riscv64/build_finalize.sh index 38669cc..6f70f5f 100755 --- a/riscv64/build_finalize.sh +++ b/riscv64/build_finalize.sh @@ -5,7 +5,7 @@ apt-get update DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ openssh-client libslirp-dev libfdt-dev libglib2.0-dev libssl-dev \ - libpixman-1-dev netcat + libpixman-1-dev # Modify fstab to mount `tmpfs` during boot # See: https://wiki.qemu.org/Documentation/9p_root_fs#Let's_start_the_Installation diff --git a/riscv64/start_in_qemu.sh b/riscv64/start_in_qemu.sh index 7f4ac3c..1d57461 100755 --- a/riscv64/start_in_qemu.sh +++ b/riscv64/start_in_qemu.sh @@ -29,11 +29,12 @@ cp -a $WORKDIR $ROOTFS_DIR/root HOST=riscv-qemu -while ! nc -z localhost 2222; do - echo "Dialing qemu-system-riscv64..." - sleep 1 +echo "Testing SSH connectivity to $HOST..." +while ! ssh -o ConnectTimeout=3 $HOST exit; do + echo "$HOST is not ready..." done # Issue command COMMAND=$@ +echo "$HOST is ready, forwarding command: $COMMAND" ssh $HOST "export PATH=\"\$PATH:/root/.cargo/bin\" && cd workdir && $COMMAND"