From 2583093ef54aec321dc0dddad0876f2d664af2c9 Mon Sep 17 00:00:00 2001 From: tesuji Date: Wed, 12 Nov 2025 04:24:02 +0000 Subject: [PATCH 1/3] add a Dockerfile to build the disk image Also use the archive link for `debootstrap` to avoid EOL links. --- scripts/create-image/Dockerfile | 36 ++++++++++++++++ scripts/create-image/configure.sh | 64 ++++++++++++++++++++++++++++ scripts/create-image/create-image.sh | 63 ++------------------------- scripts/create-image/debootstrap.sh | 13 ++++++ 4 files changed, 117 insertions(+), 59 deletions(-) create mode 100644 scripts/create-image/Dockerfile create mode 100755 scripts/create-image/configure.sh create mode 100755 scripts/create-image/debootstrap.sh diff --git a/scripts/create-image/Dockerfile b/scripts/create-image/Dockerfile new file mode 100644 index 0000000..cbb570d --- /dev/null +++ b/scripts/create-image/Dockerfile @@ -0,0 +1,36 @@ +FROM ubuntu:24.04 AS base + +ENV DEBIAN_FRONTEND=noninteractive + +SHELL ["/bin/bash", "-c"] + +RUN < Date: Thu, 13 Nov 2025 10:06:48 +0000 Subject: [PATCH 2/3] prevent using ./configure.sh directly which could brick users' host machines. --- README.md | 9 +++++++++ scripts/create-image/Dockerfile | 2 +- scripts/create-image/configure.sh | 14 ++++++++++++++ scripts/create-image/debootstrap.sh | 0 4 files changed, 24 insertions(+), 1 deletion(-) mode change 100755 => 100644 scripts/create-image/configure.sh mode change 100755 => 100644 scripts/create-image/debootstrap.sh diff --git a/README.md b/README.md index 8482cd4..fca9d6c 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,15 @@ mkdir qemu/build && cd qemu/build && ../configure --target-list=x86_64-softmmu - cd scripts/create-image/ && ./create-image.sh && cd ../.. ~~~ +Or if you prefer using docker to build your image: +~~~ +cd scripts/create-image/ +docker build -t img . +docker run -v $(pwd):/mnt --privileged --rm img +~~~ + +Notice that `privileged` is necessary because we want to use `/dev/loop*` inside docker. + ### Step 4: Install uv ~~~ pip install uv diff --git a/scripts/create-image/Dockerfile b/scripts/create-image/Dockerfile index cbb570d..8778b11 100644 --- a/scripts/create-image/Dockerfile +++ b/scripts/create-image/Dockerfile @@ -32,5 +32,5 @@ RUN ./debootstrap.sh # will copy the img file to /mnt. Need --privilege flag for docker run. COPY --chmod=0755 configure.sh /src/ -CMD ["bash", "-x", "./configure.sh"] +CMD ["bash", "-c", "set -ex; source ./configure.sh"] diff --git a/scripts/create-image/configure.sh b/scripts/create-image/configure.sh old mode 100755 new mode 100644 index 385b2aa..5b71d7d --- a/scripts/create-image/configure.sh +++ b/scripts/create-image/configure.sh @@ -2,6 +2,20 @@ # Copyright 2025 syzkaller project authors. All rights reserved. # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. +usage() { + echo "Please use the ./create-image.sh instead." >&2 + exit 1 +} + +# Prevent execution if not sourced +(return 0 2>/dev/null) || { + usage +} + +if [ -z "$DIR" ] || [ "$(realpath "$DIR")" = / ]; then + usage +fi + # Set some defaults and enable promtless ssh to the machine for root. sudo sed -i '/^root/ { s/:x:/::/ }' $DIR/etc/passwd echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100' | sudo tee -a $DIR/etc/inittab diff --git a/scripts/create-image/debootstrap.sh b/scripts/create-image/debootstrap.sh old mode 100755 new mode 100644 From a57a368ee336488c7f916db0c188633042666dac Mon Sep 17 00:00:00 2001 From: tesuji Date: Thu, 13 Nov 2025 10:24:11 +0000 Subject: [PATCH 3/3] fix typos and prefer coreutils readlink --- README.md | 2 +- scripts/create-image/Dockerfile | 4 ++-- scripts/create-image/configure.sh | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fca9d6c..9b9c266 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Or if you prefer using docker to build your image: ~~~ cd scripts/create-image/ docker build -t img . -docker run -v $(pwd):/mnt --privileged --rm img +docker run -v "$(pwd)":/mnt --privileged --rm img ~~~ Notice that `privileged` is necessary because we want to use `/dev/loop*` inside docker. diff --git a/scripts/create-image/Dockerfile b/scripts/create-image/Dockerfile index 8778b11..0a51c96 100644 --- a/scripts/create-image/Dockerfile +++ b/scripts/create-image/Dockerfile @@ -30,7 +30,7 @@ WORKDIR /src COPY --chmod=0755 debootstrap.sh /src/ RUN ./debootstrap.sh -# will copy the img file to /mnt. Need --privilege flag for docker run. +# will copy the img file to /mnt. Need --privileged flag for docker run. COPY --chmod=0755 configure.sh /src/ -CMD ["bash", "-c", "set -ex; source ./configure.sh"] +CMD ["bash", "-c", "set -ex; source /src/configure.sh"] diff --git a/scripts/create-image/configure.sh b/scripts/create-image/configure.sh index 5b71d7d..6ceba96 100644 --- a/scripts/create-image/configure.sh +++ b/scripts/create-image/configure.sh @@ -3,7 +3,7 @@ # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. usage() { - echo "Please use the ./create-image.sh instead." >&2 + echo "Please use ./create-image.sh instead." >&2 exit 1 } @@ -12,7 +12,7 @@ usage() { usage } -if [ -z "$DIR" ] || [ "$(realpath "$DIR")" = / ]; then +if [ -z "$DIR" ] || [ "$(readlink -f "$DIR")" = / ]; then usage fi