Using QEMU
I use QEMU to test my ansible-desktop repository (automatic setup of a Debian workstation using Ansible). This page acts as a personal reminder about managing the QEMU image.
- [host] Install the
qemu-system-x86
package. This should installqemu-utils
as a recommended package, which providesqemu-img
. [host] Create an image:
qemu-img create debian.img 8G
[host] Boot the image using QEMU. Pass it the Debian iso as an argument:
qemu-system-x86_64 -hda debian.img -cdrom ~/tmp/downloads/debian-11.0.0-amd64-netinst.iso -boot d -m 2048 -enable-kvm
- [guest] Install Debian.
[host] Run the image with a port forwarding from the host's port 2222 to the guest's port 22:
qemu-system-x86_64 -hda debian.img -m 2048 -enable-kvm -net user,hostfwd=tcp::2222-:22 -net nic
- [guest] As root, install
openssh-server
. [host] You should be able to connect to the guest from the host using SSH:
ssh alc@localhost -p 2222
[host] If necessary, transfer some useful files from the host to the guest…
scp -P 2222 file.txt alc@localhost:/home/alc
[guest] …or from guest to host (using the local network):
scp file.txt alc@[ip-on-local-network]:/home/alc
[host] Run the image in snapshot mode so you won't alter it:
qemu-system-x86_64 -hda debian.img -m 2048 -snapshot -enable-kvm
At this point I can test things out and always return to the same basic machine state.