I have DietPi installed in qemu / kvm, and everything seems to work except ACPI events. I cannot initiate a clean shutdown from the VM host, the only way to do it is to SSH in and issue a shutdown command. I have tried installed qemu guest additions and setting that up as a workaround, but it didn’t help.
Installing and running evtest on DietPi shows “Power Button” as /dev/input/event4". Monitoring this input and issuing a shutdown command from the VM host shows that DietPi is receiving it:
root@DietPi:~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: AT Translated Set 2 keyboard
/dev/input/event1: VirtualPS/2 VMware VMMouse
/dev/input/event2: VirtualPS/2 VMware VMMouse
/dev/input/event3: QEMU QEMU USB Tablet
/dev/input/event4: Power Button
/dev/input/event5: PC Speaker
Select the device event number [0-5]: 4
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x1 version 0x0
Input device name: "Power Button"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 116 (KEY_POWER)
Properties:
Testing ... (interrupt to exit)
Event: time 1563058630.608071, type 1 (EV_KEY), code 116 (KEY_POWER), value 1
Event: time 1563058630.608071, -------------- SYN_REPORT ------------
Event: time 1563058630.608073, type 1 (EV_KEY), code 116 (KEY_POWER), value 0
Event: time 1563058630.608073, -------------- SYN_REPORT ------------
However it does not initiate a shutdown. Is there a way to fix this so that DietPi properly shuts down when I receives an ACPI shutdown command?
That doesn’t help though. As it is now, when the host shuts down or restarts, the dietpi VM makes the host wait 2 minutes before it times out force destroys the VM to continue shutting down. That’s the issue I’m ultimately trying to solve.
Is there a way to install ACPI? Or perhaps setup a udev rule to shutdown when the “power button” is pressed? I’m just not sure how to setup the appropriate udev rule to match the button press
I created a vm.service file in my systemd to handle this (improperly) to keep me from waiting. I probably need to look at it a little harder cause it’s “yanking the plug” however I dont have to wait. It’s not a huge deal to me because if it corrupts I usually have a recent backup… That’s what VMs are good at anyway!
[Unit]
Description=Dietpi VM service
After=network.target virtualbox.service
[Service]
User=xxx
ExecStart=/usr/lib/virtualbox/VBoxHeadless -s DietPi2
ExecStop=/usr/lib/virtualbox/VBoxManage controlvm DietPi2 poweroff
[Install]
WantedBy=multi-user.target
Then you can just enable the service file and it will shut it down when the machine shuts down and boot it when it boots without having to worry about it.
Thanks that’s fantastic! Works for me and better than my solution. FYI I’m going to keep my service file and change it to send a acpi signal to properly shut my VM down on restarts now.
This command creates the file /etc/acpi/events/power_button and puts the two lines into it, there is no need to run it multiple times.
ACPID is of course a requirement to get this working, like said here.
Can you show us cat /etc/acpi/events/power_button?!
Maybe a reboot is needed for the changes to take effect, idk.