diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-09-07 19:04:47 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-09-07 19:04:47 +0200 |
| commit | 6b5120a46407f0462e664e15fed3eae5da951c75 (patch) | |
| tree | 07645ed5e18bd92595684b272ccf3c07b5e01649 | |
| parent | be20da425029ecd45b18e99fa5f09691ba0658ea (diff) | |
tools/create-gce-image.sh: auto-detect block device type
Currently we choose block device to use (nbd/loop) based on SYZ_VM_TYPE.
Strictly saying these things are orthogonal.
losetup is broken on Ubuntu. qemu-nbd is broken on Debian.
Try to auto-detect what will work based on uname.
| -rw-r--r-- | pkg/build/linux_generated.go | 13 | ||||
| -rwxr-xr-x | tools/create-gce-image.sh | 24 |
2 files changed, 27 insertions, 10 deletions
diff --git a/pkg/build/linux_generated.go b/pkg/build/linux_generated.go index 14df94954..28e9355e1 100644 --- a/pkg/build/linux_generated.go +++ b/pkg/build/linux_generated.go @@ -30,20 +30,25 @@ else exit 1 fi +BLOCK_DEVICE="loop" +if [ "$(uname -a | grep Ubuntu)" != "" ]; then + BLOCK_DEVICE="nbd" +fi + sudo umount disk.mnt || true -if [ "$SYZ_VM_TYPE" == "qemu" ]; then +if [ "$BLOCK_DEVICE" == "loop" ]; then : -elif [ "$SYZ_VM_TYPE" == "gce" ]; then +elif [ "$BLOCK_DEVICE" == "nbd" ]; then sudo modprobe nbd sudo qemu-nbd -d /dev/nbd0 || true fi rm -rf disk.mnt disk.raw || true fallocate -l 2G disk.raw -if [ "$SYZ_VM_TYPE" == "qemu" ]; then +if [ "$BLOCK_DEVICE" == "loop" ]; then DISKDEV="$(sudo losetup -f --show -P disk.raw)" CLEANUP="sudo losetup -d $DISKDEV; $CLEANUP" -elif [ "$SYZ_VM_TYPE" == "gce" ]; then +elif [ "$BLOCK_DEVICE" == "nbd" ]; then DISKDEV="/dev/nbd0" sudo qemu-nbd -c $DISKDEV --format=raw disk.raw CLEANUP="sudo qemu-nbd -d $DISKDEV; $CLEANUP" diff --git a/tools/create-gce-image.sh b/tools/create-gce-image.sh index 0db7fc065..ce880772e 100755 --- a/tools/create-gce-image.sh +++ b/tools/create-gce-image.sh @@ -17,8 +17,8 @@ # ./create-gce-image.sh /dir/with/user/space/system /path/to/bzImage # # SYZ_VM_TYPE env var controls type of target test machine. Supported values: -# - qemu (default, uses /dev/loop) -# - gce (uses /dev/nbd0) +# - qemu (default) +# - gce # Needs nbd support in kernel and qemu-utils (qemu-nbd) installed. # # If SYZ_SYSCTL_FILE env var is set and points to a file, @@ -70,21 +70,33 @@ else exit 1 fi +# qemu-nbd is broken on Debian with: +# Calling ioctl() to re-read partition table. +# Re-reading the partition table failed.: Invalid argument +# The kernel still uses the old table. The new table will be used at the +# next reboot or after you run partprobe(8) or kpartx(8). +# losetup is broken on Ubuntu with some other error. +# Try to figure out what will work. +BLOCK_DEVICE="loop" +if [ "$(uname -a | grep Ubuntu)" != "" ]; then + BLOCK_DEVICE="nbd" +fi + # Clean up after previous unsuccessful run. sudo umount disk.mnt || true -if [ "$SYZ_VM_TYPE" == "qemu" ]; then +if [ "$BLOCK_DEVICE" == "loop" ]; then : -elif [ "$SYZ_VM_TYPE" == "gce" ]; then +elif [ "$BLOCK_DEVICE" == "nbd" ]; then sudo modprobe nbd sudo qemu-nbd -d /dev/nbd0 || true fi rm -rf disk.mnt disk.raw || true fallocate -l 2G disk.raw -if [ "$SYZ_VM_TYPE" == "qemu" ]; then +if [ "$BLOCK_DEVICE" == "loop" ]; then DISKDEV="$(sudo losetup -f --show -P disk.raw)" CLEANUP="sudo losetup -d $DISKDEV; $CLEANUP" -elif [ "$SYZ_VM_TYPE" == "gce" ]; then +elif [ "$BLOCK_DEVICE" == "nbd" ]; then DISKDEV="/dev/nbd0" sudo qemu-nbd -c $DISKDEV --format=raw disk.raw CLEANUP="sudo qemu-nbd -d $DISKDEV; $CLEANUP" |
