添加 | 删除 | 显示 | |
物理卷 | pvcreat /dev/sdb1 | pvremove /dev/sdb1 | pvdisplay |
卷组 | vgcreat jvname /dev/sdb1 | vgremove jvname | vgdisplay |
逻辑卷 | lvcreat -L +1G -n lvname jvname | lvremove /dev/www/lvname | lvdisplay |
这是没处理之前磁盘的物理磁盘的使用情况:df -h
[root@centos pvdisplay]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
7.5G 1.0G 6.1G 15% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 485M 30M 430M 7% /boot
第一步:添加一个物理卷 pvcreate /dev/sdb1
[root@centos pvdisplay]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
查看一下所有物理卷的信息 pvdisplay
[root@centos pvdisplay]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_centos
PV Size 9.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2434
Free PE 0
Allocated PE 2434
PV UUID WMKyhq-sO0l-LTD2-q5nJ-YJMr-V9Qi-IzW6E3
"/dev/sdb1" is a new physical volume of "4.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 4.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID N77bvS-14vz-hu2c-2WZg-cHqY-evh0-4JTi1Q
第二步:添加一个卷组 vgcreate www /dev/sdb1
[root@centos pvdisplay]# vgcreate www /dev/sdb1
Volume group "www" successfully created
查看一下所有卷组的信息 vgdisplay
[root@centos pvdisplay]# vgdisplay
--- Volume group ---
VG Name www
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 4.99 GiB
PE Size 4.00 MiB
Total PE 1278
Alloc PE / Size 0 / 0
Free PE / Size 1278 / 4.99 GiB
VG UUID GMB8rP-v0Ti-Ywxh-BG2O-kDMv-udpe-yJEpbd
--- Volume group ---
VG Name vg_centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 9.51 GiB
PE Size 4.00 MiB
Total PE 2434
Alloc PE / Size 2434 / 9.51 GiB
Free PE / Size 0 / 0
VG UUID Jz4eJf-7ZKl-Bqr7-J1zz-Kxh8-nK37-5S8XFb
第三步:添加一个逻辑盘 lvcreate -L 1G -n a1 www
[root@centos pvdisplay]# lvdisplay
--- Logical volume ---
LV Path /dev/www/a1
LV Name a1
VG Name www
LV UUID CFumjL-D7ID-Mr8H-iqvS-E6vq-D0On-A263UE
LV Write Access read/write
LV Creation host, time centos, 2013-06-16 00:59:31 +0800
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg_centos/lv_root
LV Name lv_root
VG Name vg_centos
LV UUID BrFp1R-bqOU-pU4u-GnCq-3oXF-zz20-7fMckJ
LV Write Access read/write
LV Creation host, time centos, 2013-06-12 08:43:55 +0800
LV Status available
# open 1
LV Size 7.54 GiB
Current LE 1930
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_centos/lv_swap
LV Name lv_swap
VG Name vg_centos
LV UUID G3vVUl-cxHH-vOYt-Vhg7-T2S5-99QX-V1zVKf
LV Write Access read/write
LV Creation host, time centos, 2013-06-12 08:44:07 +0800
LV Status available
# open 1
LV Size 1.97 GiB
Current LE 504
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
第四步:格式化逻辑卷/给逻辑卷指定文件系统 mke2fs -j /dev/www/a1
[root@centos pvdisplay]# mke2fs -j /dev/www/a1
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
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
第五步:挂载上去来使用 mount /dev/www/a1 /root/pvdisplay/
[root@centos pvdisplay]# mount /dev/www/a1 /root/pvdisplay/
现在再查一下磁盘使用情况 df -h
[root@centos pvdisplay]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
7.5G 1.1G 6.1G 15% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 485M 30M 430M 7% /boot
/dev/mapper/www-a1 1008M 34M 924M 4% /root/pvdisplay
第六步:增加磁盘容量(这是LVM的优势所在)
增加逻辑卷的大小: lvextend -L +2G /dev/www/a1
[root@centos pvdisplay]# lvextend -L +2G /dev/www/a1
Extending logical volume a1 to 3.00 GiB
Logical volume a1 successfully resized
使其生效,很重要的一步
resize2fs - ext2/ext3/ext4文件系统重定义大小工具
resize2fs /dev/www/a1
[root@centos pvdisplay]# resize2fs /dev/www/a1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/www/a1 is mounted on /root/pvdisplay; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/www/a1 to 786432 (4k) blocks.
The filesystem on /dev/www/a1 is now 786432 blocks long.
现在再看看磁盘使用情况 df -h
[root@centos pvdisplay]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
7.5G 1.1G 6.1G 15% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 485M 30M 430M 7% /boot
/dev/mapper/www-a1 3.0G 34M 2.8G 2% /root/pvdisplay
第六步:如果想卸载,过程必须倒过来
umount /dev/www/a1 第一步,卸载,停止使用
lvremove /dev/www/a1 第二步,删除逻辑卷
vgremove www 第三步,删除卷组
pvremove /dev/sdb 第三步,删除物理卷