From 0a6c6aefa7063862e0c31ad069f79203c38d42ca Mon Sep 17 00:00:00 2001 From: Anderson <22428720+buzzer-re@users.noreply.github.com> Date: Mon, 4 May 2026 12:59:02 -0300 Subject: [PATCH] SystemD services & "reboot" using kexec (#1) * Add: systemd services * add --reboot on m2_exec.sh to kexec into the running kernel * rem reboot from m2_exec.sh --- README.md | 23 +++++++++++++ install.sh | 70 ++++++++++++++++++++++++++++++++++++++++ m2_exec.sh | 1 + systemd/ps5boost.service | 13 ++++++++ systemd/ps5fan.service | 13 ++++++++ 5 files changed, 120 insertions(+) create mode 100755 install.sh create mode 100644 systemd/ps5boost.service create mode 100644 systemd/ps5fan.service diff --git a/README.md b/README.md index 04128ee..50e94d6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ # ps5-linux-tools - `ps5_control.c`: Allows turning on/off fan and boost via `/dev/icc` and `/dev/mp1`. +- `systemd/ps5fan.service`: Starts fan control at boot by running `ps5_control --fan on`. +- `systemd/ps5boost.service`: Starts boost mode at boot by running `ps5_control --boost on`. +- `install.sh`: Builds `ps5_control`, installs the systemd services, and enables fan and boost at startup. - `m2_init.c`: Creates a fake MBR header and GPT partition that makes PS5 OS happy. - `m2_install.sh`: Installs a Linux `.img` file by formatting the M.2 as ext4 and copying files over. - `m2_exec.sh`: Performs kexec into Linux on your M.2 SSD. + +## Systemd services + +Install the binary and enable both services: + +```sh +sudo ./install.sh +``` + +The installer places `ps5_control` at `/usr/local/sbin/ps5_control` and installs: + +- `ps5fan.service`, which runs `/usr/local/sbin/ps5_control --fan on` +- `ps5boost.service`, which runs `/usr/local/sbin/ps5_control --boost on` + +Disable either service if you do not want it at startup: + +```sh +sudo systemctl disable --now ps5fan.service +sudo systemctl disable --now ps5boost.service +``` diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..ee4a6a9 --- /dev/null +++ b/install.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +set -euo pipefail + +BINARY_NAME="ps5_control" +INSTALL_BIN="/usr/local/sbin/${BINARY_NAME}" +SYSTEMD_DIR="/etc/systemd/system" + +usage() { + cat <&2 + usage >&2 + exit 1 + ;; + esac + shift +done + +if [[ ${EUID} -ne 0 ]]; then + echo "Run as root: sudo $0" >&2 + exit 1 +fi + +if ! command -v systemctl >/dev/null 2>&1; then + echo "systemctl not found; this installer requires systemd." >&2 + exit 1 +fi + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +cd "${SCRIPT_DIR}" + +echo "Building ${BINARY_NAME}..." +make "${BINARY_NAME}" + +echo "Installing ${INSTALL_BIN}..." +install -Dm755 "${BINARY_NAME}" "${INSTALL_BIN}" + +echo "Installing systemd units..." +install -Dm644 systemd/ps5fan.service "${SYSTEMD_DIR}/ps5fan.service" +install -Dm644 systemd/ps5boost.service "${SYSTEMD_DIR}/ps5boost.service" + +systemctl daemon-reload + +echo "Enabling and starting ps5fan.service and ps5boost.service..." +systemctl enable --now ps5fan.service ps5boost.service + +echo "Done." +echo "Disable services you do not want:" +echo " sudo systemctl disable --now ps5fan.service" +echo " sudo systemctl disable --now ps5boost.service" diff --git a/m2_exec.sh b/m2_exec.sh index 701fc03..10052cb 100755 --- a/m2_exec.sh +++ b/m2_exec.sh @@ -7,6 +7,7 @@ fi NVME_PART="/dev/nvme0n1p1" MNT="/tmp/kexec_mnt" + ROOT_LABEL=$(blkid -s LABEL -o value "$NVME_PART") if [ -z "$ROOT_LABEL" ]; then diff --git a/systemd/ps5boost.service b/systemd/ps5boost.service new file mode 100644 index 0000000..9b69129 --- /dev/null +++ b/systemd/ps5boost.service @@ -0,0 +1,13 @@ +[Unit] +Description=Enable PS5 boost mode +After=dev-mp1.device +ConditionPathExists=/dev/mp1 + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/ps5_control --boost on +ExecStop=/usr/local/sbin/ps5_control --boost off +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/systemd/ps5fan.service b/systemd/ps5fan.service new file mode 100644 index 0000000..a191d68 --- /dev/null +++ b/systemd/ps5fan.service @@ -0,0 +1,13 @@ +[Unit] +Description=Enable PS5 fan control +After=dev-icc.device +ConditionPathExists=/dev/icc + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/ps5_control --fan on +ExecStop=/usr/local/sbin/ps5_control --fan off +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target