Truenas, home assistant os, failed to start QEMU Guest Agent

Hello!

Not entirely sure which subgroup to put this in so hoping that it close enough. Not really sure if it’s Truenas or home assistant causing this.

I’m running Home assistant os (latest) as a VM, (not docker/plugin) in truenas scale (TrueNAS-SCALE-22.02.4). Having trouble with graceful/orderly shutdowns. seams that Truenas just “cuts the power”. If I click (in Truenas) power of or stop it just dies. Reboot seem to properly shutdown but not coming back on.Looking thru startup in haos I see that it “failed to start QEMU Guest Agent”. As i understand it that’s the link between the host and the vm and is needed for this to work.

I also get see ‘systemctl status qemu-guest service’ for details. See image for info on the systemctl status.

Are there anybody who knows how to fix this and get it going. I would like it shutdown properly in case of powerfail. I’m no Linux guru (read: I know nothing att all) so any pointers would be appreciated.

Thank you
/Micke

I have the same issue with truenas scale 22.12, did you solve it?

Hi,

I have the same problem however found a partial workaround at Reddit

Need to attach the special serial device to the VM then do an extra reboot of VM to let the qemu-guest to start normally with the OS:

To list how to refer to the HA OS VM:

virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" list

In my case the VM called as “1_homeassistant”. So I can use the following command to attach the missing serial device and reboot the VM

virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" attach-device 1_homeassistant  --file /mnt/nasV1/VM/Channel.xml --current
virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" reboot 1_homeassistant

The content of the Channel.xml:

<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/f16x86_64.agent'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>

Hope this helps until it became fixed in TrueNAS or even become to a configurable item through its GUI.

-Boti

1 Like

Curious what Version of TrueNAS your on?

I just tried your suggestion on SCALE 22.12.0 but I get an error running the virsh command

error: Failed to attach device from /mnt/nvme/vm/channel.xml
error: internal error: no virtio-serial controllers are available

Hi Troy,

I have Angelfish TrueNAS-SCALE-22.02.4 installed.

-Boti

Strange as it may be… I changed my VM display type from VNC to SPICE and now the virsh command works on SCALE 22.12.0 :man_shrugging:


Updated Post

Digging around in the middleware code I came across this

    if spice_server_available:
        # We always add spicevmc channel device when a spice display device is available to allow users
        # to install guest agents for improved vm experience

So it looks like they are only creating the virtio-serial device if your VM is using a SPICE display type

1 Like

To attach the guest agent early enough in the VM startup, we need to use a startup script. With the help @boti post and the link they shared to reddit, here is the (v2) script I’m using

The VM should NOT be set to autostart, this is key. Instead run this script as Post Init

Click to see post init settings

start-haos.sh

#!/bin/bash

## Set the name of your VM
vm='HomeAssistant'


if [ ${EUID} -ne 0 ]; then
  echo "Please run this script as root or using sudo"
  exit 1
fi

set -euo pipefail

# create a temporary XML file for the QEMU guest agent
guest_agent=$(mktemp -t agent.xml.XXXXX)
cat << "END_AGENT" > "${guest_agent}"
<channel type='unix'>
   <target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
END_AGENT

# get id and use it to start the VM
id=$(/usr/bin/midclt call vm.query | /usr/bin/jq -r '.[] | ( .id|tostring ) + ":" + .name' | /usr/bin/grep "${vm}" | /usr/bin/cut -f1 -d':')
/usr/bin/midclt call vm.start "${id}" &> /dev/null
sleep 1

# get VM name and use it to attach the QEMU guest agent
name=$(/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" list --name | /usr/bin/grep "${vm}")
/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" attach-device "${name}" "${guest_agent}"

# remove the temporary XML file
rm "${guest_agent}"

Note: I removed the v1 script from my previous post

sorry for very late reply, i have not worked this out, but also havent put to much effort in. ill test @boti ideea and and the script @troy wrote. ill get back with the results. thank you

I also submitted a bug report with ix-systems on Jira back in December. I’m happy to say they have already issued a patch and it will be included in the next Scale update 22.12.1

1 Like

means that, that the checkbox with qemu-guest agent can cheked and I don’t need the scripts?

Correct, no need for any scripts. On TrueNAS Scale 22.12.1 and later, no configuration is required. A channel for the guest agent will be added to the VM automatically.

1 Like

nice, today I will switch from proxmox to Truenas Scale, this was the only thing that bothered me

The aeotec zwave sitck work like a charm, but the conbee2 doesen’t? The zigbee2mqtt won’t start, but doesen’t show specific errors in the log.

I think it’s an issue with KVM and the ConBee II - I just posted this a few hours ago