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.
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
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
#!/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
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.