From 94f2d2cd9ada01fffcca94f883a403686e1f7cea Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Thu, 13 Jul 2017 11:14:20 +0100 Subject: [PATCH] linuxkit: Fix qemu run behaviour when file does not exist This commit fixes an issue reported on Slack where `linuxkit run` will assume that a file that is neither a kernel or iso must be a disk image without first checking that it exists. This would result in `qemu-img` attempting to create a disk with 0 size due to the default behaviour of creating disk images that do not exist. Signed-off-by: Dave Tucker --- src/cmd/linuxkit/run_qemu.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 354e1bdae..f072c0d54 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -170,6 +170,9 @@ func runQemu(args []string) { // user not trying to boot off ISO or kernel, so assume booting from a disk image if !*kernelBoot && !*isoBoot { + if _, err := os.Stat(path); err != nil { + log.Fatalf("Boot disk image %s does not exist", path) + } // currently no way to set format, but autodetect probably works d := Disks{DiskConfig{Path: path}} disks = append(d, disks...)