5-LVM逻辑卷管理
2016.6.13
LVM概述
1.PV(Physical Volume,物理卷)
1)pvscan命令
[root@test2 jason]# pvscan
PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free]
Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0 ]
[root@test2 jason]#
2) pvcreate命令
[root@test2 jason]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
dev_is_mpath: failed to get device for 8:19
dev_is_mpath: failed to get device for 8:19
Device /dev/sdb3 not found (or ignored by filtering).
原因分析,是sdb3是扩展分区
查看现有分区信息:
[root@test2 jason]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d0a36
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa8f24694
Device Boot Start End Blocks Id System
/dev/sdb1 1 2612 20980858+ 83 Linux
/dev/sdb2 2613 5224 20980890 83 Linux
/dev/sdb3 5225 10443 41921617+ 5 Extended
/dev/sdb5 5225 5486 2104483+ 82 Linux swap / Solaris
/dev/sdb6 5487 6792 10490413+ 83 Linux
Disk /dev/mapper/vg_jason-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_jason-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
重新分配sdb3
[root@test2 jason]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): t
Partition number (1-6): 3
Hex code (type L to list codes): 83
You cannot change a partition into an extended one or vice versa
Delete it first.
Command (m for help): d
Partition number (1-6): 3
Command (m for help): t
Partition number (1-4): 3
Partition 3 does not exist yet!
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (5225-10443, default 5225):
Using default value 5225
Last cylinder, +cylinders or +size{K,M,G} (5225-10443, default 10443):
Using default value 10443
Command (m for help): p
Disk /dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa8f24694
Device Boot Start End Blocks Id System
/dev/sdb1 1 2612 20980858+ 83 Linux
/dev/sdb2 2613 5224 20980890 83 Linux
/dev/sdb3 5225 10443 41921617+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
再次使用pvcreate命令:
[root@test2 jason]# pvcreate /dev/sdb1/ /dev/sd
sda sda1 sda2 sdb sdb1 sdb2 sdb3
[root@test2 jason]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
[root@test2 jason]#
3)pvdisplay命令
[root@test2 jason]# pvdisplay /dev/sdb3
"/dev/sdb3" is a new physical volume of "39.98 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 39.98 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID UB831l-dcjr-1uGK-ZZNQ-hw4Z-SMbf-2uXZUn
[root@test2 jason]# pvdisplay /dev/sdb1
"/dev/sdb1" is a new physical volume of "20.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 20.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID fvMlj2-a75t-dOui-Ye6o-VGCL-FWX2-JwQ1g2
4)pvremove命令
before remove:
[root@test2 jason]# pvscan
PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [20.01 GiB]
PV /dev/sdb2 lvm2 [20.01 GiB]
PV /dev/sdb3 lvm2 [39.98 GiB]
Total: 4 [99.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 3 [80.00 GiB]
[root@test2 jason]#
removing:
错误的命令:
[root@test2 jason]# remove /dev/sdb3
bash: remove: command not found
正确的命令
[root@test2 jason]# pvremove /dev/sdb3
Labels on physical volume "/dev/sdb3" successfully wiped
[root@test2 jason]#
after remove:
[root@test2 jason]# pvscan
PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [20.01 GiB]
PV /dev/sdb2 lvm2 [20.01 GiB]
Total: 3 [59.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 2 [40.02 GiB]
从这里可以看出来sdb3已经被移除
LVM的管理命令
1.PV物理卷管理
2.VG卷组管理
3.LV逻辑卷管理
功能 | PV管理命令 | VG管理命令 | LV管理命令 |
---|---|---|---|
Scan 扫描 | pvscan | vgscan | lvscan |
Create 建立 | pvcreate | vgcreate | lvcreate |
Display 显示 | pvdisplay | vgdisplay | lvdisplay |
Remove 移除 | pvremove | vgremove | lvremove |
Extend 扩展 | vgextend | lvextend | |
educe 减少 | vgreduce | lvreduce |