aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAndrew Donnellan <ajd@linux.ibm.com>2025-12-15 14:34:12 +1100
committerAleksandr Nogikh <nogikh@google.com>2025-12-18 10:02:13 +0000
commite14dbeb99dc80832252033b9ed81b85b13bef5c4 (patch)
tree9ab855014eb0ec9ea4496ed78131c2b32079a1e2 /tools
parentd16e3a6cf5569a127b892117931aa2066c7af65c (diff)
tools/create-image.sh: add option to specify output prefix
Add an option, -o / --output, to specify a prefix used for the name of the directory where debootstrap generates the system, and the final disk image and SSH key filenames. The default remains using the distro release codename. For now, ban the use of slashes, spaces, . and .. as output names. Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/create-image.sh24
1 files changed, 18 insertions, 6 deletions
diff --git a/tools/create-image.sh b/tools/create-image.sh
index a760ff9d1..a489ce037 100755
--- a/tools/create-image.sh
+++ b/tools/create-image.sh
@@ -29,9 +29,12 @@ display_help() {
echo " -d, --distribution Set on which Debian distribution to create (default: $RELEASE)"
echo " -f, --feature Check what packages to install in the image, options are minimal, full (default: $FEATURE)"
echo " -h, --help Display help message"
+ echo " -o, --output Set output prefix (default: value of --distribution)"
echo " -p, --add-perf Add perf support. Requires environment variable \$KERNEL pointing to kernel source tree"
echo " -s, --seek Image size in MB (default: $(($SEEK + 1)))"
echo
+ echo "The chroot will be created in ./<output>, the final image will be created in ./<output>.img, and SSH keys will be named"
+ echo "./<output>.id_rsa[.pub]."
}
while true; do
@@ -56,6 +59,15 @@ while true; do
FEATURE=$2
shift 2
;;
+ -o | --output)
+ if [[ "$2" == *"/"* || "$2" == *" "* || "$2" == "." || "$2" == ".." ]]
+ then
+ echo "Error: output prefix cannot contain /, spaces, or be . or .."
+ exit 1
+ fi
+ OUTPUT="$2"
+ shift 2
+ ;;
-p | --add-perf)
PERF=true
shift 1
@@ -127,7 +139,7 @@ if [ $FEATURE = "full" ]; then
PREINSTALL_PKGS=$PREINSTALL_PKGS","$ADD_PACKAGE
fi
-DIR=$RELEASE
+DIR="${OUTPUT:-$RELEASE}"
sudo rm -rf $DIR
sudo mkdir -p $DIR
sudo chmod 0755 $DIR
@@ -174,9 +186,9 @@ echo 'binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0' | sudo tee
echo -en "127.0.0.1\tlocalhost\n" | sudo tee $DIR/etc/hosts
echo "nameserver 8.8.8.8" | sudo tee -a $DIR/etc/resolv.conf
echo "syzkaller" | sudo tee $DIR/etc/hostname
-ssh-keygen -f $RELEASE.id_rsa -t rsa -N ''
+ssh-keygen -f $DIR.id_rsa -t rsa -N ''
sudo mkdir -p $DIR/root/.ssh/
-cat $RELEASE.id_rsa.pub | sudo tee $DIR/root/.ssh/authorized_keys
+cat $DIR.id_rsa.pub | sudo tee $DIR/root/.ssh/authorized_keys
# Add perf support
if [ $PERF = "true" ]; then
@@ -195,9 +207,9 @@ fi
echo 'ATTR{name}=="vim2m", SYMLINK+="vim2m"' | sudo tee -a $DIR/etc/udev/rules.d/50-udev-default.rules
# Build a disk image
-dd if=/dev/zero of=$RELEASE.img bs=1M seek=$SEEK count=1
-sudo mkfs.ext4 -F $RELEASE.img
+dd if=/dev/zero of=$DIR.img bs=1M seek=$SEEK count=1
+sudo mkfs.ext4 -F $DIR.img
sudo mkdir -p /mnt/$DIR
-sudo mount -o loop $RELEASE.img /mnt/$DIR
+sudo mount -o loop $DIR.img /mnt/$DIR
sudo cp -a $DIR/. /mnt/$DIR/.
sudo umount /mnt/$DIR