ACPI shutdown does nothing

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)
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?

It’s essentially a RPi, which doesn’t even have an on/off switch - and no acpi shutdown. I just use shutdown -h now on my VM.

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!

Description=Dietpi VM service virtualbox.service

ExecStart=/usr/lib/virtualbox/VBoxHeadless -s DietPi2
ExecStop=/usr/lib/virtualbox/VBoxManage controlvm DietPi2 poweroff


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.

I solved it. Make sure acpid is installed, then create /etc/acpi/events/power_button with the following:

event=button/power PBTN 00000080 00000000

Your event may differ, but you can look it up by running acpi_listen and then sending the ACPI shutdown command.

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.