「Pm-utils」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(アーカイブに移動)
タグ: 新規リダイレクト
 
(4人の利用者による、間の12版が非表示)
1行目: 1行目:
  +
#redirect [[ArchWiki:アーカイブ]]
{{DISPLAYTITLE:pm-utils}}
 
[[Category:電源管理]]
+
[[Category:アーカイブ]]
[[en:Pm-utils]]
 
[[it:Pm-utils]]
 
[[ru:Pm-utils]]
 
[[zh-CN:Pm-utils]]
 
{{Related articles start}}
 
{{Related|Uswsusp}}
 
{{Related|TuxOnIce}}
 
{{Related articles end}}
 
{{Warning|1=Pm-utils でハイバネートをして systemd をアップデートするとファイルが破壊されるという報告が存在します: https://bbs.archlinux.org/viewtopic.php?pid=1423442 。}}
 
'''pm-utils''' はサスペンドと電源状態を設定するフレームワークです。{{ic|powersave}} などのスクリプトなどを置き換えるために作られました。
 
 
pm-utils はカーネルのサスペンドと復帰を様々なハックで包み込むシェルスクリプトのコレクションです。サスペンドに対応していないドライバーやサブシステムによるバグを回避するためにハックが必要になります。カスタムフックをディレクトリに配置することで簡単に拡張することができ、システムの管理者がフックを作成するだけでなく、パッケージによってフックがインストールされることもあります。システムのサスペンドや電源状態の変化に特別注意する必要があるパッケージにフックが含まれています。
 
 
あまり知られていない機能として [[Laptop Mode Tools]] による切り替えを模倣します。
 
 
[[CPU 周波数スケーリング|cpupower]] パッケージと組み合わせて使うことで、ノートパソコン (デスクトップ) のユーザーは完全な電源管理スイートとして利用できます。
 
 
== インストール ==
 
 
[[公式リポジトリ]]の {{Pkg|pm-utils}} パッケージを[[pacman|インストール]]してください。
 
 
{{Note|
 
* 復帰時にビデオに問題が発生する場合は、[[公式リポジトリ]]から {{Pkg|vbetool}} もインストールする必要があります。
 
* 初めてインストールするときは、{{Pkg|acpi}} がインストールされていることを確認してください。
 
}}
 
 
root で {{ic|pm-suspend}}, {{ic|pm-suspend-hybrid}}, {{ic|pm-hibernate}} を実行すると手動でサスペンドが行われます。サスペンドスクリプトは {{ic|/var/log/pm-suspend.log}} にログを書き出します。
 
 
=== 別のサスペンドバックエンドをインストール (任意) ===
 
 
Arch Linux のパッケージでは次のバックエンドに対応するようになっています: {{ic|kernel}}, {{ic|tuxonice}}, {{ic|uswsusp}}。以下のコマンドで確認できます:
 
pacman -Ql pm-utils | grep module.d
 
 
サスペンドバックエンドは {{ic|/etc/pm/config.d}} の {{ic|SLEEP_MODULE}} 設定変数で指定することができ、デフォルトでは {{ic|kernel}} バックエンドが使われます。別のサスペンドバックエンドを使うには、それぞれ必要なパッケージをインストールしてください。どちらも [[Arch User Repository]] からインストールできます:
 
* uswsusp - {{AUR|uswsusp-git}}
 
* tuxonice - {{AUR|linux-ice}} / [[linux-pf]]
 
 
さらに、{{Pkg|pm-utils}} には独自のビデオ互換データベースが付属しており、{{ic|/usr/lib/pm-utils/video-quirks/}} にインストールされます。
 
 
== 基本設定 ==
 
 
=== スタンバイ/RAM にサスペンド ===
 
 
理想的な状態は、root で {{ic|pm-suspend}} を実行することでメモリへのサスペンドが開始され、全ての動作状態が RAM に保存されて、消費電力を抑えるために RAM 以外の部品は全部シャットダウンされることです。また、電源ボタンを押すことでこの状態から復帰できなければなりません。
 
 
{{Note|ネットワークドライバーは SUSPENDED_MODULES に必ず記述することを推奨します。ほとんどのワイヤレスドライバーはスタンバイ後に問題を起こすことが知られています。Intel の iwlwifi, Atheros の ath5k, Realtek の r8* ドライバーなどが復帰後に問題を起こすという報告がフォーラムにあります。iwlwifi は復帰後にリロードしないと接続速度が 1Mbps まで落ちます。}}
 
 
場合によっては、{{ic|pm-suspend}} を実行するとフリーズするなどの問題が発生することがあります。特定のモジュールが正しく動作しないのが原因です。問題を発生させるモジュールがわかっている場合、{{ic|/etc/pm/config.d/modules}} の {{ic|SUSPEND_MODULES}} に以下のようにモジュールを追加します:
 
SUSPEND_MODULES="uhci_hd button ehci_hd iwlwifi"
 
設定に追加されたモジュールはサスペンドが行われる前にアンロードされ、復帰後にリロードされます。
 
 
ノートパソコンのフタを閉じた時などの電源イベントによって自動的に {{ic|pm-suspend}} を実行するように設定したい場合は、[[Acpid]] を参照してください。
 
 
=== ハイバネーション (suspend2disk) ===
 
 
[[サスペンドとハイバネート#ハイバネーション]]の指示に従ってハイバネーションを設定してください。
 
 
もしくは、{{ic|kernel}} バックエンドを使わない場合、[[Uswsusp#設定]] や [[TuxOnIce#ブートローダーの設定]] を見て下さい。
 
 
=== 通常ユーザーでサスペンド/ハイバネート ===
 
 
root パスワードを入力することなくサスペンドする方法は3つあります: [[Udev]] を使用する方法、UPower を使用する方法、[[sudo|visudo]] でユーザーに適当な権限を与える方法です。
 
 
==== ユーザーに権限を与える方法 ====
 
 
{{Pkg|pm-utils}} スクリプトは root で実行する必要があるため、sudo を使うことで root パスワードを入力しないで通常ユーザーでスクリプトを使えるようにすることができます。そうするには、root で {{ic|visudo}} を使って {{ic|/etc/sudoers}} ファイルを編集してください。詳しくは、[[sudo]] を参照。
 
 
以下の行を追加してください。{{ic|''username''}} はあなたのユーザー名に置き換えて、保存してから {{ic|visudo}} を終了します:
 
''username'' ALL = NOPASSWD: /usr/sbin/pm-hibernate
 
''username'' ALL = NOPASSWD: /usr/sbin/pm-suspend
 
 
もしくは、グループを使うこともできます。以下の行を使って下さい。{{ic|''group''}} は置き換えて下さい:
 
%''group'' ALL = NOPASSWD: /usr/sbin/pm-hibernate
 
%''group'' ALL = NOPASSWD: /usr/sbin/pm-suspend
 
 
{{Note|These must come after any user privilege specifications, e.g., {{ic|1=username ALL=(ALL) ALL}}, or they will not work.}}
 
 
上記の設定によって、パスワードを入力しなくても以下のコマンドを実行することでスクリプトが実行できます:
 
$ sudo pm-hibernate
 
 
もしくは:
 
 
$ sudo pm-suspend
 
 
また、ユーザーを {{ic|power}} [[グループ]]に追加して、アプレットなどを使用してサスペンドできるようにします。グループに追加していないと、[[GNOME]] のシャットダウンアプレットなどでサスペンドしようとしたときに、耳障りなビープ音が三回鳴って画面がロックされます。ユーザーをグループに追加するには:
 
# gpasswd -a ''username'' power
 
 
これで[[デスクトップ環境]]の電源管理ツールを使って、ノートパソコンのフタが閉じられたとき、あるいはバッテリーの残量が少なくなったときに、自動的にサスペンドやハイバネートをすることができるようになります。
 
 
=== 省電力機能 ===
 
 
pm-utils ではシステムが AC アダプタに接続しているかどうかに合わせてコマンドを実行することができます。スクリプトを {{ic|/etc/pm/power.d/}} フォルダの中に作成してください。スクリプトの例は [http://crunchbanglinux.org/forums/post/110148/#p110148 crunchbang フォーラム] に存在します。AC 状態の変化を検出するには upower を動作させる必要があるので注意してください (詳しくは [https://bbs.archlinux.org/viewtopic.php?id=132125] を参照)。
 
 
==== AC 状態にあわせて明るさを変化させる ====
 
 
以下は AC 状態にあわせて輝度を変化させる例です。以下の内容で {{ic|/etc/pm/power.d/00-brightness}} というファイルを作成して、あなたのシステムに合わせて、輝度設定のパスとファイルに書き出す値を変更してください。
 
 
{{bc|
 
#!/bin/bash
 
 
case $1 in
 
true)
 
echo "Enable screen power saving"
 
echo 5 > /sys/class/backlight/acpi_video0/device/backlight/acpi_video0/brightness
 
;;
 
false)
 
echo "Disable screen power saving"
 
echo 14 > /sys/class/backlight/acpi_video0/device/backlight/acpi_video0/brightness
 
;;
 
esac
 
}}
 
 
=== アイドル状態でサスペンド ===
 
 
xautolock プログラムを使う方法があります。{{ic|xautolock -time 30 -locker "sudo pm-suspend" -detectsleep &}} を {{ic|~/.xinitrc}} に追加してください。30分間、何も動作がない場合に {{ic|pm-suspend}} を呼び出します。
 
 
=== 通常のスワップパーティションの代わりにスワップファイルを使う ===
 
 
通常のスワップパーティションの代わりにスワップファイルを使いたい場合、[[スワップ#スワップファイル|スワップファイル]]を見て下さい。
 
 
== 高度な設定 ==
 
 
メインの設定ファイルは {{ic|/usr/lib/pm-utils/defaults}} です。このファイルを編集してはいけません。パッケージのアップデートによって、デフォルト設定に書き換えられてしまう可能性があります。設定ファイルは {{ic|/etc/pm/config.d/}} に置くようにしてください。{{ic|/etc/pm/config.d}} に {{ic|modules}} や {{ic|config}} という名前で、以下の内容のシンプルなテキストファイルを作成することで、システム全体の設定ファイルの設定を上書きできます:
 
SUSPEND_MODULES="button uhci_hcd"
 
 
=== 設定ファイルで利用できる変数 ===
 
 
; SUSPEND_MODULES="button": サスペンドする前にアンロードするモジュールのリスト
 
; SLEEP_MODULE="tuxonice uswsusp kernel": 試行するデフォルトのスリープ/復帰システム
 
; HIBERNATE_MODE="shutdown": 再起動ではなく強制的にシャットダウンさせる
 
 
=== フックの無効化 ===
 
 
不必要な、あるいは害を及ぼすフックが動作してしまう場合、それについてバグレポートを送って頂けると幸いです。{{ic|/etc/pm/sleep.d/}} にフックと呼応する空のファイルを作成することで簡単にフックを無効化できます。例えば {{ic|/usr/lib/pm-utils/sleep.d/45pcmcia}} フックを無効化したいときは、次を実行することで無効化できます:
 
# touch /etc/pm/sleep.d/45pcmcia
 
ダミーのフックには実行可能権限は付与しないでください。
 
 
{{Note|適当なディレクトリにダミーファイルを作成してください。例えば {{ic|/usr/lib/pm-utils/power.d}} のフックを無効化する場合、{{ic|/etc/pm/power.d}} にダミーファイルを作成する必要があります。}}
 
 
==== 別の方法 ====
 
 
ブラックリストにしたいモジュールを {{ic|HOOK_BLACKLIST}} 変数に定義したファイルを {{ic|/etc/pm/config.d}} に作成してください。例えば、省電力機能を自分で管理したい場合、以下を使います:
 
HOOK_BLACKLIST="hal-cd-polling intel-audio-powersave journal-commit laptop-mode pcie_aspm readahead sata_alpm sched-powersave xfs_buffer wireless"
 
 
=== フックの作成 ===
 
 
{{Note|systemd を使っている場合、sleep.d のフックはおそらく動作しません。そのようなときは systemd の[[電源管理#スリープフック|スリープフック]]を使って下さい。}}
 
サスペンドやハイバネートのときに何か特別なことをしたい場合、簡単にフックを自分で作成して {{ic|/etc/pm/sleep.d}} に配置することができます。このディレクトリに含まれているフックはサスペンド時にアルファベット順で実行されます (そのため名前の先頭には2桁の数字を付けて、順番が明確になるようにしています)。復帰時は逆の順番で実行されます。数字については以下のように決められています:
 
;00 - 49: ユーザーやパッケージが作成したフック。通常のサービスやユーザー空間のインフラストラクチャが動作しているときに実行するべきフック。
 
;50 - 74: サービスを管理するフック。この範囲のフックはサービスを起動したり停止します。50 以下のフックはサービスが有効になっている状態に実行されると考えてかまいません。
 
;75 - 89: コア以外のハードウェアあるいはモジュールを管理するフック。モジュールをロード・アンロードしたり、安全な状態にサスペンドしたりハイバネートするのを破壊するようなビデオ以外のハードウェアを扱うフックはこの範囲に収まります。75 以下では、全てのモジュールがロードされることになります。
 
;90 - 99: 重要なサスペンドのフック用に予約されています。
 
 
ログファイルに情報を流すだけの、無用のフックを作ると以下のようになります:
 
 
#!/bin/bash
 
case $1 in
 
hibernate)
 
echo "Hey guy, we are going to suspend to disk!"
 
;;
 
suspend)
 
echo "Oh, this time we are doing a suspend to RAM. Cool!"
 
;;
 
thaw)
 
echo "Oh, suspend to disk is over, we are resuming..."
 
;;
 
resume)
 
echo "Hey, the suspend to RAM seems to be over..."
 
;;
 
*) echo "Somebody is calling me totally wrong."
 
;;
 
esac
 
 
上記のファイルを {{ic|/etc/pm/sleep.d/66dummy}} として保存して {{ic|chmod +x /etc/pm/sleep.d/66dummy}} を実行してください。サスペンドや復帰時にメッセージが出力されます。
 
 
{{Warning|全てのフックは root で実行されます。したがって、一時ファイルを作成する場合は注意してください。セキュリティに問題が起きないように {{ic|PATH}} 環境変数が正しく設定されていることなどを確認します。}}
 
 
== 仕組み ==
 
 
仕組みはとても簡単です: メインスクリプト ({{ic|pm-suspend}}, {{ic|pm-hibernate}}, {{ic|pm-suspend-hybrid}} などのシンボリックリンクで {{ic|pm-action}} が呼びされます) はアルファベット順で実行可能スクリプトである"フック"を実行し、その際 {{ic|suspend}} (suspend to RAM) あるいは {{ic|hibernate}} (suspend to disk) のパラメータが使われます。全てのフックが実行されると、マシンはスリープ状態になります。マシンが再度起こされると、全てのフックは逆順に実行され {{ic|resume}} (resume from RAM) あるいは {{ic|thaw}} (resume from disk) のパラメータが使われます。フックは様々なことを行います。ブートローダーの準備や Bluetooth サブシステムの停止、重要なモジュールのアンロードなどです。
 
 
{{ic|pm-suspend}} と {{ic|pm-hibernate}} はどちらも大抵は [[Udev]] から呼び出され、Udev 自体は {{Pkg|gnome-power-manager}} や {{ic|kpowersave}} などのデスクトップアプレットから実行されます。
 
 
{{Note|{{ic|suspend-hybrid}} is a placeholder right now -- it is not completely implemented.}}
 
 
マシンを高出力モードあるいは低出力モードに設定することもできます。{{ic|true}} や {{ic|false}} のパラメータを追加して {{ic|pm-powersave}} コマンドを使います。基本的なところはサスペンドフレームワークと同じです。
 
 
サスペンドするときのフックは以下のディレクトリに配置されています:
 
;{{ic|/usr/lib/pm-utils/sleep.d}}: ディストリビューションやパッケージによって配置されたフック
 
;{{ic|/etc/pm/sleep.d}}: システム管理者によって追加されたフック
 
 
電源状態を変更するときのフックは以下のディレクトリに配置されています:
 
;{{ic|/usr/lib/pm-utils/power.d}}: ディストリビューションやパッケージによって配置されたフック
 
;{{ic|/etc/pm/power.d}}: システム管理者によって追加されたフック
 
 
{{ic|/etc/pm/}} のフックは {{ic|/usr/lib/pm-utils/}} のフックよりも優先されるため、システム管理者はディストリビューションによって決められたデフォルト設定を上書きすることができます。
 
 
=== Pm-suspend の内部 ===
 
 
This outlines the internal actions when {{ic|pm-suspend}} is run, describing how {{ic|pm-utils}} gracefully falls back onto the kernel method if the requirements of other methods are not met.
 
 
$ pm-suspend
 
 
The first step is set-up preliminary variables and source parent scripts:
 
export STASHNAME=pm-suspend
 
export METHOD="$(echo ${0##*pm-} |tr - _)"
 
. "/usr/lib/pm-utils/pm-functions"
 
 
The variable {{Ic|METHOD}} is extracted from the executable name, ''suspend'' from {{ic|pm-suspend}} and ''hibernate'' from {{ic|pm-hibernate}}.
 
 
The location of runtime configuration parameters is defined in {{ic|/usr/lib/pm-utils/pm-functions}} as ''PM_UTILS_RUNDIR="/var/run/pm-utils"'' and ''STORAGEDIR="${PM_UTILS_RUNDIR}/${STASHNAME}/storage"''. Therefore ''STORAGEDIR="/var/run/pm-utils/pm-suspend/storage"''; this is where {{ic|pm-suspend}} will cache its configuration. Disabled hooks are stored as plain text files with the hook name prefixed by "''disable_hook:''". Configuration parameters are appended to the ''parameters'' file:
 
{{hc|$ ls -lah /var/run/pm-utils/pm-suspend/storage/|
 
-rw-r--r-- 1 root root 20 May 19 09:57 disable_hook:99video
 
-rw-r--r-- 1 root root 0 May 19 02:59 parameters
 
-rw-r--r-- 1 root root 247 May 19 02:59 parameters.rm
 
-rw-r--r-- 1 root root 9 May 19 02:59 state:cpu0_governor
 
-rw-r--r-- 1 root root 9 May 19 02:59 state:cpu1_governor
 
}}
 
 
Then {{Ic|pm-functions}} will source the files located in {{Ic|/etc/pm/config.d/}} in addition to {{ic|/usr/lib/pm-utils/defaults}}. Upon returning, {{Ic|pm-functions}} will proceed to source the files specified by '''$SLEEP_METHOD''' as {{Ic|/usr/lib/pm-utils/module.d/$SLEEP_METHOD[...]}} if they exist:
 
for mod in $SLEEP_MODULE; do
 
mod="${PM_UTILS_LIBDIR}/module.d/${mod}"
 
[ -f "$mod" ] || continue
 
. "$mod"
 
done
 
 
Otherwise, if '''$SLEEP_MODULE''' is empty, {{ic|do_suspend()}} will be set to the kernel backend as described above:
 
if [ -z "$SUSPEND_MODULE" ]; then
 
if grep -q mem /sys/power/state; then
 
SUSPEND_MODULE="kernel"
 
do_suspend() { echo -n "mem" >/sys/power/state; }
 
elif [ -c /dev/pmu ] && pm-pmu --check; then
 
SUSPEND_MODULE="kernel"
 
do_suspend() { pm-pmu --suspend; }
 
elif grep -q standby /sys/power/state; then
 
SUSPEND_MODULE="kernel"
 
do_suspend() { echo -n "standby" >/sys/power/state; }
 
fi
 
fi
 
 
Assuming '''$SLEEP_MODULE''' is not empty and {{Ic|uswsusp}} is specified, {{Ic|/usr/lib/pm-utils/module.d/uswsusp}} is executed. This script checks several requirements (these are the requirements for being able to use uswsusp):
 
* [ -z $SUSPEND_MODULE ]
 
* command_exists s2ram
 
* grep -q mem /sys/power/state || ( [ -c /dev/pmu ] && pm-pmu --check; );
 
If these requirements are met, do_suspend() is defined as:
 
do_suspend()
 
{
 
uswsusp_get_quirks
 
s2ram --force $OPTS
 
}
 
Most importantly, the {{Ic|uswsusp}} module runs:
 
add_before_hooks uswsusp_hooks
 
add_module_help uswsusp_help
 
The first function, ''add_before_hook'' disables the '''pm-utils''' hooks '''99video''' since this functionality is subsumed by '''s2ram'''.
 
The second function, ''add_module_help'', adds uswsusp-module-specific help, which in essence replaces the help function provided by '''99video'''.
 
 
Back to {{Ic|pm-suspend}}:
 
command_exists "check_$METHOD" && command_exists "do_$METHOD"
 
"check_$METHOD"
 
This verifies that the ''check_suspend'' and ''do_suspend'' methods have been defined. The ''check_suspend'' method simply verifies that $SUSPEND_MODULE is not empty:
 
 
check_suspend() { [ -n "$SUSPEND_MODULE" ]; }
 
 
Lastly, {{Ic|pm-suspend}} must run all hooks that have not been disabled, sync file-system buffers, and run ''do_suspend'':
 
if run_hooks sleep "$ACTION $METHOD"; then
 
# Sleep only if we know how and if a hook did not inhibit us.
 
log "$(date): performing $METHOD"
 
sync
 
"do_$METHOD" || r=128
 
log "$(date): Awake."
 
 
The method ''run_hooks'' is a wrapper for ''_run_hooks'', which the case of {{ic|pm-suspend}} is called as ''run_hooks sleep "suspend suspend"''. Given that:
 
PARAMETERS="${STORAGEDIR}/parameters"
 
PM_UTILS_LIBDIR="/usr/lib/pm-utils"
 
PM_UTILS_ETCDIR="/etc/pm"
 
 
The method ''_run_hooks'', will for each hook in ''"${PM_UTILS_LIBDIR}/$1.d"'' and ''"${PM_UTILS_ETCDIR}/$1.d"'', check that sleep has not been inhibited and update the runtime parameters stored in ''$PARAMETERS'' before running each hook via ''run_hook $hook $2''. In the case of Suspend-to-RAM, all the hooks in ''{/usr/lib/pm-utils/sleep.d/,/etc/pm/sleep.d/}'' will be enumerated, and ''run_hook'' will be passed the parameters ''$hook'' and "''suspend suspend''". The method ''run_hook'' uses the ''hook_ok'' function to verify that the hook has not been disabled before executing the hook with the "''suspend suspend''" parameters.
 
 
== Tips and tricks ==
 
 
=== 復帰時にハードディスクの電源管理レベルを自動的に設定 ===
 
 
以下のようにフックを作成:
 
{{hc|/etc/pm/sleep.d/50-hdparm_pm|<nowiki>
 
#!/bin/dash
 
 
if [ -n "$1" ] && ([ "$1" = "resume" ] || [ "$1" = "thaw" ]); then
 
hdparm -B 254 /dev/sda > /dev/null
 
fi
 
</nowiki>}}
 
 
そして次を実行:
 
# chmod +x /etc/pm/sleep.d/50-hdparm_pm
 
 
上記の [[Bash]] スクリプトが動作しない場合、以下のスクリプトで動作する可能性があります:
 
{{hc|/etc/pm/sleep.d/50-hdparm_pm|<nowiki>
 
#!/bin/sh
 
 
. "${PM_FUNCTIONS}"
 
case "$1" in
 
thaw|resume)
 
sleep 6
 
hdparm -B 254 /dev/sda
 
;;
 
*)
 
;;
 
esac
 
exit $NA
 
</nowiki>}}
 
 
{{ic|-B}} スイッチの値を低くすると効果があるかもしれません。[[hdparm]] を見て下さい。
 
 
=== マウスの再起動 ===
 
 
ノートパソコンによっては、サスペンドがされた後にマウスが動かなくなることがあります。{{ic|/etc/pm/hooks}} にフックを作成して PS/2 ドライバー (例: {{ic|i8042}}) を強制的に再初期化することで解決します ([[#フックの作成|フックの作成]]を参照):
 
 
#!/bin/sh
 
echo -n "i8042" > /sys/bus/platform/drivers/i8042/unbind
 
echo -n "i8042" > /sys/bus/platform/drivers/i8042/bind
 
 
=== Openbox のメニューにスリープモードを追加 ===
 
 
Openbox users can add the new scripts as additional shutdown options within the Openbox menu by adding the items to a new or existing sub-menu in {{ic|~/.config/openbox/menu.xml}}, for example:
 
<menu id="64" label="Shutdown">
 
<item label="Lock"> <action name="Execute"> <execute>xscreensaver-command -lock</execute> </action> </item>
 
<item label="Logout"> <action name="Exit"/> </item>
 
<item label="Reboot"> <action name="Execute"> <execute>sudo shutdown -r now</execute> </action> </item>
 
<item label="Poweroff"> <action name="Execute"> <execute>sudo shutdown -h now </execute> </action> </item>
 
'''<item label="Hibernate"> <action name="Execute"> <execute>sudo pm-hibernate</execute> </action> </item>'''
 
'''<item label="Suspend"> <action name="Execute"> <execute>sudo pm-suspend</execute> </action> </item>'''
 
</menu>
 
 
=== "sleep" と "power" ボタンの処理 ===
 
 
"Sleep" と "power" ボタンは {{ic|acpid}} の {{ic|/etc/acpi/handler.sh}} で処理されます ("button/power" と "power/sleep" エントリを見て下さい)。{{ic|pm-suspend}} や {{ic|pm-hibernate}} を呼び出すようにデフォルトのアクションを置き換えることができます。
 
 
[[電源管理#ACPI イベント|systemd]] は独自に電源イベントを管理しており pm-utils や {{ic|/etc/pm/*}} のスクリプトは使わないので注意してください。
 
 
=== ハイバネートやサスペンド時にスクリーンセーバーをロック ===
 
 
You may wish to run a screen locking utility when the system suspends (so that a password is required after waking up). This can be done by adding a script to the {{ic|/etc/pm/sleep.d}} folder. Make sure the script is executable (chmod 755) and owned by {{ic|root:root}}.
 
 
A simple example script is:
 
 
{{hc|/etc/pm/sleep.d/00screensaver-lock|<nowiki>
 
#!/bin/sh
 
#
 
# 00screensaver-lock: lock workstation on hibernate or suspend
 
 
username= # add username here; i.e.: username=foobar
 
userhome=/home/$username
 
export XAUTHORITY="$userhome/.Xauthority"
 
export DISPLAY=":0"
 
 
case "$1" in
 
hibernate|suspend)
 
su $username -c "/usr/bin/slimlock" & # or any other such as /usr/bin/xscreensaver-command -lock
 
;;
 
thaw|resume)
 
;;
 
*) exit $NA
 
;;
 
esac</nowiki>}}
 
 
Replace {{ic|/usr/bin/slimlock}} with the path to your screen locking utility of choice.
 
 
If you do not wish to hard-code your username (e.g., if you have multiple users), then it is necessary to determine the current X11 username and display number. For systems using [[systemd]], you can use [https://github.com/rephorm/xuserrun xuserrun] and the following sleep.d script (be sure to modify the path to xuserrun and your desired screen locker):
 
 
{{hc|/etc/pm/sleep.d/00screensaver-lock|<nowiki>
 
#!/bin/sh
 
#
 
# 00screensaver-lock: lock workstation on hibernate or suspend
 
 
case "$1" in
 
hibernate|suspend)
 
/path/to/xuserrun /usr/bin/slimlock & # or any other such as /usr/bin/xscreensaver-command -lock
 
;;
 
thaw|resume)
 
;;
 
*) exit $NA
 
;;
 
esac
 
</nowiki>}}
 
 
If you have problems using xuserrun, you can instead try having loginctl do this directly. This script will lock all active sessions before going into hibernation:
 
 
{{hc|/etc/pm/sleep.d/00screensaver-lock|<nowiki>
 
#!/bin/sh
 
#
 
# 00screensaver-lock: lock workstation on hibernate or suspend
 
 
case "$1" in
 
hibernate|suspend)
 
loginctl lock-sessions
 
;;
 
thaw|resume)
 
;;
 
*) exit $NA
 
;;
 
esac
 
</nowiki>}}
 
 
=== polkit でハイバネーションを無効化 ===
 
 
ハイバネーションを無効化するには、{{ic|/etc/polkit-1/}} に {{ic|99-disable-hibernate.rules}} という名前の新しいファイルを作成してください。そして、以下の内容を記述します:
 
 
{{hc|99-disable-hibernate.rules|<nowiki>
 
polkit.addRule(function(action, subject) {
 
if ((action.id == "org.freedesktop.login1.hibernate")) {
 
return polkit.Result.NO;
 
}
 
});
 
 
polkit.addRule(function(action, subject) {
 
if ((action.id == "org.freedesktop.login1.hibernate-multiple-sessions")) {
 
return polkit.Result.NO;
 
}
 
});
 
</nowiki>}}
 
 
KDE を使っている場合、一度ログオフすればハイバネーションオプションが消えます。
 
 
== トラブルシューティング ==
 
 
サスペンドやハイバネートが正しく動作しない場合、ログファイル {{ic|/var/log/pm-suspend.log}} に何らかの情報を見つけられる可能性があります。例えば、動作したフックやフックの出力などがログファイルで確認できます。
 
 
Also, check the output of the {{ic|pm-is-supported}} command. This command (with the {{ic|--hibernate}} or {{ic|--suspend}} flag) will do some sanity checking and report any errors it finds in your configuration. It will not detect all possible errors, but may still be useful.
 
 
=== セグメンテーション違反 ===
 
 
セグメンテーション違反が発生してシステムが反応しなくなったりする場合、[[#ハイバネーション (suspend2disk)|上]]で説明しているように {{ic|/boot/grub/menu.lst}} の resume-path に UUID を設定してみてください。
 
 
=== サスペンドから復帰する代わりに再起動する ===
 
 
この問題はサスペンド時に NVS 領域を保存するようになってから起こるようになりました (2.6.35-rc4) ([http://www.spinics.net/lists/linux-acpi/msg29521.html メーリングリストの投稿])。しかしながら、全てのマシンでこの機構が動作するとは限らないと知れ渡ってから、カーネルの開発者は {{ic|1=acpi_sleep=nonvs}} カーネルコマンドラインオプションで無効化できるようにしています ([[カーネルパラメータ]]を参照)。
 
 
=== サスペンドから復帰するとシャットダウンしてしまう ===
 
 
On an Acer Aspire AS3810TG, resuming from suspend shuts down the computer instead of waking it up. If you experience a similar issue, try passing the parameter {{ic|1=i8042.reset=1}} to your kernel. In [[GRUB]], the line in {{ic|/boot/grub/grub.cfg}} should be something like this:
 
linux /vmlinuz-linux root=/dev/vg00/root resume=/dev/vg00/swap i8042.reset=1 ro
 
 
Although I have not tested this, you could also set this parameter live without having to restart by doing:
 
# sysctl -e -w i8042.reset=1
 
 
=== サスペンドから復帰したときに画面が表示されない ===
 
 
Some laptops (e.g. Dell Inspiron Mini 1018) will just show a black screen with no backlight after resuming from suspend. If this happens to you, try going into the BIOS of the laptop and disabling Intel SpeedStep if it is present.
 
 
You could also try, without disabling SpeedStep, creating a quirk in {{ic|/etc/pm/sleep.d/}} with this content (requires {{Pkg|vbetool}}):
 
{{bc|
 
#!/bin/sh
 
#
 
case "$1" in
 
suspend)
 
;;
 
resume)
 
sleep 5
 
vbetool dpms off
 
vbetool dpms on
 
;;
 
*) exit $NA
 
;;
 
esac
 
}}
 
save it as you want but with a {{ic|00}} in front of the name so this is called last when resuming; remember to {{ic|chmod +x}} the script.
 
Try adjusting the {{ic|sleep}} time if the other commands are called too soon, or if it works well, you can also try removing that line.
 
 
Some other laptops (e.g. Toshiba Portégé R830) will just show a black screen with no backlight after resuming from suspend, with fans blowing at top speed. If this is what you're seeing, try going into the BIOS and disable the VT-d virtualization setting by switching to "VT-x only".
 
 
=== VirtualBox の問題 ===
 
 
ノートパソコンによっては VirtualBox のカーネルモジュールによって {{ic|pm-suspend}} や {{ic|pm-hibernate}} が機能しなくなることがあります ([https://bbs.archlinux.org/viewtopic.php?id=123354] を参照)。サスペンドやハイバネートがされる代わりに、システムはフリーズしてインジケータ LED が点滅します (ThinkPad の場合、サスペンドインジケータが点滅。MSI Wind U100 の場合、Caps Lock や Scroll Lock のインジケータが点滅)。{{ic|pm-suspend}} と {{ic|pm-hibernate}} のログは通常通りに出力されます。
 
 
サスペンドやハイバネートをする前にモジュールをアンロードして、復帰後にモジュールをリロードするようにすることで問題を解決できます。スクリプトを使うことでモジュールを管理できます:
 
{{bc|1=
 
#!/bin/sh
 
 
rmmod vboxdrv
 
pm-hibernate
 
modprobe vboxdrv
 
}}
 
 
{{Note|root で {{ic|vboxbuild}} を実行してカーネルモジュールをリビルドすることで問題が解決するという報告もあります。}}
 
 
=== スワップパーティションが存在しないのにハイバネート ===
 
 
有効なスワップパーティションが存在しないのにハイバネートしようとすると、ハイバネートが開始されるようにみえて、すぐに復帰してしまいます。たとえ、ログ出力を詳細にするように指定していても、スワップパーティションが存在しないことに関するエラーメッセージが全く表示されません。そのため、この問題をデバッグするのは大変です。スワップパーティションが何らかの理由で破損していて無効になっていると、インストール時にスワップパーティションを設定していてもこの問題が発生することがあります。ハイバネートですぐ復帰するようならば、使用しているスワップパーティションが本当に有効になっているか確認してください。{{ic|blkid}} コマンドの出力が以下のようになっている場合:
 
{{hc|# blkid|2=
 
/dev/sda1: UUID="00000-000-000-0000000" TYPE="ext2"
 
/dev/sda2: UUID="00000-000-000-0000000" TYPE="ext4"
 
/dev/sda3: UUID="00000-000-000-0000000" TYPE="ext4"
 
/dev/sda4: UUID="00000-000-000-0000000" TYPE="swap"
 
}}
 
タイプが {{ic|"swap"}} のパーティションがあれば大丈夫です。パーティションが存在しない場合、[[スワップ#スワップパーティション]]を見て、スワップパーティションを再作成・有効化してください。
 
 
=== サスペンドしようとしたときにカーソルしか表示されない黒画面になる ===
 
 
If you get a black screen with unblinking cursor when trying to do
 
$ sudo pm-suspend
 
have a look at {{ic|/var/log/pm-suspend.log}} and search for "ehci" or "xhci". Some of the names you could find may be "ehci_hd", "xhci_hd" or "ehci_hcd".
 
 
Then as root create the file {{ic|/etc/pm/config.d/modules}} and include this code with the exact name of the ehci or xhci module you found. For example:
 
SUSPEND_MODULES="ehci_hcd"
 
Suspend should now be working.
 
 
=== 画面が表示されない問題 ===
 
 
Some users have reported having issues with their laptops not resuming after a suspend or hibernate. This is due to the {{ic|autodetect}} hook in "HOOKS" array of the {{ic|/etc/mkinitcpio.conf}} file. This can be disabled using the same method for adding the {{ic|resume}} hook. Just remove {{ic|autodetect}} from the list and follow the steps to build the new image. See [[#Mkinitcpio_Resume_Hook|Resume Hook]] for more details on building the new image.
 
 
{{Note|If you are using [[plymouth]] it may be an other reason to this issue. Adding {{ic|resume}} before {{ic|plymouth}} in "HOOKS" array of the {{ic|/etc/mkinitcpio.conf}} file should fix this.}}
 
 
=== 64ビットの OS で復帰できない ===
 
 
Certain motherboards/BIOS combinations (specifically known are some Zotac ITX boards, perhaps others) will not resume properly from suspend if any 64 bit operating system is installed. The solution is the enter your BIOS setup and Disable the "Memory Remapping Hole" in your DRAM configuration page. This will probably fix the suspend to RAM problem but will probably result in your OS not detecting all of your RAM.
 
 
=== radeon ドライバーでハイバネートから復帰した時に黒画面になる ===
 
 
When using the radeon driver and having {{ic|radeon}} in the {{ic|HOOKS}} array of the {{ic|/etc/mkinitcpio.conf}} resuming from hibernation results in the screen being black, however everything else working (testable by keeping a console open with a command to execute and starting the execution after resuming).
 
This seems to be related to using {{ic|radeon.dpm<nowiki>=</nowiki>1}} (default since kernel 3.13) as the power management method in radeon.
 
 
HOOKS 行から {{ic|radeon}} を削除 (そして initrd を再生成) することでこの問題は解決します ([https://bugs.freedesktop.org/show_bug.cgi?id=72716] を参照)。
 
 
=== ハイバネート時にコンピュータの電源が切れない ===
 
 
Linux をハイバネートしてディスクにデータが書き込まれた後、コンピュータの電源が正しく切れないことがあります。その場合、強制的に電源を切ってから再起動すると、復帰が正しく動作します。
 
 
{{ic|/etc/pm/config.d/hibernate_mode}} という名前の実行可能ファイルを作成して、次の行を記述することで修正できます: {{ic|HIBERNATE_MODE<nowiki>=</nowiki>"shutdown"}}。その後 pm-hibernate でコンピュータが正しくシャットダウンされるようになります。
 
 
=== サスペンド後にディスプレイの電源が入らない (radeon) ===
 
 
radeon gpu でサスペンド後にディスプレイが表示されない場合、以下の内容で {{ic|/etc/pm/config.d/radeon}} を作成してみてください:
 
 
{{hc|/etc/pm/config.d/radeon|2=
 
QUIRK_S3_BIOS="true"
 
QUIRK_S3_MODE="true"
 
}}
 
 
== 参照 ==
 
 
* [http://en.opensuse.org/SDB:Pm-utils OpenSUSE Wiki] - The article from where this was originally sourced (Licensed under GPL)
 
* [https://wiki.ubuntu.com/UnderstandingSuspend Understanding Suspend] - Ubuntu article explaining how suspending to RAM works
 
* [http://www.mjmwired.net/kernel/Documentation/power/basic-pm-debugging.txt#178 PM Debugging] - Basic PM debugging
 
*[[Cpufrequtils]] - CPU 周波数スケーリングと CPU 電源スキーム
 
*[[Acpid]] - ACPI イベントを通知するデーモン
 
* [http://superuser.com/questions/298672/linuxhow-to-hibernate-after-a-period-of-sleep Hibernate after sleep] - An example of a custom pm-utils hook where hibernation is triggered after a period of time in suspension
 

2021年7月7日 (水) 14:11時点における最新版