Linux 休眠命令
休眠的型別
目前大概由三種類型的休眠:
suspend(suspend to RAM)
指的是除了記憶體以外的大部分機器部件都進入斷電狀態。 這種休眠狀態恢復速度特別快,但由於記憶體中的資料並沒有被儲存下來,因此這個狀態的系統並沒有進入真正意義上的休眠狀態,還在持續耗電。
hibernate(suspend to disk)
這種休眠會將記憶體中的系統狀態寫入交換空間內,當系統啟動時就可以從交換空間內讀回系統狀態。 這種情況下系統可以完全斷電,但由於要儲存/讀取系統狀態到/從交換空間,因此速度會比較慢,而且需要進行一些配置(下面會說到)
hybrid(suspend to both)
結合了上面兩種休眠型別。它像hibernate一樣將系統狀態存入交換空間內,同時也像suspend一樣並不關閉電源。 這種,在電源未耗盡之前,它能很快的從休眠狀態恢復。而若休眠期間電源耗盡,則它可以從交換空間中恢復系統狀態。
suspend 休眠
進入 suspend 特別簡單,無需額外的配置,在 systemd 系統上直接執行 systemctl suspend 就行了。
systemctl suspend
它的實際動作由 systemd-suspend.service 所定義, 在 archlinux 上,它長成這樣子的:
#SPDX-License-Identifier: LGPL-2.1+ # #This file is part of systemd. # #systemd is free software; you can redistribute it and/or modify it #under the terms of the GNU Lesser General Public License as published by #the Free Software Foundation; either version 2.1 of the License, or #(at your option) any later version. [Unit] Description=Suspend Documentation=man:systemd-suspend.service(8) DefaultDependencies=no Requires=sleep.target After=sleep.target [Service] Type=oneshot ExecStart=/usr/lib/systemd/systemd-sleep suspend