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!

      1. X-C1 Safe Power-Off (xoff)
  1. What this does (by design)
  2. • xoff → clean Linux shutdown
  3. • All filesystems unmounted
  4. • Then hardware power is cut via X-C1 GPIO pulse
  5. • Board stays off (manual power-on required)
  6. • Reboot remains safe (no power cut)
  1. Prerequisites
  2. • Raspberry Pi with X-C1 board attached
  3. • Raspberry Pi OS (Bullseye / Bookworm / Trixie)
  4. • GPIO27 wired to X-C1 soft power-cut input (default)
  5. • Root filesystem on ext4 (standard)
    1. Step 1 — Install required packages

sudo apt update sudo apt install -y gpiod

  1. Verify GPIO access:

gpioinfo -c gpiochip0 | grep GPIO27

  1. You should see: "line 27: "GPIO27" input"
    1. Step 2 — Create the hardware power-cut script
  1. 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'

  1. !/usr/bin/env bash

set -euo pipefail

  1. 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

    1. Step 3 — Create the systemd shutdown unit
  1. 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

  1. Activate it:

sudo systemctl daemon-reload sudo systemctl enable xc1-cutpower.service

  1. 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"

  1. Expected: Attached to poweroff.target, Not attached to reboot.target
    1. Step 4 — Install the xoff command
  1. 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'

  1. !/usr/bin/env bash

exec sudo systemctl poweroff EOF

sudo chmod 0755 /usr/local/bin/xoff

  1. If you previously used an alias, remove it:

unalias xoff 2>/dev/null || true sed -i '/^alias xoff=/d' ~/.bashrc

  1. Verify:

type -a xoff

  1. Expected: xoff is /usr/local/bin/xoff
    1. Step 5 — Test sequence
  1. Test poweroff (expected to cut power)

xoff

  1. Expected behavior: System shuts down cleanly, Power is cut, Board stays off, Manual power-on required
  1. Test reboot (must NOT cut power)

sudo reboot

  1. Expected behavior: Normal reboot, Power remains applied, No manual intervention required
      1. Summary
  1. You now have:
  2. • A clean, modern, maintainable X-C1 power-off implementation
  3. • No deprecated GPIO sysfs
  4. • No vendor scripts
  5. • No reboot hazards
  6. • No disk corruption risk