Skip to content

Commit e14dbeb

Browse files
ajdlinuxa-nogikh
authored andcommitted
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>
1 parent d16e3a6 commit e14dbeb

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tools/create-image.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ display_help() {
2929
echo " -d, --distribution Set on which Debian distribution to create (default: $RELEASE)"
3030
echo " -f, --feature Check what packages to install in the image, options are minimal, full (default: $FEATURE)"
3131
echo " -h, --help Display help message"
32+
echo " -o, --output Set output prefix (default: value of --distribution)"
3233
echo " -p, --add-perf Add perf support. Requires environment variable \$KERNEL pointing to kernel source tree"
3334
echo " -s, --seek Image size in MB (default: $(($SEEK + 1)))"
3435
echo
36+
echo "The chroot will be created in ./<output>, the final image will be created in ./<output>.img, and SSH keys will be named"
37+
echo "./<output>.id_rsa[.pub]."
3538
}
3639

3740
while true; do
@@ -56,6 +59,15 @@ while true; do
5659
FEATURE=$2
5760
shift 2
5861
;;
62+
-o | --output)
63+
if [[ "$2" == *"/"* || "$2" == *" "* || "$2" == "." || "$2" == ".." ]]
64+
then
65+
echo "Error: output prefix cannot contain /, spaces, or be . or .."
66+
exit 1
67+
fi
68+
OUTPUT="$2"
69+
shift 2
70+
;;
5971
-p | --add-perf)
6072
PERF=true
6173
shift 1
@@ -127,7 +139,7 @@ if [ $FEATURE = "full" ]; then
127139
PREINSTALL_PKGS=$PREINSTALL_PKGS","$ADD_PACKAGE
128140
fi
129141

130-
DIR=$RELEASE
142+
DIR="${OUTPUT:-$RELEASE}"
131143
sudo rm -rf $DIR
132144
sudo mkdir -p $DIR
133145
sudo chmod 0755 $DIR
@@ -174,9 +186,9 @@ echo 'binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0' | sudo tee
174186
echo -en "127.0.0.1\tlocalhost\n" | sudo tee $DIR/etc/hosts
175187
echo "nameserver 8.8.8.8" | sudo tee -a $DIR/etc/resolv.conf
176188
echo "syzkaller" | sudo tee $DIR/etc/hostname
177-
ssh-keygen -f $RELEASE.id_rsa -t rsa -N ''
189+
ssh-keygen -f $DIR.id_rsa -t rsa -N ''
178190
sudo mkdir -p $DIR/root/.ssh/
179-
cat $RELEASE.id_rsa.pub | sudo tee $DIR/root/.ssh/authorized_keys
191+
cat $DIR.id_rsa.pub | sudo tee $DIR/root/.ssh/authorized_keys
180192

181193
# Add perf support
182194
if [ $PERF = "true" ]; then
@@ -195,9 +207,9 @@ fi
195207
echo 'ATTR{name}=="vim2m", SYMLINK+="vim2m"' | sudo tee -a $DIR/etc/udev/rules.d/50-udev-default.rules
196208

197209
# Build a disk image
198-
dd if=/dev/zero of=$RELEASE.img bs=1M seek=$SEEK count=1
199-
sudo mkfs.ext4 -F $RELEASE.img
210+
dd if=/dev/zero of=$DIR.img bs=1M seek=$SEEK count=1
211+
sudo mkfs.ext4 -F $DIR.img
200212
sudo mkdir -p /mnt/$DIR
201-
sudo mount -o loop $RELEASE.img /mnt/$DIR
213+
sudo mount -o loop $DIR.img /mnt/$DIR
202214
sudo cp -a $DIR/. /mnt/$DIR/.
203215
sudo umount /mnt/$DIR

0 commit comments

Comments
 (0)