aboutsummaryrefslogtreecommitdiffstats
path: root/tools/create-gce-image.sh
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-05-14 19:32:39 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-05-14 19:32:39 +0200
commit86ea19e4c2dac00bda532edaf45507f10e9da575 (patch)
tree6dd2c3cab8127ccfa2c58ec3fda21e073767ebfc /tools/create-gce-image.sh
parent9467cacb1c3020e2a7ddd60b40dfbbf5a1733785 (diff)
tools/create-gce-image.sh: revert loop to nbd
loop devices are nice, but unfortunately this creates images that does not boot on GCE. Reason is unclear. Revert back to nbd for now.
Diffstat (limited to 'tools/create-gce-image.sh')
-rwxr-xr-xtools/create-gce-image.sh26
1 files changed, 14 insertions, 12 deletions
diff --git a/tools/create-gce-image.sh b/tools/create-gce-image.sh
index 834aa7b76..be1d0c889 100755
--- a/tools/create-gce-image.sh
+++ b/tools/create-gce-image.sh
@@ -8,8 +8,9 @@
# 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 grub and maybe something else:
+# - you need qemu-nbd, 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
#
@@ -59,17 +60,21 @@ 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 || true
+
+sudo modprobe nbd
fallocate -l 2G 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
+sudo qemu-nbd -c /dev/nbd0 --format=raw disk.raw
+CLEANUP="sudo qemu-nbd -d /dev/nbd0; $CLEANUP"
+echo -en "o\nn\np\n1\n\n\na\nw\n" | sudo fdisk /dev/nbd0
+until [ -e /dev/nbd0p1 ]; do sleep 1; done
+sudo mkfs.ext4 /dev/nbd0p1
mkdir -p disk.mnt
CLEANUP="rm -rf disk.mnt; $CLEANUP"
-sudo mount $LODEVPART disk.mnt
+sudo mount /dev/nbd0p1 disk.mnt
CLEANUP="sudo umount disk.mnt; $CLEANUP"
sudo cp -a $1/. disk.mnt/.
sudo cp $2 disk.mnt/vmlinuz
@@ -132,7 +137,4 @@ 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 $LODEV
-#sudo umount disk.mnt
-#rm -rf disk.mnt
-#sudo losetup -d $LODEV
+sudo grub-install --target=i386-pc --boot-directory=disk.mnt/boot --no-floppy /dev/nbd0