Uswsusp

提供: ArchWiki
2015年12月6日 (日) 18:16時点におけるKusakata (トーク | 投稿記録)による版
ナビゲーションに移動 検索に移動

関連記事

uswsusp (userspace software suspend) は Linux 環境でハイバネーション (suspend-to-disk) や サスペンド (suspend-to-RAM あるいは standby) をするために使われるユーザースペースツールのセットです。以下のツールから構成されます:

  • s2ram - サスペンドの前や復帰後にグラフィックアダプタの操作をユーザーランドから行えるようにして復帰後にグラフィック (やシステム全体) を復活させる、カーネルの suspend-to-RAM 機構のラッパー。vbetool や radeontool の機能を取り入れます。動作中のハードウェアの設定リストと適切な操作のセットを読み込むことで正しく復帰を実行します。HAL によって管理されているハードウェアのホワイトリストを使用します - s2ram は HAL のデータベースオプションを s2ram のパラメータに翻訳します。
ノート: HAL は廃止されユーザー空間の設定を省いて直接 KMS ドライバーがグラフィックカードの状態を保存するため、s2ram の開発は終了しておりホワイトリストのエントリがこれから追加されることはありません。KMS ドライバーを使っている場合、s2ram は直接マシンをサスペンドします。
  • s2disk - ユーザー空間ソフトウェアサスペンド (µswsusp) のリファレンス実装。システムをサスペンドするのに必要な手順 (プロセスのフリーズやスワップ領域の準備など) をまとめて、イメージの読み書きを処理します。s2disk はイメージの圧縮や暗号化などの機能をサポートしており、他の機能 (例: 見栄えの良いプログレスバー, 外部ディスクへのイメージの保存, 復帰中にテトリスを遊ぶなど) も簡単に追加できます。
  • s2both - バッテリー残量がないときは s2ram と s2disk の機能を組み合わせるのが大いに役立ちます。s2both は (s2disk のように) システムのスナップショットをスワップに書き出して、それから (s2ram のように) マシンを STR 状態にします。バッテリーの残量が十分ある場合は STR から高速に復帰でき、足りないときはディスクから復帰するため作業を喪失することがありません。

インストール

uswsusp は AURuswsusp-gitAUR からインストールできます。

設定

ディスクにサスペンドする前に /etc/suspend.conf を編集してください。

  • スワップパーティションを使う場合:
resume device = /dev/disk/by-label/swap

/dev/disk/by-label/swap はスワップパーティションが含まれている適当なブロックデバイスに置き換えて下さい。

resume device = /dev/sdXN  # the partition which contains swapfile 
resume offset = 123456

123456 はスワップファイルのヘッダが存在する resume デバイスの先頭からのオフセットに置き換えて下さい。resume オフセットは以下のコマンドで確認できます:

# swap-offset your-swap-file
  • image size パラメータを使うことで s2disk によって作成されるシステムのスナップショットイメージの容量を制限することができます (任意)。設定された容量ではイメージを作成することができない場合でも、s2disk は制限を無視してサスペンドを行います。イメージ容量を 0 に設定した場合、イメージは可能な限り小さくなります。
  • shutdown method パラメータはマシンの電源を切れる状態になったときに実行する操作を指定します (任意)。"reboot" に設定するとマシンはすぐに再起動するようになります。"platform" に設定するとカーネルから利用できる特殊な電源管理の操作を使ってマシンはシャットダウンします。ハードウェアによっては復帰後に正しく再初期化するために必要だったり、システムの復帰が高速化されたりします。
  • compute checksum パラメータが 'y' に設定されている場合、s2disk と resume ツールは MD5 アルゴリズムを使ってイメージの整合性を確認します。
  • compress パラメータが 'y' に設定されている場合、s2disk と resume ツールは LZF 圧縮アルゴリズムを使ってイメージを圧縮・解凍します。
  • splash が 'y' に設定されている場合、s2disk や resume はスプラッシュシステムを使います。現在 splashy と fbsplash がサポートされています。
    ノート: This requires additional configure flags for uswsusp (--enable-splashy and --enable-fbsplash, respectively).
  • resume pause オプションはハイバネートから復帰した後に待機時間を挟み込み、ユーザーが統計情報を読めるようにします (読み書き速度やイメージ容量など)。
  • threads が有効になっている場合、s2disk はイメージの圧縮・暗号化・書き込みに複数のスレッドを使います。有効にすることで動作が高速になります。詳しくは suspend.c のコメントを読んで下さい。

暗号化のサポート

  • パッケージに含まれている suspend-keygen ユーティリティでキーを生成してください
  • /etc/suspend.conf にキーの名前を記述します:
encrypt = y
RSA key file = <path_to_keyfile>

initramfs の再作成

ノート: Whenever you modify /etc/suspend.conf, you will need to rebuild your initramfs. If you fail to do so, and linux cannot find your image at startup, you will not see an error message indicating this. Your boot process will hang after starting the uresume hook, typically after the message with the libgcrypt version.

/etc/mkinitcpio.conf ファイルを編集して HOOKS エントリに "uresume" を追加してください:

HOOKS="base udev autodetect block uresume filesystems"

そして ramdisk を再作成してください:

# mkinitcpio -p linux

サンプル設定

/etc/suspend.conf
snapshot device = /dev/snapshot

resume device = /dev/disk/by-label/swap

# image size is in bytes
image size = 1468006400

#suspend loglevel = 2

compute checksum = y

compress = y

#encrypt = y

#early writeout = y

#splash = y

# up to 60 (seconds)
#resume pause = 30  

threads = y

使用方法

スタンドアロン

ディスクにサスペンドするには、次を実行:

# s2disk

RAM にサスペンドするには、まず次を実行:

# s2ram --test

あなたのマシンが動作確認済みのマシンデータベースに入っているか確認します。"Machine matched entry xyz" などと返ってきたら次を実行:

# s2ram

サスペンドできない場合 --force パラメータを使用したり、他のパラメータと組み合わせる必要があるかもしれません (s2ram --help を参照)。

Pm-utils や hibernate-script などの s2disk を内部的に呼び出すユーザースペースツールを使用する必要がある場合もあります。詳しくは hibernate-script を見て下さい。

pm-utils を使う

Pm-utils は uswsusp を含む、複数のスリープバックエンドを使うことができます。/etc/pm/config.d/module を作成・編集してください:

SLEEP_MODULE=uswsusp

上記の設定で pm-suspend と pm-hibernate は uswsusp を使うようになります。通常ユーザーは以下のコマンドを使うことで uswsusp でサスペンドすることが可能です:

$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
ノート: ユーザーのウィンドウマネージャデスクトップ環境は gdm や kdm などのログインマネージャで起動する必要があります。また、upower をインストールしてください。

systemd を使う

systemctl hibernate でシステムをハイバネーション (Suspend to Disk) するには、以下を実行:

# cp /usr/lib/systemd/system/systemd-hibernate.service /etc/systemd/system/
# cd /etc/systemd/system/

お好きなテキストエディタで systemd-hibernate.service を開いて以下の行を編集して:

/etc/systemd/system/systemd-hibernate.service
...
ExecStart=/usr/lib/systemd/systemd-sleep hibernate

以下のようにしてください:

/etc/systemd/system/systemd-hibernate.service
...
ExecStart=/bin/sh -c 's2disk && run-parts --regex .\* -a post /usr/lib/systemd/system-sleep'

設定後、systemctl hibernate を実行するとシステムがハイバネートします。同じように systemd-hybrid-sleep.service で uswsusp のハイブリッドスリープも有効にできます。

トラブルシューティング

マシンがホワイトリストに入っていない

s2ram でホワイトリストのエントリとあなたのマシンが一致しない場合、あなたのマシンに関する様々な情報が出力されます (s2ram -i で表示されるのと同じです)。その場合、s2ram -f を使うことで s2ram で強制的にマシンをサスペンドすることができます。

s2ram -f が動作しない

s2ram -f が動作しない場合、s2ram によって提供されている別の手段を試してみて下さい。s2ram -h を実行すると利用可能なオプションのリストが表示されます:

# s2ram -h
Usage: s2ram [-nhi] [-fspmrav]

Options:
    -h, --help:       this text.
    -n, --test:       test if the machine is in the database.
                      returns 0 if known and supported
    -i, --identify:   prints a string that identifies the machine.
    -f, --force:      force suspending, even on unknown machines.

The following options are only available with -f/--force:
    -s, --vbe_save:   save VBE state before suspending and restore after resume.
    -p, --vbe_post:   VBE POST the graphics card after resume
    -m, --vbe_mode:   get VBE mode before suspend and set it after resume
    -r, --radeontool: turn off the backlight on radeons before suspending.
    -a, --acpi_sleep: set the acpi_sleep parameter before suspend
                      1=s3_bios, 2=s3_mode, 3=both
    -v, --pci_save:   save the PCI config space for the VGA card.

以下の組み合わせを試してみて下さい:

  s2ram -f -a 1
  s2ram -f -a 2
  s2ram -f -a 3
  s2ram -f -p -m
  s2ram -f -p -s
  s2ram -f -m
  s2ram -f -s
  s2ram -f -p
  s2ram -f -a 1 -m
  s2ram -f -a 1 -s

If none of those combinations work, start again but add the -v switch.

Note that mixing the -a options and the vbetool options (-p, -m, -s) is normally only a measure of last resort, it usually does not make much sense.

If you find several combinations that work (e.g. s2ram -f -a 3 and s2ram -f -p -m both work on your machine), the in-kernel method (-a) should be preferred over the userspace methods (-p, -m, -s).

Verify all combinations in both cases when reporting success to the s2ram developers:

  • when issuing s2ram from console
  • when issuing s2ram from X

オプションをどのように組み合わせても s2ram が動作しない

There is a trick which does not correspond to a command line option, because it requires additional operations from you. It is marked with NOFB in the whitelist and used for those laptops which suspend and resume properly only if no framebuffer is used. If you verify that no command line option of s2ram works, you can try disabling the framebuffer. To do this, you need to edit your bootloader configuration, remove any possible vga=<foo> values from the kernel line and reboot. This at least if you use the VESAFB framebuffer (as in the arch default kernel). If you use a different framebuffer driver, refer to the documentation of the driver to see how to disable it.

参照