闲着没事,复习了LVM,做了些一般性的操作,记录下来,以前就是没有记录所以都忘记了。
LV建立流程:
1.建立PV
2.建立VG,将PV加入到VG中。
3.建立LV,并设置LV大小。
4.格式化LV或LP成你需要的文件系统。
LV删除流程:
1.umountFS
2.删除LV。
3.将PV从所在的VG中删除。
4.删除VG。
将其他一个VG中的PV分给另一个VG。
1.删除一个LV和VG
删除逻辑卷以前首先需要将其卸载,然后删除:
# umount /dev/vgtest2/lv_test2
# lvremove /dev/vgtest2/lv_test2
lvremove -- do you really want to remove " /dev/vgtest2/lv_test2"? [y/n]: y
lvremove -- doing automatic backup of volume group "web_document"
lvremove -- logical volume " /dev/vgtest2/lv_test2" successfully removed
[root@web4 lvtest]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_data_2 VolGroup00 -wi-ao 5.75G
lv_data_3 VolGroup00 -wi-ao 4.00G
lv_oracle VolGroup00 -wi-ao 9.03G
lv_swap VolGroup00 -wi-ao 1.00G
lv_system VolGroup00 -wi-ao 7.94G
lv_test vgtest -wi-ao 2.00G
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest2 lvm2 a- 5.00G 5.00G
应该先将 /dev/sdi 从vgtest2删除,因为做实验,VG中只有一个PV所以就直接删除了VG。
删除vgtest2
[root@web4 lvtest]# vgremove vgtest2
Volume group "vgtest2" successfully removed
[root@web4 lvtest]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 3 5 0 wz--n- 27.81G 96.00M
vgtest 1 1 0 wz--n- 5.00G 3.00G
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi lvm2 -- 5.00G 5.00G
/dev/sdi 已经没有VGTEST2的信息了
因为我没有把PV删除所以pvs里面还有/dev/sdi 的信息。
2.将PV /dev/sdi 分给VGTEST
[root@web4 lvtest]# vgextend vgtest /dev/sdi
Volume group "vgtest" successfully extended
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest lvm2 a- 5.00G 5.00G
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest lvm2 a- 5.00G 5.00G
[root@web4 lvtest]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 3 5 0 wz--n- 27.81G 96.00M
vgtest 2 1 0 wz--n- 9.99G 7.99G
vgtest 2 1 0 wz--n- 9.99G 7.99G
看出 VGTEST已经8G了 这两个PV都在VGTEST里面了。扩展LV跟FS。
刷新下
[root@web4 lvtest]# partprobe
[root@web4 lvtest]# lvextend -L+6G /dev/vgtest/lv_test
Extending logical volume lv_test to 8.00 GB
Logical volume lv_test successfully resized
[root@web4 lvtest]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 3 5 0 wz--n- 27.81G 96.00M
vgtest 2 1 0 wz--n- 9.99G 1.99G
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 0
/dev/sdi vgtest lvm2 a- 5.00G 1.99G
[root@web4 lvtest]# vgdisplay
--- Volume group ---
VG Name vgtest
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
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 9.99 GB
PE Size 4.00 MB
Total PE 2558
Alloc PE / Size 2048 / 8.00 GB
Free PE / Size 510 / 1.99 GB
VG UUID qujMHQ-lK0V-LtD2-5odd-8wyy-0ggz-dv5H2N
减小LV到2G的容量。减小2G的话使用-L-2G参数。
[root@web4 lvtest]# lvreduce -L2G /dev/vgtest/lv_test
WARNING: Reducing active and open logical volume to 2.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 2.00 GB
Logical volume lv_test successfully resized
[root@web4 lvtest]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_data_2 VolGroup00 -wi-ao 5.75G
lv_data_3 VolGroup00 -wi-ao 4.00G
lv_oracle VolGroup00 -wi-ao 9.03G
lv_swap VolGroup00 -wi-ao 1.00G
lv_system VolGroup00 -wi-ao 7.94G
lv_test vgtest -wi-ao 2.00G
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest lvm2 a- 5.00G 5.00G
[root@web4 lvtest]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 3 5 0 wz--n- 27.81G 96.00M
vgtest 2 1 0 wz--n- 9.99G 7.99G
将/dev/sdi从vgtest中删除。
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest lvm2 a- 5.00G 5.00G
[root@web4 lvtest]# vgreduce vgtest /dev/sdi
Removed "/dev/sdi" from volume group "vgtest"
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi lvm2 -- 5.00G 5.00G
把/dev/sdi加进vgtest中。
[root@web4 lvtest]# vgextend vgtest /dev/sdi
Volume group "vgtest" successfully extended
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest lvm2 a- 5.00G 5.00G
删除PV /dev/sdi
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi lvm2 -- 5.00G 5.00G
[root@web4 lvtest]# pvremove /dev/sdi
Labels on physical volume "/dev/sdi" successfully wiped
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
备份PV的数据从/dev/sdh移动到/dev/sdi上。
[root@web4 lvtest]# pvcreate /dev/sdi
Physical volume "/dev/sdi" successfully created
[root@web4 lvtest]# pvc
-bash: pvc: command not found
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi lvm2 -- 5.00G 5.00G
[root@web4 lvtest]# vgextend vgtest /dev/sdi
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "vgtest" successfully extended
[root@web4 lvtest]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 0
/dev/sdb1 VolGroup00 lvm2 a- 9.97G 96.00M
/dev/sdc1 VolGroup00 lvm2 a- 9.97G 0
/dev/sdh vgtest lvm2 a- 5.00G 3.00G
/dev/sdi vgtest lvm2 a- 5.00G 5.00G
[root@web4 lvtest]# pvmove -v /dev/sdh /dev/sdi
Finding volume group "vgtest"
Archiving volume group "vgtest" metadata (seqno 14).
Creating logical volume pvmove0
Moving 512 extents of logical volume vgtest/lv_test
Found volume group "vgtest"
Updating volume group metadata
Creating volume group backup "/etc/lvm/backup/vgtest" (seqno 15).
Found volume group "vgtest"
Found volume group "vgtest"
Suspending vgtest-lv_test (253:5) without device flush
Found volume group "vgtest"
Creating vgtest-pvmove0
Loading vgtest-pvmove0 table
Resuming vgtest-pvmove0 (253:6)
Found volume group "vgtest"
Loading vgtest-pvmove0 table
Suppressed vgtest-pvmove0 identical table reload.
Loading vgtest-lv_test table
Resuming vgtest-lv_test (253:5)
Checking progress every 15 seconds
/dev/sdh: Moved: 18.0%
/dev/sdh: Moved: 35.7%
/dev/sdh: Moved: 53.7%
/dev/sdh: Moved: 71.7%
/dev/sdh: Moved: 89.3%
/dev/sdh: Moved: 100.0%
Found volume group "vgtest"
Found volume group "vgtest"
Loading vgtest-lv_test table
Suspending vgtest-lv_test (253:5) without device flush
Suspending vgtest-pvmove0 (253:6) without device flush
Found volume group "vgtest"
Found volume group "vgtest"
Found volume group "vgtest"
Resuming vgtest-pvmove0 (253:6)
Found volume group "vgtest"
Resuming vgtest-lv_test (253:5)
Found volume group "vgtest"
Removing vgtest-pvmove0 (253:6)
Found volume group "vgtest"
Removing temporary pvmove LV
Writing out final volume group after pvmove
Creating volume group backup "/etc/lvm/backup/vgtest" (seqno 17).
原来/dev/sdh使用了2G的数据,现在都移动到/dev/sdi上了。在工作中如果一个PV损坏,可以将损坏PV中的数据移动到新添加的PV上。但是最好别坏!
[root@web4 lvtest]# pvdisplay
--- Physical volume ---
PV Name /dev/sdh
VG Name vgtest
PV Size 5.00 GB / not usable 4.00 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 1279
Free PE 1279
Allocated PE 0
PV UUID dP8Vxk-lRSh-Cymo-27tr-rhNg-dLgR-GT2ZJZ
--- Physical volume ---
PV Name /dev/sdi
VG Name vgtest
PV Size 5.00 GB / not usable 4.00 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 1279
Free PE 767
Allocated PE 512
PV UUID 4Dbbw4-EvXX-cb5H-sZrT-qdaK-xxC5-JkubU3
我在/lvtest/下做的pvmove,移动后访问的路径仍然在/lvtest/,不一样的只是PV被更换了,真奇妙。
阅读(864) | 评论(0) | 转发(0) |