VirtualBox to QEMU
This is a basic configuration file (vmconfig.sh
):
```
bridged or routed or nat
VMNETWORKLINK=nat
VMBRIDGEIF=br0
VMNUMBER=24 VMTAPDEV0=tap${VMNUMBER} VMMACADDR0=84:8f:69:a9:52:a5 VMNAME=ubuntu VMVNCIP=0.0.0.0 VMSPICEIP=0.0.0.0 VMSPICEPORT=59${VMNUMBER} VMIMAGENAME=Ubuntu24.04VB_LinuxVMImages.COM.vdi VMIMAGEFORMAT=vdi VMPASSTHRU=${PWD} VMRAMMB=2048 VMCLIIP="192.168.80.${VMNUMBER}" VMDISPLAY="-display vnc=0.0.0.0:${VMNUMBER}" ```
This is a file that uses some of the values from the above configuration
(vmstart_bios.sh
):
```
!/bin/sh
source ./vmconfig.sh qemu-system-x8664 -name ${VMNAME} \ -nodefaults \ -accel kvm \ -machine q35 \ -cpu host \ -smp 2 \ -rtc base=utc \ -vga virtio \ -usbdevice tablet \ ${VMDISPLAY} \ -m ${VMRAMMB} \ -drive file=${VMIMAGENAME},format=${VMIMAGEFORMAT},if=virtio \ -fsdev local,id=exp1,path=${VMPASSTHRU},securitymodel=passthrough \ -device virtio-9p-pci,fsdev=exp1,mount_tag=host${VMNAME} \ -device virtio-net-pci,netdev=netdev0,mac=${VMMACADDR0} \ -netdev user,id=netdev0,net=192.168.76.0/24,dhcpstart=192.168.76.9,hostfwd=tcp::2022-:22,hostfwd=tcp::2443-:443,hostfwd=tcp::2080-:80 ```
The image was downloaded from https://www.linuxvmimages.com/images/ubuntu-2404/ IMPORTANT: I don't know that these images are trustworthy! don't take this as a recommendation!
To access the console of this machine a VNC client can connect to one of your
host's IP addresses on port 5924. I use wlvncc
which is basic and just what
you need to get the job done.
As you can see from the final lines, the configuration includes a NAT driver
that will do DHCP for the VM once it boots. That makes things quite easy to
get things working. Also the hostfwd
rules are quite useful if you want
to access this machine via SSH or HTTP/HTTPS.