Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
6.3. 由 LVM 鏡像錯誤中復原
此部份提供了一個從「基於實體卷冊的基本裝置發生了錯誤所造成的 LVM 鏡像卷冊的 leg 錯誤」的情況下復原之範例。當一個鏡像 leg 發生錯誤時,LVM 便會將鏡像卷冊轉換為線性卷冊,它會和先前相同地繼續進行作業不過缺少鏡像的重複。在此情況下,您可新增一個新的磁碟裝置至系統,使用它來取代實體裝置並重建鏡像。
下列指令建立了將會使用於鏡像的實體卷冊。
[root@link-08 ~]# pvcreate /dev/sd[abcdefgh][12]
Physical volume "/dev/sda1" successfully created
Physical volume "/dev/sda2" successfully created
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdc2" successfully created
Physical volume "/dev/sdd1" successfully created
Physical volume "/dev/sdd2" successfully created
Physical volume "/dev/sde1" successfully created
Physical volume "/dev/sde2" successfully created
Physical volume "/dev/sdf1" successfully created
Physical volume "/dev/sdf2" successfully created
Physical volume "/dev/sdg1" successfully created
Physical volume "/dev/sdg2" successfully created
Physical volume "/dev/sdh1" successfully created
Physical volume "/dev/sdh2" successfully created
下列指令建立了卷冊群組
vg
和鏡像卷冊 groupfs
。
[root@link-08 ~]#vgcreate vg /dev/sd[abcdefgh][12]
Volume group "vg" successfully created [root@link-08 ~]#lvcreate -L 750M -n groupfs -m 1 vg /dev/sda1 /dev/sdb1 /dev/sdc1
Rounding up size to full physical extent 752.00 MB Logical volume "groupfs" created
您可使用
lvs
指令來驗證 mirror leg 和 mirror log 的基本裝置和鏡像卷冊的格式。請注意,在第一個範例中,鏡像還未完整同步化;您應等到 Copy%
這個欄位顯示了 100.00 之後才繼續進行。
[root@link-08 ~]#lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Devices groupfs vg mwi-a- 752.00M groupfs_mlog 21.28 groupfs_mimage_0(0),groupfs_mimage_1(0) [groupfs_mimage_0] vg iwi-ao 752.00M /dev/sda1(0) [groupfs_mimage_1] vg iwi-ao 752.00M /dev/sdb1(0) [groupfs_mlog] vg lwi-ao 4.00M /dev/sdc1(0) [root@link-08 ~]#lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Devices groupfs vg mwi-a- 752.00M groupfs_mlog 100.00 groupfs_mimage_0(0),groupfs_mimage_1(0) [groupfs_mimage_0] vg iwi-ao 752.00M /dev/sda1(0) [groupfs_mimage_1] vg iwi-ao 752.00M /dev/sdb1(0) [groupfs_mlog] vg lwi-ao 4.00M i /dev/sdc1(0)
在此範例中,
/dev/sda1
這個鏡像的主要 leg 發生了錯誤。任何寫入至鏡像卷冊的動作都會造成 LVM 偵測到錯誤的鏡像。當這情況發生時,LVM 會將鏡像轉換為單獨的線性卷冊。在此情況下,若要進行轉換的話,請執行 dd
這項指令
[root@link-08 ~]# dd if=/dev/zero of=/dev/vg/groupfs count=10
10+0 records in
10+0 records out
您可使用
lvs
指令來驗證裝置現在是否是個 linear 裝置。因為磁碟發生錯誤,因而產生了 I/O 錯誤。
[root@link-08 ~]# lvs -a -o +devices
/dev/sda1: read failed after 0 of 2048 at 0: Input/output error
/dev/sda2: read failed after 0 of 2048 at 0: Input/output error
LV VG Attr LSize Origin Snap% Move Log Copy% Devices
groupfs vg -wi-a- 752.00M /dev/sdb1(0)
在此情況下,您還是應該能使用邏輯卷冊,不過將不會有鏡像重複。
To rebuild the mirrored volume, you replace the broken drive and recreate the physical volume. If you use the same disk rather than replacing it with a new one, you will see "inconsistent" warnings when you run the
pvcreate
command.
[root@link-08 ~]#pvcreate /dev/sda[12]
Physical volume "/dev/sda1" successfully created Physical volume "/dev/sda2" successfully created [root@link-08 ~]#pvscan
PV /dev/sdb1 VG vg lvm2 [67.83 GB / 67.10 GB free] PV /dev/sdb2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sda1 lvm2 [603.94 GB] PV /dev/sda2 lvm2 [603.94 GB] Total: 16 [2.11 TB] / in use: 14 [949.65 GB] / in no VG: 2 [1.18 TB]
接下來請透過新的實體卷冊來延伸原始的卷冊群組。
[root@link-08 ~]#vgextend vg /dev/sda[12]
Volume group "vg" successfully extended [root@link-08 ~]#pvscan
PV /dev/sdb1 VG vg lvm2 [67.83 GB / 67.10 GB free] PV /dev/sdb2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sda1 VG vg lvm2 [603.93 GB / 603.93 GB free] PV /dev/sda2 VG vg lvm2 [603.93 GB / 603.93 GB free] Total: 16 [2.11 TB] / in use: 16 [2.11 TB] / in no VG: 0 [0 ]
將 linear 卷冊轉換回它原始的鏡像狀態。
[root@link-08 ~]# lvconvert -m 1 /dev/vg/groupfs /dev/sda1 /dev/sdb1 /dev/sdc1
Logical volume mirror converted.
您可使用
lvs
指令來驗證鏡像是否已被儲存。
[root@link-08 ~]# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Devices
groupfs vg mwi-a- 752.00M groupfs_mlog 68.62 groupfs_mimage_0(0),groupfs_mimage_1(0)
[groupfs_mimage_0] vg iwi-ao 752.00M /dev/sdb1(0)
[groupfs_mimage_1] vg iwi-ao 752.00M /dev/sda1(0)
[groupfs_mlog] vg lwi-ao 4.00M /dev/sdc1(0)