Check if /dev/kvm exists and prefer to mount that device rather than start a privileged container

This commit is contained in:
Héctor Molinero Fernández 2021-08-02 21:23:21 +02:00
parent c4905ecf00
commit d9b34fadd2
3 changed files with 7 additions and 4 deletions

View File

@ -8,7 +8,7 @@ docker run --detach \
--name qemu-reactos \ --name qemu-reactos \
--restart on-failure:3 \ --restart on-failure:3 \
--publish 127.0.0.1:6080:6080/tcp \ --publish 127.0.0.1:6080:6080/tcp \
--privileged --env QEMU_VM_KVM=true \ --env QEMU_VM_KVM=true --device /dev/kvm \
docker.io/hectormolinero/qemu-reactos:latest docker.io/hectormolinero/qemu-reactos:latest
``` ```
> The instance will be available through a web browser from: http://localhost:6080/vnc.html > The instance will be available through a web browser from: http://localhost:6080/vnc.html
@ -40,7 +40,7 @@ VM boot menu (`off` by default).


#### `QEMU_VM_KVM` #### `QEMU_VM_KVM`
Start QEMU in KVM mode (`false` by default). Start QEMU in KVM mode (`false` by default).
> The `--privileged` option is required to use KVM in the container. > The `--device /dev/kvm` option is required to use KVM in the container.


## License ## License
See the [license](LICENSE.md) file. See the [license](LICENSE.md) file.

2
run.sh
View File

@ -40,7 +40,7 @@ printf -- '%s\n' "Creating \"${CONTAINER_NAME:?}\" container..."
--publish '127.0.0.1:5900:5900/tcp' \ --publish '127.0.0.1:5900:5900/tcp' \
--publish '127.0.0.1:6080:6080/tcp' \ --publish '127.0.0.1:6080:6080/tcp' \
--publish '127.0.0.1:15900:15900/tcp' \ --publish '127.0.0.1:15900:15900/tcp' \
--privileged --env QEMU_VM_KVM=true \ --env QEMU_VM_KVM=true --device /dev/kvm \
"${IMAGE_NAME:?}" "$@" >/dev/null "${IMAGE_NAME:?}" "$@" >/dev/null


printf -- '%s\n\n' 'Done!' printf -- '%s\n\n' 'Done!'

View File

@ -11,7 +11,10 @@ QEMU_ARGS="${QEMU_ARGS-} -boot order=${QEMU_VM_BOOT_ORDER:?},menu=${QEMU_VM_BOOT
QEMU_ARGS="${QEMU_ARGS-} -netdev user,id=n0,${QEMU_VM_NET_OPTIONS:?} -device ${QEMU_VM_NET_DEVICE:?},netdev=n0" QEMU_ARGS="${QEMU_ARGS-} -netdev user,id=n0,${QEMU_VM_NET_OPTIONS:?} -device ${QEMU_VM_NET_DEVICE:?},netdev=n0"
QEMU_ARGS="${QEMU_ARGS-} -usb -device usb-tablet" QEMU_ARGS="${QEMU_ARGS-} -usb -device usb-tablet"
QEMU_ARGS="${QEMU_ARGS-} -k ${QEMU_VM_KEYBOARD:?}" QEMU_ARGS="${QEMU_ARGS-} -k ${QEMU_VM_KEYBOARD:?}"
if [ "${QEMU_VM_KVM:?}" = true ]; then QEMU_ARGS="${QEMU_ARGS-} -enable-kvm"; fi
if [ "${QEMU_VM_KVM:?}" = true ] && [ -c /dev/kvm ]; then
QEMU_ARGS="${QEMU_ARGS-} -enable-kvm"
fi


cd /var/lib/qemu/ cd /var/lib/qemu/
exec 2>&1 exec 2>&1