Smokes your problems, coughs fresh air.

Tag: qemu

Booting Debian Trixie (13) on Qemu

There are many sites out there that describe how to emulate a Raspberry Pi with Raspberry Pi OS on it, so I won’t give those details, but with the new Debian Trixie (13) based Raspberry Pi OS, I ran into trouble booting. It kept hanging or rebooting at:

[    8.849465] systemd[1]: Detected architecture arm64.
[    8.854622] systemd[1]: Detected first boot.
 
Welcome to Raspbian GNU/Linux 13 (trixie)!
 
[    8.995587] systemd[1]: Hostname set to <raspberrypi>.
[    9.040059] systemd[1]: Initializing machine ID from random generator.

After checking on a real Pi what the next steps were in the boot process, I found the relevant fix was disabling the watchdog, which seems could only be done reliably by editing ‘/etc/systemd/system.conf’ and set:

WatchdogDevice=/dev/watchdog666

Also note that the ‘console=ttyAMA0,115200’ you see in many of the articles, probably needs to be ‘console=ttyAMA1,115200’. It did for me.

And for reference, my complete qemu command:

qemu-system-aarch64 \
  -no-reboot \
  -machine raspi3b \
  -cpu cortex-a72 \
  -nographic \
  -dtb bcm2710-rpi-3-b-plus.dtb \
  -m 1G \
  -smp 4 \
  -kernel kernel8.img \
  -drive file=2025-10-09-raspios-trixie-armhf-flashmq.img,if=sd,format=raw \
  -append "rw earlyprintk loglevel=8 console=ttyAMA1,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" \
  -device usb-net,netdev=net0 \
  -netdev user,id=net0,hostfwd=tcp::2222-:22

Making sure virtual machine guests shut down properly on a Debian host

I just installed libvirt and installed a vritual machine with virt-install. I also used virsh to configure it to autostart on machine start. This way, it integrates quite nicely with the host operating system.

However, I found out that libvirt provides no way to properly shut the machines down when the host goes down. It is completely beyond me that they didn’t implement this. When you shut down libvirtd, the guests just die…

Googling yielded almost nothing, except a bug report from 17 Mar 2009 with a request for this. The report still wasn’t handled, but the guy said that he wrote a crude script to do it. I mailed him to ask for it, and here it is:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          kvm_domains
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     
# Default-Stop:      0 6
# Short-Description: Shutdown kvm domains
# Description:       Shutdown kvm domains on reboot/poweroff.
#                    Forcefully kill instances that still run after a
#                    given timeout.
### END INIT INFO
 
# Author: Michael Biebl <biebl@teco.edu>
#
 
# Do NOT "set -e"
 
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="KVM domains"
VIRSH=/usr/bin/virsh
SCRIPTNAME=/etc/init.d/kvm_domains
TIMEOUT=60
 
# Exit if the package is not installed
[ -x "$VIRSH" ] || 0
 
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
 
#
# Function that stops the daemon/service
#
do_stop()
{
	domains=$($VIRSH -q list | awk '/running/ {print $2}')
 [ -z "$domains" ] ;
		log_progress_msg "none"
	 0
 
 d $domains ;
		$VIRSH -q shutdown $d > /dev/null
		log_progress_msg $d
 
 
	i=0
 [ $i -lt $TIMEOUT ] ;
	 $VIRSH -q list | grep -q running ;
			i=$(($i+1))
			log_progress_msg "."
			sleep 1
	
		 0
	
 
	# forcefully kill the remaining kvm instances
	killall -9 kvm
 1 
}
 
 "$1"
  start)
	;;
  stop)
	log_begin_msg "Stopping $DESC:"
	do_stop
 "$?"
		0) log_end_msg 0 ;;
		1) log_end_msg 1 ;;
 
	;;
  restart|force-reload)
	;;
  *)
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
 "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 3
	;;
 
:

It depends on text output by virsh, so it’s not the most robust, but it works.

Run this to put in it in the proper runlevels (the 10 on my system makes sure it executes before kvm and libvirt):

update-rc.d kvm_domains stop 10 0 6 .

© 2025 BigSmoke

Theme by Anders NorenUp ↑