LVM创建的流程: PV-->VG-->LV.
PV(Physical Volume) :物理卷,可以是单独磁盘,也可以是硬盘分区。
VG(Volume Group) :卷组,是PV的组合,可以看成单独的逻辑磁盘。
LV(Logical Volume) :逻辑分区,当于物理分区的/dev/hdaX,只有逻辑卷才可以写数据。
1:创建磁盘分区
[root@rhel5 ~]# fdisk -l #查看系统中当前的磁盘
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 6 48163+ 83 Linux
/dev/sda2 7 515 4088542+ 83 Linux
/dev/sda3 516 2356 14787832+ 83 Linux
/dev/sda4 2357 2610 2040255 5 Extended
/dev/sda5 2357 2610 2040223+ 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 83 Linux
/dev/sdb2 38 99 498015 5 Extended
2:使用命令fdisk /dev/sdb 创建出两个分区/dev/sdb5 /dev/sdb6,各为100M
[root@rhel5 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 6 48163+ 83 Linux
/dev/sda2 7 515 4088542+ 83 Linux
/dev/sda3 516 2356 14787832+ 83 Linux
/dev/sda4 2357 2610 2040255 5 Extended
/dev/sda5 2357 2610 2040223+ 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 83 Linux
/dev/sdb2 38 99 498015 5 Extended
/dev/sdb5 38 50 104391 83 Linux
/dev/sdb6 51 63 104391 83 Linux
[root@rhel5 mnt]# partprobe #执行partprobe使分区表生效
3:利用刚刚创建的分区来创建PV
[root@rhel5 ~]# pvcreate /dev/sdb5
Physical volume "/dev/sdb5" successfully created
[root@rhel5 ~]# pvcreate /dev/sdb6
Physical volume "/dev/sdb6" successfully created
[root@rhel5 ~]# pvscan #扫描PV
PV /dev/sdb5 lvm2 [101.94 MB]
PV /dev/sdb6 lvm2 [101.94 MB]
Total: 2 [203.89 MB] / in use: 0 [0 ] / in no VG: 2 [203.89 MB]
[root@rhel5 ~]# pvdisplay #查看创建好的PV的详细信息
--- NEW Physical volume ---
PV Name /dev/sdb5
VG Name
PV Size 101.94 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID YASLH1-FyGQ-AJKz-Ik4h-H4NG-XLUw-sc7Fyx
--- NEW Physical volume ---
PV Name /dev/sdb6
VG Name
PV Size 101.94 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID iPEY0d-JpT6-UuKz-0Bte-DBQF-7lrM-NnKm1u
4:创建VG
[root@rhel5 ~]# vgcreate vg1 /dev/sdb5 /dev/sdb6 #利用现有的PV创建VG ,VG名是vg1
Volume group "vg1" successfully created
[root@rhel5 ~]# vgdisplay #查看卷组信息
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 200.00 MB
PE Size 4.00 MB
Total PE 50
Alloc PE / Size 0 / 0
Free PE / Size 50 / 200.00 MB
VG UUID 08WljC-W0J4-wPB5-5NEY-ttLT-1wgO-TWa8dY
5:创建逻辑卷lvm1
[root@rhel5 ~]# lvcreate -L 100M -n lvm1 /dev/vg1 #创建逻辑卷lvm1 ,-L指定大小100M, -n 指定逻辑卷名为lvm1
/dev/cdrom: open failed: Read-only file system
Logical volume "lvm1" created
[root@rhel5 ~]# lvdisplay #查看逻辑卷是否创建成功
--- Logical volume ---
LV Name /dev/vg1/lvm1
VG Name vg1
LV UUID 2MntF2-QRj1-MxEk-S30r-v55v-CjJO-KTqL67
LV Write Access read/write
LV Status available
# open 0
LV Size 100.00 MB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
6:格式化逻辑卷,并挂载
[root@rhel5 ~]# mkfs -t ext3 /dev/vg1/lvm1 #以ext3的格式来格式化lvm1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@rhel5 ~]# mount /dev/vg1/lvm1 /mnt #挂载lvm1到 /mnt目录
[root@rhel5 mnt]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext3 3960348 2523512 1232412 68% /
/dev/sda1 ext3 46633 14775 29450 34% /boot
tmpfs tmpfs 517700 0 517700 0% /dev/shm
/dev/mapper/vg1-lvm1
ext3 99150 5664 88366 7% /mnt
如上所示,已经挂载成功,可以使用啦