aboutsummaryrefslogtreecommitdiffstats
path: root/tools/create-gce-image.sh
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-05-14 11:16:36 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-05-14 11:16:36 +0200
commitea9496cdbdfc9679a413f184502bb6d33bf44c6a (patch)
tree0f17d2a9d70731692fd72d95a6a0b743c226eb05 /tools/create-gce-image.sh
parent481f030ccdc0fc0749f595c1f21b8c7c101387b2 (diff)
tools/create-gce-image.sh: use loop instead of nbd
loop is much more standard than nbd and does not require additional modules. nbd broke on Debian rolling. loop also allows parallel execution thanks to losetup -f. Use loop instead of nbd. Also improve cleanup logic and add one missing sudo. Update #501
Diffstat (limited to 'tools/create-gce-image.sh')
-rwxr-xr-xtools/create-gce-image.sh37
1 files changed, 19 insertions, 18 deletions
diff --git a/tools/create-gce-image.sh b/tools/create-gce-image.sh
index 348ebd8ca..834aa7b76 100755
--- a/tools/create-gce-image.sh
+++ b/tools/create-gce-image.sh
@@ -8,9 +8,8 @@
# Prerequisites:
# - you need a user-space system, a basic Debian system can be created with:
# sudo debootstrap --include=openssh-server,curl,tar,gcc,libc6-dev,time,strace,sudo,less,psmisc,selinux-utils,policycoreutils,checkpolicy,selinux-policy-default stable debian
-# - you need qemu-nbd, grub and maybe something else:
+# - you need grub and maybe something else:
# sudo apt-get install qemu-utils grub-efi
-# - you need nbd support in kernel
# - you need kernel to use with image (e.g. arch/x86/boot/bzImage)
# note: kernel modules are not supported
#
@@ -47,6 +46,9 @@ set -eux
# If you really need to kill it, use a different signal. But better wait.
trap "" SIGINT
+CLEANUP=""
+trap 'eval " $CLEANUP"' EXIT
+
if [ ! -e $1/sbin/init ]; then
echo "usage: create-gce-image.sh /dir/with/user/space/system /path/to/bzImage"
exit 1
@@ -57,19 +59,18 @@ if [ "$(basename $2)" != "bzImage" ]; then
exit 1
fi
-# Clean up after previous unsuccessful run.
-sudo umount disk.mnt || true
-sudo qemu-nbd -d /dev/nbd0 || true
-rm -rf disk.mnt disk.raw tag obj || true
-
-sudo modprobe nbd
+rm -rf disk.mnt disk.raw || true
fallocate -l 2G disk.raw
-sudo qemu-nbd -c /dev/nbd0 --format=raw disk.raw
+echo -en "o\nn\np\n1\n\n\na\nw\n" | sudo fdisk disk.raw
+LODEV="$(sudo losetup -f --show -P disk.raw)"
+LODEVPART=$LODEV"p1"
+CLEANUP="sudo losetup -d $LODEV; $CLEANUP"
+until [ -e $LODEVPART ]; do sleep 1; done
+sudo mkfs.ext4 $LODEVPART
mkdir -p disk.mnt
-echo -en "o\nn\np\n1\n2048\n\na\n1\nw\n" | sudo fdisk /dev/nbd0
-until [ -e /dev/nbd0p1 ]; do sleep 1; done
-sudo mkfs.ext4 /dev/nbd0p1
-sudo mount /dev/nbd0p1 disk.mnt
+CLEANUP="rm -rf disk.mnt; $CLEANUP"
+sudo mount $LODEVPART disk.mnt
+CLEANUP="sudo umount disk.mnt; $CLEANUP"
sudo cp -a $1/. disk.mnt/.
sudo cp $2 disk.mnt/vmlinuz
sudo sed -i "/^root/ { s/:x:/::/ }" disk.mnt/etc/passwd
@@ -79,7 +80,7 @@ echo "debugfs /sys/kernel/debug debugfs defaults 0 0" | sudo tee -a disk.mnt/etc
echo 'binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0' | sudo tee -a disk.mnt/etc/fstab
for i in {0..31}; do
echo "KERNEL==\"binder$i\", NAME=\"binder$i\", MODE=\"0666\"" | \
- tee -a disk.mnt/etc/udev/50-binder.rules
+ sudo tee -a disk.mnt/etc/udev/50-binder.rules
done
# We disable selinux for now because the default policy on wheezy prevents
# mounting of cgroup2 (and stretch we don't know how to configure yet).
@@ -131,7 +132,7 @@ menuentry 'linux' --class gnu-linux --class gnu --class os {
linux /vmlinuz root=/dev/sda1 console=ttyS0 earlyprintk=serial vsyscall=native rodata=n ftrace_dump_on_oops=orig_cpu oops=panic panic_on_warn=1 nmi_watchdog=panic panic=86400 $CMDLINE
}
EOF
-sudo grub-install --target=i386-pc --boot-directory=disk.mnt/boot --no-floppy /dev/nbd0
-sudo umount disk.mnt
-rm -rf disk.mnt
-sudo qemu-nbd -d /dev/nbd0
+sudo grub-install --target=i386-pc --boot-directory=disk.mnt/boot --no-floppy $LODEV
+#sudo umount disk.mnt
+#rm -rf disk.mnt
+#sudo losetup -d $LODEV