[This tutorial is still working in progress]
Start the VM on hardware event
In my case, I don't use the SD card in daily workflow and it's nice to be used as a "switch". You can always use a handy USB device as an event trigger.
Create a service called `start-on-remove-sd`:
sudo nano /etc/systemd/system/start-on-remove-sd.service
Replace the contents of the file with the following:
[Unit] Description=Start VM on SD card removal After=network.target [Service] ExecStart=/usr/bin/bash -c "journalctl -fn0 | grep --line-buffered 'mmc0: card 0007 removed' | while read -r line; do qm start 106; done" [Install] WantedBy=default.target
Save the file and exit the text editor. Reload the systemd daemon to apply the changes:
sudo systemctl daemon-reload
Enable and start the service using the following commands:
sudo systemctl enable start-on-remove-sd.service sudo systemctl start start-on-remove-sd.service