Dockerization of supported QEMU releases
Go to file
Namhyeon, Go 961da5ff5d
Fix repository error on debian:bullseye-slim
Fix repository error on latest debian:bullseye-slim base image
2022-11-01 22:21:01 +09:00
.github/workflows Use jq-template.awk 2020-08-27 16:34:48 -07:00
5.2 change the repository server 2022-01-06 17:36:22 +09:00
6.0 Fix repository error on debian:bullseye-slim 2022-11-01 22:21:01 +09:00
6.1 Fix repository error on debian:bullseye-slim 2022-11-01 22:20:10 +09:00
.gitattributes Fix .gitattributes specificity 2020-10-16 16:28:51 -07:00
.gitignore Use jq-template.awk 2020-08-27 16:34:48 -07:00
apply-templates.sh Add explicit "native" variants 2021-03-20 22:10:01 -07:00
Dockerfile.template change the repository server 2022-01-06 17:36:22 +09:00
generate-stackbrew-library.sh Add 6.1.0 2021-08-24 13:48:22 -07:00
README.md Update README.md 2021-12-31 03:25:54 +09:00
start-qemu Try writing zero bytes to "/dev/kvm" as a more robust test for access 2021-03-19 08:57:33 -07:00
update.sh Use jq-template.awk 2020-08-27 16:34:48 -07:00
versions.json Add 6.1.0 2021-08-24 13:48:22 -07:00
versions.sh Use jq-template.awk 2020-08-27 16:34:48 -07:00

gnh1201/docker-qemu

This repository is forked from tianon/docker-qemu

$ touch /home/jsmith/hda.qcow2
$ docker run -it --rm \
	--device /dev/kvm \
	--name qemu-container \
	-v /home/jsmith/hda.qcow2:/tmp/hda.qcow2 \
	-e QEMU_HDA=/tmp/hda.qcow2 \
	-e QEMU_HDA_SIZE=100G \
	-e QEMU_CPU=4 \
	-e QEMU_RAM=4096 \
	-v /home/jsmith/downloads/debian.iso:/tmp/debian.iso:ro \
	-e QEMU_CDROM=/tmp/debian.iso \
	-e QEMU_BOOT='order=d' \
	-e QEMU_PORTS='2375 2376' \
	tianon/qemu:native

Note: port 22 will always be mapped (regardless of the contents of QEMU_PORTS).

For supplying additional arguments, use a command of start-qemu <args>. For example, to use -curses, one would docker run ... tianon/qemu start-qemu -curses.

For UEFI support, the ovmf package is installed, which can be utilized most easily by supplying --bios /usr/share/ovmf/OVMF.fd.

By default, this image will use QEMU's user-mode networking stack, which means if you want ping/ICMP working, you'll likely need to also include something like --sysctl net.ipv4.ping_group_range='0 2147483647' in your container runtime settings.

The native variants for amd64 only contain qemu-system-x86_64 -- the non-native variants contain QEMU compiled for a variety of target CPUs.

Build Docker image

$ git clone https://github.com/gnh1201/docker-qemu
$ cd docker-qemu
$ docker build -t gnh1201/qemu:6.1 .

For non-native

Note: Non-native virtualization does not support KVM acceleration (Do not use --device /dev/kvm).

ARM

$ touch /hdimages/armhf.qcow2
$ docker run -it --rm \
    --name qemu-container-arm \
    --user="$(id --user):$(id --group)" \
    -v /hdimages/armhf.qcow2:/tmp/hda.qcow2 \
    -v /bootimages/initrd-debian11-armhf.gz:/tmp/initrd.gz \
    -v /bootimages/vmlinuz-debian11-armhf:/tmp/vmlinuz \
    -e QEMU_HDA=/tmp/hda.qcow2 \
    -e QEMU_HDA_SIZE=20G \
    -e QEMU_CPU=1 \
    -e QEMU_RAM=1024 \
    -v /cdimages/debian-11.1.0-armhf-netinst.iso:/tmp/debian.iso:ro \
    -e QEMU_CDROM=/tmp/debian.iso \
    -e QEMU_BOOT='order=d' \
    -e QEMU_PORTS='2375 2376' \
    -e QEMU_ARCH='arm' \
    -e QEMU_MACHINE='virt' \
    -e QEMU_KERNEL=/tmp/vmlinuz \
    -e QEMU_INITRD=/tmp/initrd.gz \
    gnh1201/qemu:6.1

MIPS

$ touch /hdimages/mips64el.qcow2
$ docker run -it --rm \
    --name qemu-container-mips64el \
    --user="$(id --user):$(id --group)" \
    -v /hdimages/mips64el.qcow2:/tmp/hda.qcow2 \
    -v /bootimages/debian11-mips64el-malta/initrd.gz:/tmp/initrd.gz \
    -v /bootimages/debian11-mips64el-malta/vmlinuz-5.10.0-9-5kc-malta:/tmp/vmlinuz \
    -e QEMU_HDA=/tmp/hda.qcow2 \
    -e QEMU_HDA_SIZE=20G \
    -e QEMU_CPU=1 \
    -e QEMU_RAM=1024 \
    -v /cdimages/debian-11.1.0-mips64el-netinst.iso:/tmp/debian.iso:ro \
    -e QEMU_CDROM=/tmp/debian.iso \
    -e QEMU_BOOT='order=d' \
    -e QEMU_PORTS='2375 2376' \
    -e QEMU_ARCH='mips64el' \
    -e QEMU_MACHINE='malta' \
    -e QEMU_CPUMODEL='5KEc' \
    -e QEMU_KERNEL=/tmp/vmlinuz \
    -e QEMU_INITRD=/tmp/initrd.gz \
    -e QEMU_APPEND='console=ttyS0' \
    gnh1201/qemu:6.1

If ARM or MIPS is selected, vmlinuz(kernel image) and initrd are required. Please refer to this article and proceed.

Manually bootloader activation

When using the non-native (e.g. ARM, MIPS) platform, the bootloader must be extracted manually after the installation is completed.

$ qemu-img convert armhf.qcow2 armhf.raw
$ sudo mkdir /mnt/tmp
$ sudo mount -o loop,offset=$((2048 * 512)) armhf.raw /mnt/tmp
$ cd /mnt/tmp/boot

Then, copy the initrd and vmlinuz files to an external directory. And load using QEMU_KERNEL and QEMU_INITRD variables.

Manually root activation

When using the non-native (e.g. ARM, MIPS) platform, it was confirmed that the settings were not reflected in /etc/passwd and /etc/shadow. Please refer to the two links below and set them up manually.