Udev is one of those classic open source tools that is immensely powerful and gracefully well designed, with all sorts of emergent power...
...that ends up being an obscure bit of graybeard prestidigitation purely because of it's awful syntax.
No really, there's a very clean mapping between the state in sysfs and the resulting uevents produced. You just can't tell because of the way it looks.
So that’s an option rather than power. Devise where you’d place a YubiKey on an extension cord, with its removal triggering logout and shutdown.
I believe Windows has something similar - also an event.
Systemd, D-Bus, and udev can be used separately or together to make this easier to listen in userland, it will just be dependent on your distribution or setup.
The kernel essentially flags the power source through udev, and the rule triggers the script. That can be done programmatically instead of a script as well. libudev is there for that: https://www.freedesktop.org/software/systemd/man/latest/libu...
https://wiki.archlinux.org/title/Udev (userland /dev is what udev does)
As it is, all you need is a screwdriver to take out the disc, put it in another box, format it and put it back. Then you have a machine good to sell on eBay.
NFC could be another way of protecting a PC so you need your phone to unlock it.
PCs used to have a low grade lock on them originally, that locked the power button and disks behind a flimsy piece of plastic. This feature was soon dropped.
Clearly the market does not demand theft proofing. Otherwise we would have a little bit more than noble efforts like this udev script.
It even has parts pairing, so the e.g. the screen has some features disabled if you swap it.
But it does feel like the security regime is pretty lax. I feel like some BLE tracker system is a natural fit for laptops. I'd love a motion sensor alarm built in.
Framework laptop's embedded controller is open source, run Zephyr. I don't think there's a ton of peripherals it has access too, but I love the idea that one could potentially make their own firmware that has their own security designs built in.
echo 1 > /proc/sys/kernel/sysrq
echo o > /proc/sysrq-trigger
https://docs.redhat.com/en/documentation/red_hat_enterprise_... echo 1 > /proc/sys/kernel/sysrq
echo u > /proc/sysrq-trigger
dmesg --follow \
| grep -qm1 'Emergency Remount complete'
echo o > /proc/sysrq-trigger
...least putting a bit too much trust in ext4/btrfs/zfs journalling.Not nearly as elegant, but I keep running into problems where I want to run some command when X happens. I've been trying to lean into systemd, creating a service for whatever it is I want run (perhaps just a oneshot if it's a a one off command). Then have a separate program that detects for the desired condition (polling?) and runs systemd-notify to signal that it's healthy. Then you can just BindTo=, so that the desired command runs whenever the condition-detector thing goes green.
Works pretty well so far.
Apreche•23h ago
What it’s actually about how to automatically automatically trigger a command on a Linux computer (almost certainly a laptop) in the event that it switches from AC power to battery power.
The example given is your laptop is plugged it at a café. Someone steals it, which involves unplugging it from the wall. At the moment it is unplugged it automatically shuts down, locks itself, etc.
I wonder if the same approach will also work for a computer connected to a UPS. Probably not!
nisegami•23h ago
netsharc•23h ago
For big servers, the UPS's batteries might only give minutes of power, so they'd listen for such a signal to do an orderly shutdown.
LoganDark•23h ago
1718627440•23h ago
Rooster61•22h ago
This is still a logical use case, but it's not the mental image that immediately got conjured up after reading the title for me.
NooneAtAll3•22h ago
Rooster61•21h ago
wkjagt•21h ago
Rooster61•21h ago
tenthirtyam•19h ago
yndoendo•9h ago
wildzzz•20h ago
As for a UPS, I have a Synology NAS that can monitor an APC UPS over its serial USB port. When the UPS loses power or is told to gracefully shutdown, the NAS also gracefully shuts down.
piperswe•20h ago
Considering that my UPS appears as a battery in KDE when I plug the USB cable in, I wouldn't be surprised if it's treated the same as a laptop battery across most of the stack
telotortium•20h ago
nemomarx•19h ago
mrheosuper•10h ago
You could achieve same thing if you unplug your battery.