标签:lvm
LVM逻辑卷管理
基本的逻辑卷管理概念
用户在无需停机的情况下可以方便地调整各个分区大小
命令管理:
PV(Physical Volume)- 物理卷
pvcreate pvremove psdisplay pvscan pvspvmove
VG(Volumne Group)- 卷组
vgcreate vgscan vgs vgextend(扩充)、vgremove(删除) vgreduce(移除,缩容)
vgcreate
-s:pe大小,默认4M
LV(Logical Volume)- 逻辑卷
lvcreate lvscan lvs lvextend(扩充)、lvremove(删除)vgreduce(移除,缩容)
lvcreate
-n:指定名称
-L: 指定大小
-l:%vg|pvs|FREE,打算分配%
首先准备环境:
准备两块格式为8e的 磁盘 后缀为 linux LVM(LVM2)
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 7859 62914560 8e Linux LVM
/dev/sda3 7859 8512 5252256 8e Linux LVM
使用命令添加
[root@localhost ~]# pvcreate /dev/sda{5,6}
Physical volume "/dev/sda3" successfully created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg0 lvm2 a-- 59.99g 7.99g
/dev/sda3 lvm2 --- 5.01g 5.01g
/dev/sda5 lvm2 --- 5.01g 5.01g
/dev/sda6 lvm2 --- 5.01g 5.01g
创建vg:
[root@localhost ~]# vgcreate magelvm /dev/sda{5,6}
Physical volume "/dev/sda5" successfully created
Physical volume "/dev/sda6" successfully created
Volume group "magelvm" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
magelvm 2 0 0 wz--n- 10.02g 10.02g
vg0 1 4 0 wz--n- 59.99g 7.99g
增加空间:
[root@localhost ~]# vgextend magelvm /dev/sda3
Volume group "magelvm" successfully extended
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name magelvm
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 2
VG Access read/write
VG Status resizable
VG Size 15.02 GiB
移除空间:(需要注意移除的磁盘上是否有数据,有的话先转移)
[root@localhost ~]# pvmove /dev/sda3
No data to move for magelvm
[root@localhost ~]# vgreduce magelvm /dev/sda3
Removed "/dev/sda3" from volume group "magelvm"
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name magelvm
System ID
Format lvm2
VG Access read/write
VG Status resizable
VG Size 10.02 GiB
创建LV:
[root@localhost ~]# lvcreate -L 5G -n mageedu magelvm
Logical volume "mageedu" created
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mageedu magelvm -wi-a----- 5.00g
root vg0 -wi-ao---- 20.00g
(创建完LV 需要格式化,然后挂载“mount”)
[root@localhost ~]# mke2fs -t ext4 /dev/magelvm/mageedu
逻辑卷扩展的步骤
查看卷组有空闲空间否
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mageedu magelvm -wi-a----- 5.00g
-->扩展物理边界
[root@localhost ~]# lvextend -L 8G /dev/magelvm/mageedu
Size of logical volume magelvm/mageedu changed from 5.00 GiB (1280 extents) to 8.00 GiB (2048 extents).
Logical volume mageedu successfully resized
-->扩展逻辑边界
[root@localhost ~]# resize2fs /dev/magelvm/mageedu
resize2fs 1.41.12 (17-May-2010)
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg0-root 20G 549M 19G 3% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 190M 33M 148M 18% /boot
/dev/mapper/vg0-usr 9.8G 2.1G 7.2G 23% /usr
/dev/mapper/vg0-var 20G 260M 19G 2% /var
/dev/mapper/magelvm-mageedu
7.8G 12M 7.4G 1% /mnt
缩减逻辑卷的步骤
卸载卷,并执行强制检查
[root@localhost ~]# umount /dev/magelvm/mageedu
[root@localhost ~]# e2fsck -f /dev/magelvm/mageedu
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/magelvm/mageedu: 11/524288 files (0.0% non-contiguous), 68559/2097152 blocks
缩减逻辑边界
[root@localhost ~]# resize2fs /dev/magelvm/mageedu
resize2fs 1.41.12 (17-May-2010)
缩减物理边界
[root@localhost ~]# lvreduce -L 2G /dev/magelvm/mageedu
WARNING: Reducing active logical volume to 2.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mageedu? [y/n]: y
Size of logical volume magelvm/mageedu changed from 8.00 GiB (2048 extents) to 2.00 GiB (512 extents).
Logical volume mageedu successfully resized
挂载卷
[root@localhost ~]# mount /dev/magelvm/mageedu /mnt
本文出自 “Hotel California” 博客,转载请与作者联系!
标签:lvm
原文地址:http://zhongshixun.blog.51cto.com/10314910/1691010