「LVM によるルートファイルシステムのスナップショット作成」の版間の差分
一部翻訳 |
リンクを修正 |
||
| (同じ利用者による、間の3版が非表示) | |||
| 1行目: | 1行目: | ||
[[Category: |
[[Category:システムリカバリ]] |
||
[[en:Create root filesystem snapshots with LVM]] |
[[en:Create root filesystem snapshots with LVM]] |
||
[[zh-hans:Create root filesystem snapshots with LVM]] |
[[zh-hans:Create root filesystem snapshots with LVM]] |
||
{{Related articles start}} |
{{Related articles start}} |
||
{{Related|LVM}} |
{{Related|LVM}} |
||
{{Related| |
{{Related|Tar によるフルシステムバックアップ}} |
||
{{Related articles end}} |
{{Related articles end}} |
||
| 14行目: | 14行目: | ||
[[LVM#スナップショット|LVM スナップショット]] の前提条件が正しく設定されていることを確認してください。 |
[[LVM#スナップショット|LVM スナップショット]] の前提条件が正しく設定されていることを確認してください。 |
||
== |
== セットアップ == |
||
システムの起動時にルートボリュームのクリーンなスナップショットを作成するために systemd サービスを使用します。 |
|||
Use a systemd service to create a clean snapshot of the root volume during system startup. |
|||
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} を作成します。 |
|||
{{bc|1= |
{{bc|1= |
||
| 37行目: | 37行目: | ||
}} |
}} |
||
ルートボリュームグループとボリューム名に合わせて、{{ic|lvcreate}} コマンドを適応させます。 |
|||
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name. |
|||
必要であれば、スナップショットサイズを調整します。追加のファイルシステムをスナップショットする必要がある場合 |
|||
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted |
|||
起動時に {{ic|ExecStart}} プロパティを拡張して、lvcreate コマンドを追加することができます。 |
|||
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands, |
|||
{{ic| ; }} で区切られた (セミコロンの前後にスペースがあることに注意してください。詳しくは [https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines systemd サービスマニュアル] を参照してください)。 |
|||
{{Note|実行中のシステムで {{ic|lvcreate}} コマンドが思い通りに動くまでテストする必要があります。 |
|||
{{Note|You should test the {{ic|lvcreate}} command in the running system until it works as desired. |
|||
テスト用のスナップショットは {{ic|lvremove}} で削除してください。実行中のシステムから取得したスナップショットは、シングルユーザーモードや起動中に取得したスナップショットほど一貫性がありません。}} |
|||
Remove the test snapshots with {{ic|lvremove}}. The snapshots taken from a running system are not as consistent as snapshots taken in single user mode or during startup.}} |
|||
新しい systemd ターゲット {{ic|/etc/systemd/system/make-snapshots.target}} を作成します。 |
|||
{{bc|1= |
{{bc|1= |
||
| 53行目: | 53行目: | ||
}} |
}} |
||
{{ic|multi-user.target}} がデフォルトターゲットでない場合、ベースターゲットを適応させます。デスクトップに入りたい場合は、{{ic|graphical.target}} に変更する必要があります。 |
|||
Adapt the base target, if {{ic|multi-user.target}} is not your default target. If you want to get into your desktop, you need to change it to {{ic|graphical.target}}. |
|||
{{ic|mk-lvm-snapshots.service}} を [[有効化]] |
|||
新しいターゲットでシステムを起動すると、ローカルファイルシステムをマウントした直後に LVM snapshot(s) が作成されます。 |
|||
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems. |
|||
このターゲットで起動する [[GRUB]] メニューエントリを取得するには、{{ic|/boot/grub/custom.cfg}} をベースに作成します。 |
|||
{{ic|grub.cfg}} は通常のスタートアップ用エントリです。カーネルコマンドラインを拡張して、新しく起動する |
|||
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new |
|||
{{ic|make-snapshots.target}} |
{{ic|make-snapshots.target}} です。 |
||
{{bc|1= |
{{bc|1= |
||
| 73行目: | 73行目: | ||
}} |
}} |
||
{{ic|grub.cfg}} が変更された場合は、{{ic|custom.cfg}} を調整することを忘れないでください。 |
|||
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes. |
|||
この grub エントリでシステムを再起動すると、{{ic|lvs}} に新しく作成されたスナップショットが表示されるはずです。 |
|||
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot. |
|||
{{Tip| |
{{Tip|新しいサービスのメッセージを取得するには、root で {{ic|journalctl -u mk-lvm-snapshots.service}} を実行してください}} |
||
== |
== 使い方 == |
||
=== |
=== バックアップ === |
||
この機能を利用してシステムのフルバックアップを行うには、スナップショット作成ターゲットでシステムを再起動します。 |
|||
To use this functionality for a full system backup, restart your system with the snapshot creation target. |
|||
スナップショットボリューム (必要であればさらにボリューム) を、できれば読み込み専用 ({{ic|-o}}) オプションを使ってマウントしてください。 |
|||
Mount the snapshot volume (and further volumes, if required), preferably using the read only ({{ic|-o}}) option. |
|||
次に、例えば tar を使って、[[Tar によるフルシステムバックアップ]] で説明されているようにシステムをバックアップします。 |
|||
Then backup your system, for example with tar as described in [[Full system backup with tar]]. |
|||
バックアップ中は、通常のボリュームへの変更はすべて不可視なので、システムを通常通り使用し続けることができます。 |
|||
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in |
|||
スナップショット バックアップ後、スナップショットボリュームを削除することを忘れないでください。 |
|||
the snapshots. Do not forget to delete the snapshot volume after the backup – changes to your regular volume will |
|||
コピーオンライト操作により、スナップショットのスペースを使用します。スナップショット領域が完全に使用されるようになり、LVM |
|||
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM |
|||
が自動的にスナップショットを大きくすることができない場合、LVM は通常のボリュームへのさらなる書き込みを拒否するか、スナップショットを削除します。 |
|||
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the |
|||
snapshot, which should be avoided. |
|||
=== |
=== 更新を元に戻す === |
||
LVM スナップショットのもう1つの用途は、更新のテストと元に戻すことです。この場合、システムのスナップショットを作成します |
|||
Another use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system |
|||
既知の良好な状態で、後で更新または変更を実行します。 |
|||
in a known good state and perform updates or changes afterwards. |
|||
更新を永続的に保持したい場合は、''lvremove'' を使用してスナップショットを削除するだけです。スナップショットに戻したい場合 |
|||
If you want to permantly stick to the updates just drop the snapshot with ''lvremove''. If you want to revert to the snapshotted |
|||
スナップショットに対して {{ic|lvconvert--merge}} を発行します。システムの次回の再起動時(デフォルトのターゲットを使用)、スナップショット |
|||
state issue a {{ic|lvconvert --merge}} for the snapshot. During the next restart of the system (use the default target) the snapshot |
|||
通常のボリュームにマージされます。ボリュームへのすべての変更は、スナップショットが取り消された後に行われます。 |
|||
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone. |
|||
{{Note|マージ後、スナップショットは存在しなくなります。ロールバックでさらにテストする場合は、新しいスナップショットを再作成します。}} |
|||
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback |
|||
option is desired.}} |
|||
== |
== 既知の問題点 == |
||
{{Out of date|Linked report is from 2011, "currently" is August 2016. Is this still an issue? Either way, the systemd configuration should be moved to [[systemd]] as other programs may block shutdown, e.g. [https://github.com/systemd/systemd/issues/2691].}} |
{{Out of date|Linked report is from 2011, "currently" is August 2016. Is this still an issue? Either way, the systemd configuration should be moved to [[systemd]] as other programs may block shutdown, e.g. [https://github.com/systemd/systemd/issues/2691].}} |
||
[https://bugzilla.redhat.com/show_bug.cgi?id=681582 バグ 681582] により、アクティブなスナップショットを使用してシステムをシャットダウンするとスナップショットがしばらくハングすることがあります(現在1~3分)。回避策として、より短いジョブタイムアウトを設定することができます。 |
|||
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active |
|||
| ⚫ | |||
snapshots may hang for some time (currently 1...3 minutes). As a workaround a shorter job timeout can be set. |
|||
| ⚫ | |||
{{ic|1=JobTimeoutSec=10}}: |
{{ic|1=JobTimeoutSec=10}}: |
||
2022年2月14日 (月) 19:09時点における最新版
関連記事
この記事では、システム起動時にルートファイルシステムの LVM スナップショットを作成する設定方法について説明します。このようなスナップショットは、ダウンタイムを最小限に抑えた フルシステムバックアップ や、システムの更新をテストして元に戻すオプションに使用することができます。
必要なもの
LVM ルートファイルシステムと systemd を搭載したシステムが必要です。 LVM スナップショット の前提条件が正しく設定されていることを確認してください。
セットアップ
システムの起動時にルートボリュームのクリーンなスナップショットを作成するために systemd サービスを使用します。
/etc/systemd/system/mk-lvm-snapshots.service を作成します。
[Unit] Description=make LVM snapshots Requires=local-fs-pre.target Wants=local-fs.target DefaultDependencies=no Conflicts=shutdown.target After=local-fs-pre.target Before=local-fs.target [Install] WantedBy=make-snapshots.target [Service] Type=oneshot ExecStart=/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root
ルートボリュームグループとボリューム名に合わせて、lvcreate コマンドを適応させます。
必要であれば、スナップショットサイズを調整します。追加のファイルシステムをスナップショットする必要がある場合
起動時に ExecStart プロパティを拡張して、lvcreate コマンドを追加することができます。
; で区切られた (セミコロンの前後にスペースがあることに注意してください。詳しくは systemd サービスマニュアル を参照してください)。
lvcreate コマンドが思い通りに動くまでテストする必要があります。
テスト用のスナップショットは lvremove で削除してください。実行中のシステムから取得したスナップショットは、シングルユーザーモードや起動中に取得したスナップショットほど一貫性がありません。新しい systemd ターゲット /etc/systemd/system/make-snapshots.target を作成します。
[Unit] Description=Make Snapshots Requires=multi-user.target
multi-user.target がデフォルトターゲットでない場合、ベースターゲットを適応させます。デスクトップに入りたい場合は、graphical.target に変更する必要があります。
mk-lvm-snapshots.service を 有効化
新しいターゲットでシステムを起動すると、ローカルファイルシステムをマウントした直後に LVM snapshot(s) が作成されます。
このターゲットで起動する GRUB メニューエントリを取得するには、/boot/grub/custom.cfg をベースに作成します。
grub.cfg は通常のスタートアップ用エントリです。カーネルコマンドラインを拡張して、新しく起動する
make-snapshots.target です。
### make snapshots ###
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {
...
echo 'Loading Linux core repo kernel ...'
linux /boot/vmlinuz-linux root=/dev/lvmvolume/root ro systemd.unit=make-snapshots.target
echo 'Loading initial ramdisk ...'
initrd /boot/initramfs-linux.img
}
grub.cfg が変更された場合は、custom.cfg を調整することを忘れないでください。
この grub エントリでシステムを再起動すると、lvs に新しく作成されたスナップショットが表示されるはずです。
journalctl -u mk-lvm-snapshots.service を実行してください使い方
バックアップ
この機能を利用してシステムのフルバックアップを行うには、スナップショット作成ターゲットでシステムを再起動します。
スナップショットボリューム (必要であればさらにボリューム) を、できれば読み込み専用 (-o) オプションを使ってマウントしてください。
次に、例えば tar を使って、Tar によるフルシステムバックアップ で説明されているようにシステムをバックアップします。
バックアップ中は、通常のボリュームへの変更はすべて不可視なので、システムを通常通り使用し続けることができます。 スナップショット バックアップ後、スナップショットボリュームを削除することを忘れないでください。 コピーオンライト操作により、スナップショットのスペースを使用します。スナップショット領域が完全に使用されるようになり、LVM が自動的にスナップショットを大きくすることができない場合、LVM は通常のボリュームへのさらなる書き込みを拒否するか、スナップショットを削除します。
更新を元に戻す
LVM スナップショットのもう1つの用途は、更新のテストと元に戻すことです。この場合、システムのスナップショットを作成します 既知の良好な状態で、後で更新または変更を実行します。
更新を永続的に保持したい場合は、lvremove を使用してスナップショットを削除するだけです。スナップショットに戻したい場合
スナップショットに対して lvconvert--merge を発行します。システムの次回の再起動時(デフォルトのターゲットを使用)、スナップショット
通常のボリュームにマージされます。ボリュームへのすべての変更は、スナップショットが取り消された後に行われます。
既知の問題点
バグ 681582 により、アクティブなスナップショットを使用してシステムをシャットダウンするとスナップショットがしばらくハングすることがあります(現在1~3分)。回避策として、より短いジョブタイムアウトを設定することができます。
/usr/lib/systemd/system/dmeventd.service のコピーを /etc/systemd/system に作成し、以下のように挿入してください。
JobTimeoutSec=10:
[Unit] Description=Device-mapper event daemon Documentation=man:dmeventd(8) Requires=dmeventd.socket After=dmeventd.socket DefaultDependencies=no JobTimeoutSec=10 [Service] Type=forking ExecStart=/usr/sbin/dmeventd ExecReload=/usr/sbin/dmeventd -R Environment=SD_ACTIVATION=1 PIDFile=/run/dmeventd.pid OOMScoreAdjust=-1000