LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分
LVM
LVM区管理的灵活性。前面谈到,LVM是在磁盘分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽下层磁盘分区布局,提供一个抽象的盘卷,在盘卷上建立文件系统。物理卷(physical volume)物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
Linux用户安装Linux *** 作系统时遇到的一个最常见的难以决定的问题就是如何正确地给评估各分区大小,以分配合适的硬盘空间。而遇到出现 某个分区空间耗尽时,解决的方法通常是使用符号链接,或者使用调整分区大小的工具(比如PatitionMagic等),但这都只是暂时解决办法,没有根本解决问题。随着Linux的逻辑盘卷管理功能的出现,这些问题都迎刃而解,用户在无需停机的情况下方便地调整各个分区大小。
- PE(physical extend) : 物理拓展
- PV(physical volume) : 物理卷 --- LVM底层的东西,可以为一个硬盘如sda,sdb,sdc;也可以为一个硬盘里面的一个分区如sda1,sdb1
- VG(volume group) : 卷组 --- 卷组由多个LV组成,是个抽象的,是一个目录而并非一个设备,如/dev/testVg
- LV(logic volume) : 逻辑卷 --- LV存在于PE里面
- 图示:
pv : /dev/sdb /dev/sdc
--pv-- --pv-- --pv-- --pv-- --pv-- --pv--
vg : --pv-- --pv-- --pv-- --pv-- --pv-- --pv--
lv : --lv-- --lv-- --lv-- --lv-- --lv--
pvs , vgs , lvs : 都是简略的显示相关的信息.
pvdisplay , vgdisplay , lvdisplay : 详细的显示相关的信息
PV > VG >LV > 格式化 > 挂载使用
[root@localhost ~]# pvcreate /dev/sd[b,c] //可以使用分区或者硬盘..pvcreate /dev/sd[b,c]1 就是这两个硬盘的第一个分区来创建LVM的PV Physical volume "/dev/sdb" successfully created Physical volume "/dev/sdc" successfully created [root@localhost ~]#pvs PV VG Fmt Attr PSize PFree /dev/sdb lvm2 a-- 20.00g 20.00g /dev/sdc lvm2 a-- 20.00g 20.00g [root@localhost ~]# pvsdisplay -bash: pvsdisplay: command not found [root@localhost ~]# clear [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb lvm2 a-- 20.00g 20.00g /dev/sdc lvm2 a-- 20.00g 20.00g [root@localhost ~]# pvdisplay "/dev/sdb" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID U71gX3-EtNA-tVPL-8WYL-99Do-PY3c-LUsfeE "/dev/sdc" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name /dev/sdc VG Name PV Size 20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID TqI9uD-vvG1-2eD2-kyTM-cEtj-ZpXc-ctLi91
[root@localhost ~]# vgcreate testVG /dev/sd[b,c] Volume group "testVG" successfully created //vgcreate 卷组名 归入卷组的磁盘或者分区 [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree testVG 2 0 0 wz--n- 39.99g 39.99g [root@localhost ~]# vgdisplay --- Volume group --- VG Name testVG 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 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 0 / 0 Free PE / Size 10238 / 39.99 GiB VG UUID fSkmZR-8WiE-COe8-n4QO-rmAz-2PgJ-BRuity
[root@localhost ~]# lvcreate -n testLV1 -L 10G testVG // -n 是设置LV卷名 , -L 是设置LV的大小[G或M] Logical volume "testLV1" created [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert testLV1 testVG -wi-a---- 10.00g [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/testVG/testLV1 LV Name testLV1 VG Name testVG LV UUID bPyUwj-twOD-flGj-x266-mXCl-rcfa-FBUykW LV Write Access read/write LV Creation host, time localhost.localdomain, 2013-04-20 17:32:23 -0700 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
[root@localhost ~]# mkfs.ext4 /dev/testVG/testLV1 // 这里我格式为ext4 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 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2684354560 80 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 37 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# mount /dev/testVG/testLV1 /mnt [root@localhost ~]# mount /dev/sda2 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/testVG-testLV1 on /mnt type ext4 (rw)
LVM 的进阶使用:拉伸和缩小
- 拓展LV
[root@localhost ~]# lvextend -L +5G /dev/testVG/testLV1 //增加5G的大小给testLV1 Extending logical volume testLV1 to 15.00 GiB Logical volume testLV1 successfully resized [root@localhost ~]# resize2fs /dev/testVG/testLV1 //更新文件系统,重新定义磁盘大小 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/testVG/testLV1 is mounted on /mnt; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/testVG/testLV1 to 3932160 (4k) blocks. The filesystem on /dev/testVG/testLV1 is now 3932160 blocks long. [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 28G 3.4G 23G 13% / tmpfs 935M 84K 935M 1% /dev/shm /dev/sda1 291M 58M 218M 22% /boot /dev/mapper/testVG-testLV1 15G 153M 14G 2% /mnt
- 拓展VG
这里演示一个新硬盘添加进去已有的卷组,,从而增加可使用个PV
[root@localhost ~]# pvcreate /dev/sdd Physical volume "/dev/sdd" successfully created [root@localhost ~]#vgextend testVG /dev/sdd Volume group "testVG" successfully extended [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree testVG 3 1 0 wz--n- 59.99g 44.99g //为什么不是剩下60G,是因为我们创建了一个LV1 10G,又拓展5G给它.所以剩下45G
- 缩小磁盘
进行这个 *** 作之前,必须umount挂载的lv,重新定义卷的大小..再缩小卷 --- 若不根据此步骤.数据极有可能丢失掉(不可挽回,切记)
[root@localhost ~]# umount /mnt //卸载挂载的LV卷,具体看你的挂载点 [root@localhost ~]# e2fsck -f /dev/testVG/testLV1 // 检查文件系统 [root@localhost ~]# resize2fs /dev/testVG/testLV1 5G //在线调整你的文件系统的大小 resize2fs 1.41.12 (17-May-2010) The filesystem is already 3932160 blocks long. Nothing to do! [root@localhost ~]# lvreduce -L -10G /dev/testVG/testLV1 //使用lvreduce 来缩小你的磁盘大小 WARNING: Reducing active logical volume to 5.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce testLV1? [y/n]: y Reducing logical volume testLV1 to 5.00 GiB Logical volume testLV1 successfully resized [root@localhost ~]# lvdisplay //查看LV的详细信息 --- Logical volume --- LV Path /dev/testVG/testLV1 LV Name testLV1 VG Name testVG LV UUID bPyUwj-twOD-flGj-x266-mXCl-rcfa-FBUykW LV Write Access read/write LV Creation host, time localhost.localdomain, 2013-04-20 17:32:23 -0700 LV Status available # open 0 LV Size 5.00 GiB //移除10G后,剩下5G Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
- 缩小VG
[root@localhost ~]# vgs //值得注意的是,移除出卷组的硬盘或者分区必须小于剩余的空间.否则必定失败保存 VG #PV #LV #SN Attr VSize VFree testVG 3 1 0 wz--n- 59.99g 54.99g [root@localhost ~]#vgreduce testVG /dev/sdd Removed "/dev/sdd" from volume group "testVG" [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree testVG 2 1 0 wz--n- 39.99g 34.99g删除LVM:
删除顺序自下而上 : lv > vg > pv
[root@localhost ~]# lvremove /dev/testVG/testLV1 Do you really want to remove active logical volume testLV1? [y/n]: y Logical volume "testLV1" successfully removed [root@localhost ~]# vgremove testVG Volume group "testVG" successfully removed [root@localhost ~]# pvremove /dev/sd[b,c] Labels on physical volume "/dev/sdb" successfully wiped Labels on physical volume "/dev/sdc" successfully wiped [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdd lvm2 a-- 20.00g 20.00g [root@localhost ~]# pvremove /dev/sdd Labels on physical volume "/dev/sdd" successfully wiped [root@localhost ~]# pvs [root@localhost ~]# vgs No volume groups found推荐使用的命令:e2fsadm
使用 e2fsadm -L +10G /dev/testVG/testLv1 相当于
# lvextend -L+10G /dev/testVG/testLv1
# resize2fs /dev/testVG/testLv1
使用 e2fsadm -L -10G /dev/testVG/testLv1 相当于(需要先umount之后才等同)
# resize2fs /dev/testVG/testLv1 5G
# lvreduce -L -10G /dev/testVG/testLv1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)