From 8e51bdb10db34d2ad6da49d57c0671f40fb22b40 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 19 Mar 2021 08:57:33 -0700 Subject: [PATCH] Try writing zero bytes to "/dev/kvm" as a more robust test for access Looking at https://lwn.net/Articles/658511/, this seems like it should be reasonably harmless as a simple test of whether we can expect `/dev/kvm` to work. Fixes #4 --- 4.2/start-qemu | 3 ++- 5.0/start-qemu | 3 ++- 5.1/start-qemu | 3 ++- 5.2/start-qemu | 3 ++- start-qemu | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/4.2/start-qemu b/4.2/start-qemu index 897fac2..908443c 100755 --- a/4.2/start-qemu +++ b/4.2/start-qemu @@ -25,7 +25,8 @@ if [ -z "${QEMU_NO_SSH:-}" ]; then fi qemuPorts+=( ${QEMU_PORTS:-} ) -if [ -e /dev/kvm ]; then +if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + # https://github.com/tianon/docker-qemu/issues/4 qemuArgs+=( -enable-kvm ) elif [ "$hostArch" = "$qemuArch" ]; then echo >&2 diff --git a/5.0/start-qemu b/5.0/start-qemu index 897fac2..908443c 100755 --- a/5.0/start-qemu +++ b/5.0/start-qemu @@ -25,7 +25,8 @@ if [ -z "${QEMU_NO_SSH:-}" ]; then fi qemuPorts+=( ${QEMU_PORTS:-} ) -if [ -e /dev/kvm ]; then +if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + # https://github.com/tianon/docker-qemu/issues/4 qemuArgs+=( -enable-kvm ) elif [ "$hostArch" = "$qemuArch" ]; then echo >&2 diff --git a/5.1/start-qemu b/5.1/start-qemu index 897fac2..908443c 100755 --- a/5.1/start-qemu +++ b/5.1/start-qemu @@ -25,7 +25,8 @@ if [ -z "${QEMU_NO_SSH:-}" ]; then fi qemuPorts+=( ${QEMU_PORTS:-} ) -if [ -e /dev/kvm ]; then +if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + # https://github.com/tianon/docker-qemu/issues/4 qemuArgs+=( -enable-kvm ) elif [ "$hostArch" = "$qemuArch" ]; then echo >&2 diff --git a/5.2/start-qemu b/5.2/start-qemu index 897fac2..908443c 100755 --- a/5.2/start-qemu +++ b/5.2/start-qemu @@ -25,7 +25,8 @@ if [ -z "${QEMU_NO_SSH:-}" ]; then fi qemuPorts+=( ${QEMU_PORTS:-} ) -if [ -e /dev/kvm ]; then +if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + # https://github.com/tianon/docker-qemu/issues/4 qemuArgs+=( -enable-kvm ) elif [ "$hostArch" = "$qemuArch" ]; then echo >&2 diff --git a/start-qemu b/start-qemu index 897fac2..908443c 100755 --- a/start-qemu +++ b/start-qemu @@ -25,7 +25,8 @@ if [ -z "${QEMU_NO_SSH:-}" ]; then fi qemuPorts+=( ${QEMU_PORTS:-} ) -if [ -e /dev/kvm ]; then +if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then + # https://github.com/tianon/docker-qemu/issues/4 qemuArgs+=( -enable-kvm ) elif [ "$hostArch" = "$qemuArch" ]; then echo >&2