LoginSignup
53
56

More than 5 years have passed since last update.

LVMでスナップショットの作成と状態の復元

Last updated at Posted at 2015-05-17

前回記事

LVMでRAID1の構築、障害対応、他RAIDボリュームの追加

スナップショットについて

ここでは、スナップショットがどのように便利なのか、そしてスナップショットをどのように作成、使用するかについて説明していきます。
ここでは、以下のようなスナップショットのユースケースを想定した使用方法について説明していきます。

一貫性のある状態の保持
スナップショット取得時点のデータの状態をそのまま保管するようなバックアップに使用することができます。
例えば毎日AM02:00 時点でDB データをスナップショットとして取得しておくことで、その日のAM02:00 時点のデータをそのままの状態でデータを保持しておくことができます。
スナップショットはオリジナルボリューム又は、スナップショットボリュームのいずれかが破損すると状態の復旧ができなくなるので、バックアップとは呼びづらい(個人的主観)
フェイルバック
何か処理を行って失敗した時にフェイルバックをする目的でスナップショットを取得しておくこともできます。
例えば、今まで問題なく動いていたのに、パッケージをアップグレードした途端に問題が発生した場合、スナップショットを取得していた時点に戻ることで、状態の切り戻しを行うことができます。

スナップショットはこれら以外にも用途はありますが、スナップショット用の論理ボリュームとオリジナルボリュームを分けて、ダウンタイムなしにバックアップの取得をすることができ、作業を止める必要がなくなります。

環境

今回スナップショットの動作確認を行う環境として、次のような環境を使用しています。


OS

Fedora21

ディスク
LVM でOS インストール済み
オリジナルデバイス
/dev/lv-test/original-volume (約16GB)
スナップショットデバイス
/dev/sdc1 (LVM の約1GB の領域)
# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               lvm-test
  PV Size               20.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               dVsuOL-GDdS-xVm1-rv6I-HeiK-bH1D-U7z86Z

# vgdisplay
  --- Volume group ---
  VG Name               lvm-test
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       5119 / 20.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               un2LXy-Jqiv-eea5-ymVf-0vOL-KCH6-6yNuIY

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/lvm-test/original
  LV Name                original
  VG Name                lvm-test
  LV UUID                yCNmOc-iZqq-0CIl-fA1Z-0omo-2boC-60IycV
  LV Write Access        read/write
  LV Creation host, time fedora-lvm01, 2015-03-21 19:10:48 +0900
  LV Status              available
  # open                 0
  LV Size                20.00 GiB
  Current LE             5119
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

# parted /dev/lvm-test/original 'print'
Model: Linux device-mapper (linear) (dm)
Disk /dev/dm-0: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  21.5GB  21.5GB  ext4

今回は/dev/lvm-test/original 論理デバイスのスナップショットをこれから作成する/dev/lvm-test/snap 上の論理デバイスに取得していきます。
lvm-test 論理ボリュームグループは空きのエクステントがないことが確認できます(Free PE /size 0 / 0)。
そのため、今回は物理デバイス/dev/sdc 上に物理ボリュームを作成し、lvm-test ボリュームグループに追加し、スナップショットボリュームを作成します。
なお、スナップショットを取得する場合は、スナップショットボリュームは同じグループでなければいけません。

スナップショットを有効的に使うためには、snapshot merge 機能があると、スナップショットからフェイルバックするときに非常に便利です。
確認するには、dmsetup targets コマンドを実行します。

# dmsetup targets
zero             v1.1.0
mirror           v1.13.2
snapshot-merge   v1.2.0
snapshot-origin  v1.8.1
snapshot         v1.12.0
striped          v1.5.1
linear           v1.2.1
error            v1.2.0

スナップショットボリュームの作成

まず、スナップショットの取得元となる/dev/lvm-test/original をマウントします。

# mkdir /mnt/{original,snap}
# mount /dev/lvm-test/original /mnt/original
# df -h 
Filesystem                      Size  Used Avail Use% Mounted on
/dev/sda3                        35G  1.5G   32G   5% /
devtmpfs                        2.0G     0  2.0G   0% /dev
tmpfs                           2.0G     0  2.0G   0% /dev/shm
tmpfs                           2.0G  532K  2.0G   1% /run
tmpfs                           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs                           2.0G  4.0K  2.0G   1% /tmp
/dev/sda1                       477M  113M  335M  26% /boot
tmpfs                           394M     0  394M   0% /run/user/1000
/dev/mapper/lvm--test-original   20G   44M   19G   1% /mnt/original

今回は/dev/sdc 物理デバイス上に/dev/lvm-test/snap 論理ボリュームを作成し、/dev/lvm-test/original 論理ボリュームのスナップショット領域を作成していきます。
あとでスナップショットの動きを確認しやすいように事前に次のコマンドを実行して、100MiB のテスト用のファイルをいくつか作成しておきます。

# mkdir /opt/lvm-test
# for I in {1..100}; do echo "dd if=/dev/urandom of=/mnt/original/file_"$(printf "%04d" ${I})" bs=$((1 * 1024)) count=$((1 * 1024 * 10))"; done | xargs -I{} -P 2 bash -c {}
.......
# ls -ltr /mnt/original | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100

今回、オリジナルの論理ボリュームの全体サイズは20GB ありますが、スナップショットボリュームはそれと同じサイズを作成する必要はありません。
オリジナルのボリューム内のデータの変更量によって、スナップショットボリュームの必要な容量は変わってくるので、完全なスナップショットボリュームに必要な容量を見積もることはここではできません。
とりあえず、1GB のスナップショットを作成していきます。

/dev/sdcにパーティションを作成する
# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +1G

Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

スナップショット用の物理ボリューム、論理ボリュームグループを作成します。

物理ボリュームの作成
# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               lvm-test
  PV Size               20.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               dVsuOL-GDdS-xVm1-rv6I-HeiK-bH1D-U7z86Z

  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               lvm-test
  PV Size               1.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              255
  Free PE               255
  Allocated PE          0
  PV UUID               MakOcI-ATCw-d23w-YI85-Mbzi-Qk2T-yvpjTO

論理ボリュームグループに追加
# vgextend lvm-test /dev/sdc1
  Volume group "lvm-test" successfully extended

# vgdisplay
  --- Volume group ---
  VG Name               lvm-test
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               20.99 GiB
  PE Size               4.00 MiB
  Total PE              5374
  Alloc PE / Size       5119 / 20.00 GiB
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               un2LXy-Jqiv-eea5-ymVf-0vOL-KCH6-6yNuIY

利用可能な領域が増えていることが確認できます(Free PE / Size 255 / 1020.00 MiB)。
なお、今回はfdisk コマンドでパーティションを作成するときにぴったり1G を指定したため、若干の誤差により1020MiB 分の領域のみ利用できます。
確実に1GiB のスナップショット領域が必要な場合は、パーティション作成時に少し余裕をもって確保するようにしてください。

新しく出来た空き領域を使用して、スナップショットボリュームを作成します。

現在の残り領域すべてをスナップショット領域として利用する
# lvcreate -s -l 100%FREE -n snap /dev/lvm-test/original
  Logical volume "snap" created.
明示的に1GBのスナップショット領域を取得する場合
# lvcreate -s -L 1G -n snap /dev/lvm-test/original

これでスナップショットが作成されました。
スナップショットの状態を確認してみます。

# lvscan
  ACTIVE   Original '/dev/lvm-test/original' [20.00 GiB] inherit
  ACTIVE   Snapshot '/dev/lvm-test/snap' [1020.00 MiB] inherit

# lvdisplay /dev/lvm-test/snap
  --- Logical volume ---
  LV Path                /dev/lvm-test/snap
  LV Name                snap
  VG Name                lvm-test
  LV UUID                TTD2tT-9DXp-kliH-gocI-rqGo-f5pt-TNge40
  LV Write Access        read/write
  LV Creation host, time fedora-lvm01, 2015-03-22 12:25:16 +0900
  LV snapshot status     active destination for original
  LV Status              available
  # open                 0
  LV Size                20.00 GiB
  Current LE             5119
  COW-table size         1020.00 MiB
  COW-table LE           255
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

スナップショットボリュームをマウントして、内容を確認してみます。

# mount -o ro /dev/lvm-test/snap /mnt/snap

# df /mnt/original /mnt/snap
Filesystem                     1K-blocks     Used Available Use% Mounted on
/dev/mapper/lvm--test-original  20507260 10285196   9157312  53% /mnt/original
/dev/mapper/lvm--test-snap      20507260 10285196   9157312  53% /mnt/snap

# ls -ltr /mnt/original/ | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100

# ls -ltr /mnt/snap | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100

スナップショットがどのように使用されるか、original 論理ボリューム上にファイルを書き込んで確認してみます。

# dd if=/dev/urandom of=/mnt/original/dummy01 bs=1024 count=$((1 * 1024 * 100))
102400+0 records in
102400+0 records out
104857600 bytes (105 MB) copied, 5.74177 s, 18.3 MB/s

ファイルを書き込んだら、また両方のボリュームを確認してみます。

# df /mnt/original /mnt/snap
Filesystem                     1K-blocks     Used Available Use% Mounted on
/dev/mapper/lvm--test-original  20507260 10387596   9054912  54% /mnt/original
/dev/mapper/lvm--test-snap      20507260 10285196   9157312  53% /mnt/snap

# ls -ltr /mnt/original/ | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100
-rw-r--r--. 1 root root 104857600 Mar 22 12:36 dummy01

# ls -ltr /mnt/snap | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100

上記のように、original 側はファイルが追加されていますが、snap 側のスナップショットボリュームについては変化していないことがわかります。
次にlvdisplay で論理ボリュームの状態を確認してみましょう。

# lvdisplay /dev/lvm-test/snap
  --- Logical volume ---
  LV Path                /dev/lvm-test/snap
  LV Name                snap
  VG Name                lvm-test
  LV UUID                TTD2tT-9DXp-kliH-gocI-rqGo-f5pt-TNge40
  LV Write Access        read/write
  LV Creation host, time fedora-lvm01, 2015-03-22 12:25:16 +0900
  LV snapshot status     active destination for original
  LV Status              available
  # open                 1
  LV Size                20.00 GiB
  Current LE             5119
  COW-table size         1020.00 MiB
  COW-table LE           255
  Allocated to snapshot  9.85%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

そうすると、Allocated to snapshot の値が増えていることがわかります。
ボリュームの元の状態を保持するために利用されています。
次に、original 側のファイルを削除してみます。

# rm /mnt/original/file_0100

# ls -ltr /mnt/original/ | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 22 12:36 dummy01

# ls -ltr /mnt/snap | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100

# lvdisplay /dev/lvm-test/snap
  --- Logical volume ---
  LV Path                /dev/lvm-test/snap
  LV Name                snap
  VG Name                lvm-test
  LV UUID                TTD2tT-9DXp-kliH-gocI-rqGo-f5pt-TNge40
  LV Write Access        read/write
  LV Creation host, time fedora-lvm01, 2015-03-22 12:25:16 +0900
  LV snapshot status     active destination for original
  LV Status              available
  # open                 1
  LV Size                20.00 GiB
  Current LE             5119
  COW-table size         1020.00 MiB
  COW-table LE           255
  Allocated to snapshot  9.86%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

削除時も、元の状態を保持するためにスナップショット領域が利用されていますが、削除処理によってファイルのデータ部分すべてが書き換わるわけではないので、このようになります。

スナップショットから復元する

スナップショットからオリジナルボリュームの状態をフェイルバックするには、lvconvert コマンドを使用します。
まず、オリジナルボリュームとスナップショットボリュームがマウントされている場合は、アンマウントしておきます。

# umount /mnt/original 
# umount /mnt/snap

lvconvert コマンドを実行して、フェイルバックします。
なお、このコマンドを実行することで/dev/lvm-test/snap スナップショットボリュームは削除されます。

# lvconvert --merge /dev/lvm-test/snap
  Merging of volume snap started.
  original: Merged: 90.2%
  original: Merged: 100.0%
  Merge of snapshot into logical volume original has finished.
  Logical volume "snap" successfully removed

フェイルバックが完了したら、オリジナルボリュームを確認してみましょう。

# mount /dev/lvm-test/original /mnt/original
# ls -ltr /mnt/original/ | tail
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0091
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0092
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0093
-rw-r--r--. 1 root root 104857600 Mar 21 19:28 file_0094
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0095
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0096
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0097
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0098
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0099
-rw-r--r--. 1 root root 104857600 Mar 21 19:29 file_0100

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/lvm-test/original
  LV Name                original
  VG Name                lvm-test
  LV UUID                yCNmOc-iZqq-0CIl-fA1Z-0omo-2boC-60IycV
  LV Write Access        read/write
  LV Creation host, time fedora-lvm01, 2015-03-21 19:10:48 +0900
  LV Status              available
  # open                 1
  LV Size                20.00 GiB
  Current LE             5119
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

オリジナルボリュームが元の状態になっており、スナップショットボリュームも削除されています。

スナップショットが溢れるケース

オリジナルボリュームに書き込みが大量発生し、スナップショットがあふれるケースについて見てみましょう。
先ほど、オリジナルボリュームに100MiB のダミーファイルを作成した後のスナップショット領域の使用率は約10% となっていました。

# lvdisplay /dev/lvm-test/snap
  --- Logical volume ---
......
  COW-table size         1020.00 MiB
  COW-table LE           255
  Allocated to snapshot  9.86%
  Snapshot chunk size    4.00 KiB
......

このまま、オリジナルボリュームに追加で100MiB * 10程度のファイルを書き込んでみます。

# lvscan
  ACTIVE   Original '/dev/lvm-test/original' [20.00 GiB] inherit
  ACTIVE   Snapshot '/dev/lvm-test/snap' [1020.00 MiB] inherit

# for I in {1..10}; do dd if#/dev/urandom of=/mnt/original/overflow_"$(printf "%04d" ${I})" bs=$((1 * 1024)) count$((1 * 1024 * 100)); done

状態を確認してみます。

# lvscan
  ACTIVE   Original '/dev/lvm-test/original' [20.00 GiB] inherit
  inactive Snapshot '/dev/lvm-test/snap' [1020.00 MiB] inherit

変更状態を保持しきれなくなったスナップショット領域がinactive になっていることがわかります。
この状態で、スナップショットからオリジナルボリュームをフェイルバックしようとするとどのようになるでしょうか。

# umount /mnt/original
# umount /mnt/snap
umount: /mnt/snap: not mounted

# lvconvert --merge /dev/lvm-test/snap
  Unable to merge invalidated snapshot LV "snap".
  Unable to merge LV "snap" into its origin.

上記のように、スナップショットからフェイルバックすることができないようになっていることがわかります。

このような状態になったら、元の状態の復元はあきらめてください・・・・・・。
使い道のなくなったスナップショットは削除しましょう。
使い道のなくなったスナップショットを削除するには、lvremove コマンドを使用します。

# lvremove /dev/lvm-test/snap

次の記事

Linuxインストール時にLVM on RAID1 な環境を構築する

53
56
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
56