This gist contains two scripts to simple quickly build UEFI-based or BIOS-based Debian/Ubuntu VMs stored as qcow2
-files – mainly intended for using those with QEMU/KVM.
This is done by relying on the mighty debootstrap
and qemu-utils
, especially qemu-nbd
.
The scripts are basically updated version of K. Trzcinski’s work.
Ensure, that you have the following packages installed:
apt install -y qemu-utils \
debootstrap \
grub-pc-bin \
ovmf # for UEFI-booting
It is strongly recommended to rely on apt-cacher-ng
to build up the build process:
apt install apt-cacher-ng
# Eventually, check that apt-cacher-ng is running
ss -tln | grep 3142
VM_NAME=debian-test
VM_FILE=${VM_NAME}.qcow2
RELEASE=bookworm
USER=user
PW=pass123
# Create a qcow2
qemu-img create -f qcow2 $VM_FILE 4G
# Build UEFI-based VM
./build-uefi-based-debian-vm.sh $VM_FILE $VM_NAME $RELEASE $USER $PW
# Run a UEFI-based via qemu
qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -net nic -net user -m 2G -smp cores=1,cpus=1 -drive file=$VM_FILE
Alternatively, build and run a BIOS-based VM like so:
# Build BIOS-based VM
./build-bios-based-debian-vm.sh $VM_FILE $VM_NAME $RELEASE $USER $PW
# Run a BIOS-based via qemu
qemu-system-x86_64 -net nic -net user -m 2G -smp cores=1,cpus=1 -drive file=$VM_FILE