分区硬盘Lvm 折腾小记
发一下牢骚和主题无关:
LVM简述(用引百度百科):
LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对盘磁分区行进管理的一种制机,LVM是立建在硬盘和分区之上的一个逻辑层,来高提盘磁分
LVM
LVM区管理的灵活性。后面谈到,LVM是在盘磁分区和文件系统之间添加的一个逻辑层,来为文件系统屏蔽层下盘磁分区布局,供给一个抽象的盘卷,在盘卷上立建文件系统。物理卷(physical volume)物理卷就是指硬盘分区或从逻辑上与盘磁分区有具一样能功的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、盘磁等)比拟,却包含有与LVM关相的管理参数。
Linux户用装安Linux操纵系统时碰到的一个最常见的难以决议的问题就是如何正确地给估评各分区小大,以分配适合的硬盘空间。而碰到现出 某个分区空间耗尽时,处理的方法通常是应用符号链接,或者应用整调分区小大的具工(比如PatitionMagic等),但这都只是时暂处理办法,没有基本处理问题。随着Linux的逻辑盘卷管理能功的现出,这些问题都解而刃迎,户用在无需停机的情况下方便地整调各个分区小大。
演示环境:CENTOS6.4 .硬盘3个,其中2个创立,一个拓展
础基概述:PE | PV | VG | LV
- 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--
LVM命令参数简述:
pvs , vgs , lvs : 都是简单的表现关相的息信.
pvdisplay , vgdisplay , lvdisplay : 体具的表现关相的息信
LVM的创立流程:
PV > VG >LV > 格式化 > 挂载应用
LVM的应用 --- PV的创立和查看
[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
LVM的应用 --- VG的创立和查看
[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
LVM的应用 --- LV的创立和查看
[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
LVM的应用 --- LV格式化和挂载
[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
文章结束给大家分享下程序员的一些笑话语录:
程序员的愿望
有一天一个程序员见到了上帝.上帝: 小伙子,我可以满足你一个愿望.程序员: 我希望中国国家队能再次打进世界杯.
上帝: 这个啊!这个不好办啊,你还说下一个吧!
程序员: 那好!我的下一个愿望是每天都能休息6个小时以上.
上帝: 还是让中国国家打进世界杯.