CommentStreams:5711125217364fdf6de9d9a7bf1553fd
This script stopped working with Trixie, so I spent the day rewriting the shutdown portion so that it's usable going forward. Enjoy!
- X-C1 Safe Power-Off (xoff)
- What this does (by design)
- • xoff → clean Linux shutdown
- • All filesystems unmounted
- • Then hardware power is cut via X-C1 GPIO pulse
- • Board stays off (manual power-on required)
- • Reboot remains safe (no power cut)
- Prerequisites
- • Raspberry Pi with X-C1 board attached
- • Raspberry Pi OS (Bullseye / Bookworm / Trixie)
- • GPIO27 wired to X-C1 soft power-cut input (default)
- • Root filesystem on ext4 (standard)
- Step 1 — Install required packages
sudo apt update sudo apt install -y gpiod
- Verify GPIO access:
gpioinfo -c gpiochip0 | grep GPIO27
- You should see: "line 27: "GPIO27" input"
- Step 2 — Create the hardware power-cut script
- This script only triggers the X-C1 power cut. It does not shut down Linux.
sudo tee /usr/local/sbin/xc1-powercut.sh > /dev/null <<'EOF'
- !/usr/bin/env bash
set -euo pipefail
- Pulse GPIO27 HIGH briefly to trigger X-C1 hard power cut
/usr/bin/gpioset -c gpiochip0 -p 100ms 27=1 EOF
sudo chmod 0755 /usr/local/sbin/xc1-powercut.sh
- Step 3 — Create the systemd shutdown unit
- This ensures the GPIO pulse fires after all filesystems are unmounted, but only on poweroff, not reboot.
sudo tee /etc/systemd/system/xc1-cutpower.service > /dev/null <<'EOF' [Unit] Description=X-C1: cut power at end of poweroff (after unmount) DefaultDependencies=no After=umount.target Before=systemd-poweroff.service
[Service] Type=oneshot ExecStart=/bin/sh -c 'sync; sleep 0.2; /usr/local/sbin/xc1-powercut.sh' TimeoutStartSec=5
[Install] WantedBy=poweroff.target EOF
- Activate it:
sudo systemctl daemon-reload sudo systemctl enable xc1-cutpower.service
- Confirm attachment:
systemctl show -p After -p Before xc1-cutpower.service systemctl list-dependencies --plain poweroff.target | grep xc1 systemctl list-dependencies --plain reboot.target | grep xc1 || echo "not attached to reboot"
- Expected: Attached to poweroff.target, Not attached to reboot.target
- Step 4 — Install the xoff command
- We deliberately avoid shell aliases so this works consistently across SSH, scripts, and non-interactive shells
sudo tee /usr/local/bin/xoff > /dev/null <<'EOF'
- !/usr/bin/env bash
exec sudo systemctl poweroff EOF
sudo chmod 0755 /usr/local/bin/xoff
- If you previously used an alias, remove it:
unalias xoff 2>/dev/null || true sed -i '/^alias xoff=/d' ~/.bashrc
- Verify:
type -a xoff
- Expected: xoff is /usr/local/bin/xoff
- Step 5 — Test sequence
- Test poweroff (expected to cut power)
xoff
- Expected behavior: System shuts down cleanly, Power is cut, Board stays off, Manual power-on required
- Test reboot (must NOT cut power)
sudo reboot
- Expected behavior: Normal reboot, Power remains applied, No manual intervention required
- Summary
- You now have:
- • A clean, modern, maintainable X-C1 power-off implementation
- • No deprecated GPIO sysfs
- • No vendor scripts
- • No reboot hazards
- • No disk corruption risk