(none):/ # vgchange -an test
Volume group test metadata is inconsistent
Volume group for uuid not found:
tcyuXvjcxCN7912qAJlEYzphncdWabTJ21OTTrG6DrMS8dPF5Wlh04GOHyO5ClbY
1 logical volume(s) in volume group "test" now active
* 即报告 vg 的 metadata 不一致
* 重新启动系统
(none):~ # vgchange -an test
0 logical volume(s) in volume group "test" now active
(none):~ # vgchange -ay test
1 logical volume(s) in volume group "test" now active
已不存在该问题,这时候 /etc/lvm/backup 也已经更新了。
之后尝试 mount
清单 13. 重新挂载
(none):~ # mount /dev/test/lv0 /test
mount: you must specify the filesystem type
由 LVM 产生的硬件重定位:更高层次的重定位,LVM 将有问题的物理地址 A 上的数据拷贝到物理地址 B,LVM 会继续读地址 A 上的数据,但是硬盘已经将真实的 IO 转向物理地址 B。
软件重定位:最高层次的重定位,也由 LVM 设备产生。LVM 生成一个坏道表,当读物理地址 A 上的数据时,先检查坏道表,如果 A 在坏道表中,就转向物理地址 B。
但以上这些,其实对用户都是透明的,用户可以在创建 lv 时通过 lvcreate – r n
参数关闭这样,系统将不创建坏块重定位区域(BBRA),引导、根和主交换逻辑卷必须使用此参数。当用户觉得 LVM
有问题的时候,首先要做的事情就是备份,尽可能地保存卷组中的数据。卷组发生问题后进行的备份需要和发生问题前进行的备份进行对比。针对存在坏道的情
况,fsck 一定要慎用,尤其对于重定位已经无法处理的应尽快将硬盘导出(操作见 3.3 磁盘位置更改部分)LVM
以防坏道扩散,如在导出过程中出现问题,请比照 3.4 磁盘损坏处理。
磁盘位置更改
主板端口损坏、更欢 PC 主板、添加新的设备都可能导致磁盘位置更改的发生。由于 Linux
的主引导记录(MBR)一般记录在第一块磁盘的第一个扇区上,如果第一块磁盘的顺序发生改变,会导致系统无法启动。对于这种情况,只需要调整磁盘顺序就可
以解决(只需要保证有 MBR
的磁盘排在第一顺位就可以,不一定是总线的第一个端口)。这里讨论两种比较常见的情况,磁盘在系统内位置更改和磁盘在系统间移动。 磁盘在系统内移动
对于单一卷组的 LVM 文件系统而言,LVM 能够自动识别出磁盘位置的更改。磁盘位置更改后,正常启动系统就可以正常访问了。当系统中存在单独的卷组,或者系统中存在多个卷组是,更改磁盘位置前需要停用卷组,在完成磁盘移动后需要重新激活卷组,执行操作如下:
清单 15. 重新激活卷组
* 停用卷组:
Linux:~# vgchange – a n /dev/system
0 logical volume(s) in volume group “system” now active
Linux:~#lvscan
Inactive '/dev/system/test'[1.90 GB] inherit
* 激活卷组:
Linux:~# vgchange – a n /dev/system
1 logical volume(s) in volume group “system” now active
Linux:~#lvscan
ACTIVE '/dev/system/test'[1.90 GB] inherit
* 停用卷组:
Linux:~# vgchange – a n /dev/system
0 logical volume(s) in volume group “system” now active
* 导出卷组
Linux:~# vgexport /dev/system
Volume group “system” successfully exported
此时就可以将磁盘移动到其他系统。
清单 17. 导入并激活卷组
* 扫描 PV
Linux:~# pvscan
PV /dev/sdc is in exported VG system [2.00 GB / 96.00 MB free]
Total: 1 [2.00 GB] / in use: 1 [2.00 GB] / in no VG: 0[0 ]
* 导入 VG
Linux:~# vgimport /dev/system
Volume group “system” successfully imported
* 激活卷组
Linux:~# vgchange – a n /dev/system
1 logical volume(s) in volume group “system” now active
… ..
Reading all physical volumes. This may take a while …
Couldn' t find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy ' .
Couldn' t find all physical volumes for volume group system.
Couldn' t find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy' .
Couldn' t find all physical volumes for volume group system.
Volume group “system” not found
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy' .
Couldn't find all physical volumes for volume group system.
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy' .
Couldn't find all physical volumes for volume group system.
.not found -- exiting to /bin/sh
Rescue:~#lvscan
Reading all physical volumes. This may take a while …
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Couldn't find all physical volumes for volume group system.
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Couldn't find all physical volumes for volume group system.
Volume group “system” not found
Rescue:~#pvscan
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
PV /dev/sda2 VG system lvm2 [7.93 GB / 0 free]
PV unknown VG system lvm2 [2.00 GB / 2.00 GB free]
Total: 2 [9.92 GB] / in use: 2 [9.92 GB] / in no VG: 0 [0 ]
Rescue:~#vgreduce – removemissing system
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Couldn't find all physical volumes for volume group system.
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Couldn't find all physical volumes for volume group system.
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Couldn't find device with uuid 'wWnmiu-IdIw-K1P6-u10C-A4j1-LQSZ-c08RDy'.
Wrote out consistent volume group system
Rescue:~#vgscan
Reading all physical volumes. This may take a while …
Found volume group “system” using metadata type lvm2
Rescue:~#pvscan
PV /dev/sda2 VG system lvm2 [7.93 GB / 0 free]
Total: 1 [7.93 GB] / in use: 1 [7.93 GB] / in no VG: 0 [0 ]