Repository navigation
Lock instead of suspending on the IdeaPad Slim 3 15AMN8 #13115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from 4 commits
1fdf5c4
14dd521
8825b92
b4d3646
e5e0dfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # The IdeaPad Slim 3 15AMN8 (Lenovo 82XQ) only offers s2idle, and its Micron | ||
| # NVMe firmware rejects all I/O with Access Denied/DNR on resume, taking the | ||
| # root filesystem read-only mid-session. The kernel already works around the | ||
| # platform's suspend bug ("Using s2idle quirk to avoid IdeaPad Slim 3 15AMN8 | ||
| # platform firmware bug") but the drive still dies, so suspend can never | ||
| # succeed on this model. | ||
| # | ||
| # Locking on lid close is the strictly better fallback: the session locks and | ||
| # the panel powers down -- what a user expects from closing a laptop -- while | ||
| # keeping the machine alive instead of inviting a read-only root. | ||
|
|
||
| dmi="${OMARCHY_DMI_PATH:-/sys/class/dmi/id}" | ||
|
|
||
| conf_dir="${OMARCHY_LOGIND_CONF_DIR:-/etc/systemd/logind.conf.d}" | ||
|
|
||
| if [[ -r $dmi/sys_vendor && -r $dmi/product_name ]] && | ||
| [[ $(<"$dmi/sys_vendor") == "LENOVO" && $(<"$dmi/product_name") == "82XQ" ]]; then | ||
| install -d -m 0755 "$conf_dir" | ||
| cat >"$conf_dir/50-ideapad-suspend.conf" <<'EOF' | ||
| # The Micron NVMe in this model rejects all I/O after s2idle resume, so | ||
| # suspend can never complete. Lock instead of suspending: the session locks | ||
| # and the panel powers down, and the filesystem stays alive. | ||
| [Login] | ||
| HandleLidSwitch=lock | ||
| HandleSuspendKey=lock | ||
| HandleSuspendKeyLongPress=lock | ||
| EOF | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| echo "Lock instead of suspending on the IdeaPad Slim 3 15AMN8" | ||
|
|
||
| # On the Lenovo 82XQ the Micron NVMe rejects all I/O after s2idle resume and | ||
| # the root filesystem goes read-only mid-session, so suspend can never | ||
| # succeed on this model. The logind drop-in the installer now writes was | ||
| # missing on existing installs; write it and reload logind. | ||
|
|
||
| dmi="${OMARCHY_DMI_PATH:-/sys/class/dmi/id}" | ||
| conf_dir="${OMARCHY_LOGIND_CONF_DIR:-/etc/systemd/logind.conf.d}" | ||
| dropin="$conf_dir/50-ideapad-suspend.conf" | ||
|
|
||
| [[ -r $dmi/sys_vendor && -r $dmi/product_name ]] || exit 0 | ||
| [[ $(<"$dmi/sys_vendor") == "LENOVO" && $(<"$dmi/product_name") == "82XQ" ]] || exit 0 | ||
| [[ -f $dropin ]] && exit 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration treats any existing Check the required contents and finish the reload or reboot notice on retries. Write through a temporary file followed by a rename so a failed write cannot leave a partial repair. Knowledge Base Used: Migration framework |
||
|
|
||
| sudo install -d -m 0755 "$conf_dir" | ||
| sudo tee "$dropin" >/dev/null <<'CONF' | ||
| # The Micron NVMe in this model rejects all I/O after s2idle resume, so | ||
| # suspend can never complete. Lock instead of suspending: the session locks | ||
| # and the panel powers down, and the filesystem stays alive. | ||
| [Login] | ||
| HandleLidSwitch=lock | ||
| HandleSuspendKey=lock | ||
| HandleSuspendKeyLongPress=lock | ||
| CONF | ||
|
|
||
| # Reload rather than restart: restarting systemd-logind tears down the session. | ||
| # If the reload fails, the drop-in only takes effect after a reboot. | ||
| sudo systemctl reload systemd-logind >/dev/null 2>&1 || omarchy-state set reboot-required | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| tmp_dir=$(mktemp -d) | ||
| trap 'rm -rf "$tmp_dir"' EXIT | ||
|
|
||
| hardware_script="$ROOT/install/hardware/fix-ideapad-suspend.sh" | ||
| migration="$ROOT/migrations/1790227635.sh" | ||
| calls="$tmp_dir/calls" | ||
|
|
||
| # Stubs log every privileged call so nothing touches the host's logind and | ||
| # the assertions can tell "did not run" apart from "ran and failed". | ||
| mkdir -p "$tmp_dir/bin" | ||
| cat >"$tmp_dir/bin/sudo" <<'STUB' | ||
| #!/bin/bash | ||
| printf 'sudo %s\n' "$*" >>"$CALLS_FILE" | ||
| exec "$@" | ||
| STUB | ||
| cat >"$tmp_dir/bin/systemctl" <<'STUB' | ||
| #!/bin/bash | ||
| printf 'systemctl %s\n' "$*" >>"$CALLS_FILE" | ||
| exit "${SYSTEMCTL_STATUS:-0}" | ||
| STUB | ||
| cat >"$tmp_dir/bin/omarchy-state" <<'STUB' | ||
| #!/bin/bash | ||
| printf 'omarchy-state %s\n' "$*" >>"$CALLS_FILE" | ||
| STUB | ||
| chmod +x "$tmp_dir/bin/sudo" "$tmp_dir/bin/systemctl" "$tmp_dir/bin/omarchy-state" | ||
| : >"$calls" | ||
|
|
||
| # The affected model: Lenovo 82XQ (IdeaPad Slim 3 15AMN8). | ||
| mkdir -p "$tmp_dir/dmi-match" "$tmp_dir/conf-match" | ||
| printf 'LENOVO\n' >"$tmp_dir/dmi-match/sys_vendor" | ||
| printf '82XQ\n' >"$tmp_dir/dmi-match/product_name" | ||
|
|
||
| OMARCHY_DMI_PATH="$tmp_dir/dmi-match" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-match" \ | ||
| bash "$hardware_script" | ||
|
|
||
| dropin="$tmp_dir/conf-match/50-ideapad-suspend.conf" | ||
| [[ -f $dropin ]] || fail "hardware script writes the logind drop-in on an 82XQ" | ||
| grep -Fx '[Login]' "$dropin" >/dev/null || | ||
| fail "drop-in is a logind section" | ||
| grep -Fx 'HandleLidSwitch=lock' "$dropin" >/dev/null || | ||
| fail "drop-in locks instead of suspending on lid close" | ||
| grep -Fx 'HandleSuspendKey=lock' "$dropin" >/dev/null || | ||
| fail "drop-in locks instead of suspending on the suspend key" | ||
| grep -Fx 'HandleSuspendKeyLongPress=lock' "$dropin" >/dev/null || | ||
| fail "drop-in overrides the suspend key long-press default of hibernate" | ||
| if grep -F 'HandleLidSwitchDocked' "$dropin" >/dev/null; then | ||
| fail "docked lid close must stay ignored so clamshell displays are not locked" "$(cat "$dropin")" | ||
| fi | ||
| pass "hardware script locks instead of suspending on the IdeaPad Slim 3" | ||
|
|
||
| # Any other machine must be left alone. | ||
| mkdir -p "$tmp_dir/dmi-other" "$tmp_dir/conf-other" | ||
| printf 'LENOVO\n' >"$tmp_dir/dmi-other/sys_vendor" | ||
| printf '21H8\n' >"$tmp_dir/dmi-other/product_name" | ||
|
|
||
| OMARCHY_DMI_PATH="$tmp_dir/dmi-other" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-other" \ | ||
| bash "$hardware_script" | ||
|
|
||
| [[ ! -e $tmp_dir/conf-other/50-ideapad-suspend.conf ]] || | ||
| fail "hardware script must not touch other Lenovo models" | ||
| pass "hardware script leaves other models alone" | ||
|
|
||
| # The installer registers the quirk. | ||
| grep -F 'fix-ideapad-suspend.sh' "$ROOT/install/hardware/all.sh" >/dev/null || | ||
| fail "install/hardware/all.sh runs the IdeaPad suspend fix" | ||
| pass "install registers the IdeaPad suspend fix" | ||
|
|
||
| # The migration applies the same drop-in on existing installs, once, and | ||
| # reloads logind so it takes effect without tearing down the session. | ||
| mkdir -p "$tmp_dir/conf-migration" | ||
|
|
||
| OMARCHY_DMI_PATH="$tmp_dir/dmi-match" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-migration" \ | ||
| CALLS_FILE="$calls" PATH="$tmp_dir/bin:$PATH" bash "$migration" >/dev/null | ||
|
|
||
| migration_dropin="$tmp_dir/conf-migration/50-ideapad-suspend.conf" | ||
| grep -Fx 'HandleLidSwitch=lock' "$migration_dropin" >/dev/null || | ||
| fail "migration writes the lock-on-lid drop-in" | ||
| grep -Fx 'systemctl reload systemd-logind' "$calls" >/dev/null || | ||
| fail "migration reloads logind after writing the drop-in" "$(cat "$calls")" | ||
| if grep -F 'omarchy-state' "$calls" >/dev/null; then | ||
| fail "migration asks for no reboot when the reload succeeds" "$(cat "$calls")" | ||
| fi | ||
| pass "migration writes the lock-on-lid drop-in and reloads logind" | ||
|
|
||
| # A second run must not escalate at all. | ||
| : >"$calls" | ||
| OMARCHY_DMI_PATH="$tmp_dir/dmi-match" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-migration" \ | ||
| CALLS_FILE="$calls" PATH="$tmp_dir/bin:$PATH" bash "$migration" >/dev/null || | ||
| fail "migration is idempotent once the drop-in exists" | ||
| [[ ! -s $calls ]] || | ||
| fail "migration runs no privileged commands once the drop-in exists" "$(cat "$calls")" | ||
| pass "migration is idempotent once the drop-in exists" | ||
|
|
||
| # And it must not run at all on other hardware. | ||
| rm -f "$tmp_dir/conf-migration/50-ideapad-suspend.conf" | ||
| : >"$calls" | ||
| OMARCHY_DMI_PATH="$tmp_dir/dmi-other" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-migration" \ | ||
| CALLS_FILE="$calls" PATH="$tmp_dir/bin:$PATH" bash "$migration" >/dev/null || | ||
| fail "migration exits cleanly on unmatched hardware" | ||
| [[ ! -s $calls ]] || | ||
| fail "migration runs no privileged commands on unmatched hardware" "$(cat "$calls")" | ||
| [[ ! -e $tmp_dir/conf-migration/50-ideapad-suspend.conf ]] || | ||
| fail "migration writes nothing on unmatched hardware" | ||
| pass "migration no-ops on unmatched hardware" | ||
|
|
||
| # A refused sudo must leave the migration pending, so run it the way | ||
| # omarchy-migrate does and expect it to stop. | ||
| mkdir -p "$tmp_dir/bin-denied" | ||
| cat >"$tmp_dir/bin-denied/sudo" <<'STUB' | ||
| #!/bin/bash | ||
| printf 'sudo %s\n' "$*" >>"$CALLS_FILE" | ||
| exit 1 | ||
| STUB | ||
| chmod +x "$tmp_dir/bin-denied/sudo" | ||
| : >"$calls" | ||
| if OMARCHY_DMI_PATH="$tmp_dir/dmi-match" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-migration" \ | ||
| CALLS_FILE="$calls" PATH="$tmp_dir/bin-denied:$tmp_dir/bin:$PATH" bash -euo pipefail "$migration" >/dev/null; then | ||
| fail "migration fails when sudo is refused, so it stays pending" | ||
| fi | ||
| grep -F 'sudo install -d' "$calls" >/dev/null || | ||
| fail "migration reached sudo before stopping" "$(cat "$calls")" | ||
| [[ ! -e $tmp_dir/conf-migration/50-ideapad-suspend.conf ]] || | ||
| fail "migration writes nothing when sudo is refused" | ||
| pass "migration stays pending when sudo is refused" | ||
|
|
||
| # A failed reload leaves the drop-in inert until reboot, so it must say so. | ||
| : >"$calls" | ||
| OMARCHY_DMI_PATH="$tmp_dir/dmi-match" OMARCHY_LOGIND_CONF_DIR="$tmp_dir/conf-migration" SYSTEMCTL_STATUS=1 \ | ||
| CALLS_FILE="$calls" PATH="$tmp_dir/bin:$PATH" bash -euo pipefail "$migration" >/dev/null || | ||
| fail "migration finishes when only the reload fails" | ||
| grep -Fx 'omarchy-state set reboot-required' "$calls" >/dev/null || | ||
| fail "migration asks for a reboot when the logind reload fails" "$(cat "$calls")" | ||
| pass "migration asks for a reboot when the logind reload fails" |
Uh oh!
There was an error while loading. Please reload this page.