操作系统基于Centos 6.5
Linux ***** 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
一.
PV(physical volume)即物理卷,就是物理磁盘,可以通过fdisk -l 查看操作系统有几块硬盘
VG(volume group)即卷组,就是一组物理磁盘的组合,里面可以有一块硬盘也可以有多块硬盘
LV(logical volume)及逻辑卷,就是在VG(指定的物理磁盘组)里面划分出来的
可以说成是PV就是硬盘,而VG就是管理硬盘的操作系统,而LV就是操作系统分出来的各个分区.
PV->VG->LV-> 文件系统使用(挂载到某个目录)
二.命令集合
1.PV
pvcreate :根据物理盘,创建pv
pvscan :查询目前系统里的pv
pvdisplay:显示pv的状态
pvremove:将pv属性移除
2.VG
vgcreate:创建vg
vgscan:查找当前系统里面的vg
vgdisplay:显示当前系统vg的状态
vgextend:给vg添加额外的pv
vgreduce:在vg内删除pv
vgchange:设置vg是否是启动状态(active)
vgremove:删除一个vg
3.LV
lvcreate:创建lv
lvscan:查询当前系统的lv
lvdisplay:显示lv的属性
lvextend:给lv添加容量
lvredurce:给lv减少容量
lvremove:删除一个lv
lvresize:对lv大小的容量进行调整
三.实际操作
下面实际操作下,来看看
1.从下看到只是把sda这块硬盘用了,做了vg(vg_dsgdata),并且在vg(vg_dsgdata)下建了/dev/vg_dsgdata/lv_root, /dev/vg_dsgdata/lv_swap, /dev/vg_dsgdata/lv_home三个lv, 通过df -h看到/dev/mapper/vg_dsgdata-lv_root挂载在根目录/下,/dev/mapper/vg_dsgdata-lv_home挂载在/home目录下.从上述看,还剩余sdb,sdc,sdd三块硬盘没有使用
[root@dsgdata ~]# fdisk -l
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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/sdd: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 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: 0x000a2d9e
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 121602 976248832 8e Linux LVM
Disk /dev/mapper/vg_dsgdata-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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_dsgdata-lv_swap: 8355 MB, 8355053568 bytes
255 heads, 63 sectors/track, 1015 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_dsgdata-lv_home: 937.6 GB, 937632464896 bytes
255 heads, 63 sectors/track, 113993 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
[root@dsgdata ~]#
[root@dsgdata ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_dsgdata
PV Size 931.02 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 238341
Free PE 0
Allocated PE 238341
PV UUID lPOKfO-HZ6y-4ubK-5TPk-FuB0-ypCU-y0mK1R
[root@dsgdata ~]#
[root@dsgdata ~]# vgdisplay
--- Volume group ---
VG Name vg_dsgdata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 931.02 GiB
PE Size 4.00 MiB
Total PE 238341
Alloc PE / Size 238341 / 931.02 GiB
Free PE / Size 0 / 0
VG UUID zQcZh0-2t6e-9LuM-zHnv-R0tG-sQDi-Ba3wLK
[root@dsgdata ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_dsgdata/lv_root
LV Name lv_root
VG Name vg_dsgdata
LV UUID D7Z7jC-v0aK-fYJ5-AbcN-LmjX-nMEJ-dwpcm0
LV Write Access read/write
LV Creation host, time dsgdata, 2014-03-05 17:59:43 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_dsgdata/lv_swap
LV Name lv_swap
VG Name vg_dsgdata
LV UUID 0HrVlq-IS9g-hNH0-R1Sr-hvcd-BUI2-hkjfLh
LV Write Access read/write
LV Creation host, time dsgdata, 2014-03-05 18:00:00 +0800
LV Status available
# open 1
LV Size 7.78 GiB
Current LE 1992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/vg_dsgdata/lv_home
LV Name lv_home
VG Name vg_dsgdata
LV UUID PC4IMN-Nvm3-UpaB-Em5I-NCvq-fzPF-MKcqOs
LV Write Access read/write
LV Creation host, time dsgdata, 2014-03-05 18:00:01 +0800
LV Status available
# open 1
LV Size 873.24 GiB
Current LE 223549
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
[root@dsgdata ~]#
[root@dsgdata ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_dsgdata-lv_root 50G 4.4G 43G 10% /
tmpfs 3.9G 228K 3.9G 1% /dev/shm
/dev/sda1 485M 40M 420M 9% /boot
/dev/mapper/vg_dsgdata-lv_home 860G 200M 816G 1% /home
[root@dsgdata ~]#
2.下面手工操作,创建增加减少删除关于pv,vg,lv的操作
创建pv
[root@dsgdata /]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
[root@dsgdata /]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_dsgdata
PV Size 931.02 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 238341
Free PE 0
Allocated PE 238341
PV UUID lPOKfO-HZ6y-4ubK-5TPk-FuB0-ypCU-y0mK1R
"/dev/sdb" is a new physical volume of "931.51 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 931.51 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID MO29Sj-3lEd-Licp-BNxD-9qPH-v5y4-zLUNHI
[root@dsgdata /]# pvscan
PV /dev/sda2 VG vg_dsgdata lvm2 [931.02 GiB / 0 free]
PV /dev/sdb lvm2 [931.51 GiB]
Total: 2 [1.82 TiB] / in use: 1 [931.02 GiB] / in no VG: 1 [931.51 GiB]
[root@dsgdata /]#
[root@dsgdata /]# pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wiped
[root@dsgdata /]# pvscan
PV /dev/sda2 VG vg_dsgdata lvm2 [931.02 GiB / 0 free]
Total: 1 [931.02 GiB] / in use: 1 [931.02 GiB] / in no VG: 0 [0 ]<pre code_snippet_id="220533" snippet_file_name="blog_20140306_6_5401133" class="html" name="code">[root@dsgdata /]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
3.创建VG
[root@dsgdata /]# vgcreate DATA /dev/sdb
Volume group “DATA” successfully created
[root@dsgdata /]#
[root@dsgdata /]# vgdisplay DATA
— Volume group — VG Name DATA System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size 931.51 GiB PE Size 4.00 MiB Total PE 238467 Alloc PE / Size 0 / 0 Free PE / Size 238467 / 931.51 GiB VG UUID HhP6O7-sjLT-xzA7-YqLl-QsOJ-lQSM-3sN5VS
[root@dsgdata /]#
给VG添加或者减少容量:
[root@dsgdata /]# pvcreate /dev/sdc Physical volume “/dev/sdc”
successfully created
[root@dsgdata /]# vgextend DATA /dev/sdc
Volume group “DATA” successfully extended
[root@dsgdata /]# vgdisplay DATA
— Volume group — VG Name DATA System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 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 1.82 TiB PE Size 4.00 MiB Total PE 476934 Alloc PE / Size 0 / 0 Free PE / Size 476934 / 1.82 TiB VG UUID HhP6O7-sjLT-xzA7-YqLl-QsOJ-lQSM-3sN5VS
[root@dsgdata /]# vgreduce DATA /dev/sdc
Removed “/dev/sdc” from volume group “DATA”
[root@dsgdata /]# vgdisplay DATA
— Volume group — VG Name DATA System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 931.51 GiB PE Size 4.00 MiB Total PE 238467 Alloc PE / Size 0 / 0 Free PE / Size 238467 / 931.51 GiB VG UUID HhP6O7-sjLT-xzA7-YqLl-QsOJ-lQSM-3sN5VS
[root@dsgdata /]#
4.创建LV,并挂载
[root@dsgdata /]# lvscan
ACTIVE ‘/dev/vg_dsgdata/lv_root’ [50.00 GiB] inherit
ACTIVE ‘/dev/vg_dsgdata/lv_swap’ [7.78 GiB] inherit
ACTIVE ‘/dev/vg_dsgdata/lv_home’ [873.24 GiB] inherit
[root@dsgdata /]# lvcreate -n test -L 100G DATA
Logical volume “test” created
[root@dsgdata /]# lvscan ACTIVE
‘/dev/DATA/test’ [100.00 GiB] inherit ACTIVE
‘/dev/vg_dsgdata/lv_root’ [50.00 GiB] inherit ACTIVE
‘/dev/vg_dsgdata/lv_swap’ [7.78 GiB] inherit ACTIVE
‘/dev/vg_dsgdata/lv_home’ [873.24 GiB] inherit
[root@dsgdata /]#
在根目录下创建目录CXF
[root@dsgdata /]# mkdir /cxf
对逻辑卷进行格式化:
[root@dsgdata /]# mkfs -t ext4 /dev/DATA/test
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872</p><p>Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done</p><p>This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@dsgdata /]#
将逻辑卷/dev/DATA/test挂载到/cxf目录下:
[root@dsgdata /]# mount /dev/DATA/test /cxf
[root@dsgdata /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_dsgdata-lv_root 50G 4.4G 43G 10% /
tmpfs 3.9G 228K 3.9G 1% /dev/shm
/dev/sda1 485M 40M 420M 9% /boot
/dev/mapper/vg_dsgdata-lv_home 860G 200M 816G 1% /home
/dev/mapper/DATA-test 99G 188M 94G 1% /cxf
[root@dsgdata /]#