|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
欢迎大家来到仓酷云论坛!纲目1、简介
2、版本
3、LVM模块
4、详细操纵
- 对增加的硬盘举行分区(fdisk/dev/[hs]d[a-z])
- 对创立的分区创立物理卷(pvcreate)
- 给逻辑卷创立逻辑容器(卷组)
- 在卷组创立巨细分歧的逻辑卷(lvcreate)
- 赐与存在的卷组扩展容量
- 完成在线扩展LVM容量
- 完成缩减LVM容量(不撑持在线缩减)
- 减小卷组容量
- 使用给LVM创立快照,并完成备份并复原数据
1、简介LVM是LogicalVolumeManager(逻辑卷办理)的简写,它是Linux情况下对磁盘分区举行办理的一种机制,它由HeinzMauelshagen在Linux2.4内核上完成,于1998年公布到Linux社区中,它同意你在Linux体系上用复杂的下令行办理一个完全的逻辑卷办理情况。 2、版本
LVM1最后的LVM与1998年公布,只在Linux内核2.4版本上可用,它供应最基础的逻辑卷办理。
LVM2LVM-1的更新版本,在Linux内核2.6中才可用,它在尺度的LVM-1功效外还供应了分外的功效。
检察:(测试机CentOS5.5X86_64)
1
2
3
4
5
6
7
[root@localhost~]#uname-a
Linuxlocalhost.localdomain2.6.18-194.el5#1SMPFriApr214:58:14EDT2010x86_64x86_64x86_64GNU/Linux
[root@localhost~]#uname-r
2.6.18-194.el5
[root@localhost~]#rpm-qa|greplvm
lvm2-2.02.56-8.el5
[root@localhost~]#
3、LVM模块
Physicalvolume(PV)、Volumegroup(VG)、Logicalvolume(LV)、Physicalextent(PE),上面我们用一个复杂的图来讲明下物理卷、卷组、逻辑卷他们之间的干系(此图只是团体了解,仅供参考)
简而言之:
逻辑卷的创立,就是将多块硬盘创立物理卷,而将这些物理卷以逻辑的情势总成一个容器,然后从这个容器内里创立巨细分歧的分区文件,而这个容器就是所谓的逻辑卷,而从这个容器里创立巨细分歧的分区文件,这个分区文件就叫做逻辑卷。嘿嘿,你懂了吗?^_^……
4、详细操纵
[quote]1.分区
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@localhost~]#fdiskCl#检察已存在的分区与硬盘
Disk/dev/sda:21.4GB,21474836480bytes
255heads,63sectors/track,2610cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/sda1*13326504183Linux
/dev/sda234130810241437+83Linux
/dev/sda3130919455116702+83Linux
/dev/sda4194626105341612+5Extended
/dev/sda519462072102009682Linuxswap/Solaris
Disk/dev/sdb:21.4GB,21474836480bytes
255heads,63sectors/track,2610cylinders
Units=cylindersof16065*512=8225280bytes
Disk/dev/sdbdoesntcontainavalidpartitiontable
Disk/dev/sdc:21.4GB,21474836480bytes
255heads,63sectors/track,2610cylinders
Units=cylindersof16065*512=8225280bytes
Disk/dev/sdcdoesntcontainavalidpartitiontable
[root@localhost~]#fdisk/dev/sdb#给/sdb分区,效果以下
Command(mforhelp):p
Disk/dev/sdb:21.4GB,21474836480bytes
255heads,63sectors/track,2610cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/sdb112441959898+8eLinuxLVM#注重修正分区范例为8e
/dev/sdb224548819599308eLinuxLVM
/dev/sdb348973219599308eLinuxLVM
Command(mforhelp):
[root@localhost~]#partprobe#让内核从头读取一下硬盘
[root@localhost~]#fdisk-l/dev/sdb
Disk/dev/sdb:21.4GB,21474836480bytes
255heads,63sectors/track,2610cylinders
Units=cylindersof16065*512=8225280bytes
DeviceBootStartEndBlocksIdSystem
/dev/sdb112441959898+8eLinuxLVM
/dev/sdb224548819599308eLinuxLVM
/dev/sdb348973219599308eLinuxLVM
[root@localhost~]#
2.将物理分区与硬盘创立为物理卷(pvcreate)
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost~]#pvcreate/dev/sdb[1-3]#将分区创立为物理卷
Physicalvolume"/dev/sdb1"successfullycreated
Physicalvolume"/dev/sdb2"successfullycreated
Physicalvolume"/dev/sdb3"successfullycreated
[root@localhost~]#
[root@localhost~]#pvcreate/dev/sdc#将硬盘创立为物理卷
Physicalvolume"/dev/sdc"successfullycreated
[root@localhost~]#pvs#检察创立的物理卷
PVVGFmtAttrPSizePFree
/dev/sdb1myvglvm2a-1.87G1.87G
/dev/sdb2myvglvm2a-1.87G1.87G
/dev/sdb3myvglvm2a-1.87G1.87G
/dev/sdcmyvglvm2a-20.00G20.00G
3.将物理卷(pv)创立为卷组(vgcreate),名为myvg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@localhost~]#vgcreatemyvg/dev/sdb[1-3]/dev/sdc
Volumegroup"myvg"successfullycreated
[root@localhost~]#vgs
VG#PV#LV#SNAttrVSizeVFree
myvg400wz--n-25.60G25.60G
[root@localhost~]#
[root@localhost~]#vgdisplay
---Volumegroup---
VGNamemyvg#卷组名
SystemID
Formatlvm2
MetadataAreas4
MetadataSequenceNo1
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV0
OpenLV0
MaxPV0
CurPV4
ActPV4
VGSize25.60GB
PESize4.00MB#物理盘的基础单元:默许4MB
TotalPE6553
AllocPE/Size0/0
FreePE/Size6553/25.60GB
VGUUIDwuNBgb-tP95-pVoX-ehHw-cMfN-hyem-PNMqwe
[root@localhost~]#
4.在卷组里创立逻辑卷并格局化、挂载利用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[root@localhost~]#lvcreate-L2G-nmylv1myvg#创立逻辑卷
Logicalvolume"mylv1"created
[root@localhost~]#lvs#检察逻辑卷
LVVGAttrLSizeOriginSnap%MoveLogCopy%Convert
mylv1myvg-wi-a-2.00G
[root@localhost~]#mke2fs-j/dev/myvg/mylv1#格局化逻辑卷
mke2fs1.39(29-May-2006)
Filesystemlabel=
OStype:Linux
Blocksize=4096(log=2)
Fragmentsize=4096(log=2)
262144inodes,524288blocks
26214blocks(5.00%)reservedforthesuperuser
Firstdatablock=0
Maximumfilesystemblocks=536870912
16blockgroups
32768blockspergroup,32768fragmentspergroup
16384inodespergroup
Superblockbackupsstoredonblocks:
32768,98304,163840,229376,294912
Writinginodetables:done
Creatingjournal(16384blocks):done
Writingsuperblocksandfilesystemaccountinginformation:done
Thisfilesystemwillbeautomaticallycheckedevery26mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.
[root@localhost~]#mkdir/mydata#创立挂载目次
[root@localhost~]#mount/dev/myvg/mylv1/mydata/#挂载
[root@localhost~]#mount#检察是不是挂载乐成
/dev/sda2on/typeext3(rw)
procon/proctypeproc(rw)
sysfson/systypesysfs(rw)
devptson/dev/ptstypedevpts(rw,gid=5,mode=620)
/dev/sda3on/datatypeext3(rw)
/dev/sda1on/boottypeext3(rw)
tmpfson/dev/shmtypetmpfs(rw)
noneon/proc/sys/fs/binfmt_misctypebinfmt_misc(rw)
sunrpcon/var/lib/nfs/rpc_pipefstyperpc_pipefs(rw)
/dev/mapper/myvg-mylv1on/mydatatypeext3(rw)
[root@localhost~]#
[root@localhost~]#ls/mydata/#检察
lost+found
[root@localhost~]#dfCh#检察硬盘
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda29.5G1.8G7.2G20%/
/dev/sda34.8G138M4.4G4%/data
/dev/sda1251M17M222M7%/boot
tmpfs60M060M0%/dev/shm
/dev/mapper/myvg-mylv1
2.0G68M1.9G4%/mydata
[root@localhost~]#
5.发明卷组空间不敷,我们扩展卷组空间
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost~]#pvcreate/dev/sdd#将新硬盘/sdd到场物理卷中
Physicalvolume"/dev/sdd"successfullycreated
[root@localhost~]#pvs#检察物理卷
/dev/cdrom:openfailed:Nomediumfound
PVVGFmtAttrPSizePFree
/dev/sdb1myvglvm2a-1.87G1.87G
/dev/sdb2myvglvm2a-1.87G1.87G
/dev/sdb3myvglvm2a-1.87G1.87G
/dev/sdcmyvglvm2a-20.00G18.00G
/dev/sddmyvglvm2a-20.00G20.00G
[root@localhost~]#
[root@localhost~]#vgextendmyvg/dev/sdd#扩大卷组
Volumegroup"myvg"successfullyextended
[root@localhost~]#vgs#检察新增添的卷组
VG#PV#LV#SNAttrVSizeVFree
myvg510wz--n-45.59G43.59G
[root@localhost~]#
6.扩大逻辑卷(撑持在线扩大)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
将/dev/myvg/mylv1扩大到4G,而且请求数据能够一般会见
[root@localhost~]#cd/mydata/
[root@localhostmydata]#touchindex.html
[root@localhostmydata]#echo"test">index.html
[root@localhostmydata]#catindex.html
test
[root@localhostmydata]#vgs
/dev/cdrom:openfailed:Nomediumfound
VG#PV#LV#SNAttrVSizeVFree
myvg510wz--n-45.59G43.59G
[root@localhostmydata]#lvextend-L+2G/dev/myvg/mylv1
Extendinglogicalvolumemylv1to4.00GB
Logicalvolumemylv1successfullyresized
[root@localhostmydata]#resize2fs-p/dev/myvg/mylv1#经由过程resize2fs将文件体系的容量的确增加
resize2fs1.39(29-May-2006)
Filesystemat/dev/myvg/mylv1ismountedon/mydata;on-lineresizingrequired
Performinganon-lineresizeof/dev/myvg/mylv1to1048576(4k)blocks.
Thefilesystemon/dev/myvg/mylv1isnow1048576blockslong.
[root@localhostmydata]#lvs
LVVGAttrLSizeOriginSnap%MoveLogCopy%Convert
mylv1myvg-wi-ao4.00G
[root@localhostmydata]#
[root@localhostmydata]#catindex.html
test
[root@localhostmydata]#df-h
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda29.5G1.8G7.2G20%/
/dev/sda34.8G138M4.4G4%/data
/dev/sda1251M17M222M7%/boot
tmpfs60M060M0%/dev/shm
/dev/mapper/myvg-mylv1
4.0G69M3.7G2%/mydata#乐成增添了2G
[root@localhostmydata]#
7.缩减逻辑卷
- 检察逻辑卷利用空间情况
- 不克不及在线缩减,得先卸载
- 确保缩减后的空间巨细仍然能存储原本的一切数据
- 在缩减之前应当先强行反省文件,以确保文件体系处于一至性形态
<divstyle="padding:0px;margin:0px;"><divid="highlighter_61719"class="syntaxhighlighterbash"style="overflow:visible!important;width:720px;">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<divclass="container">将/dev/myvg/mylv1缩减到1G,而且请求数据能够一般会见(以是我们就按下面的提醒在操纵)
[root@localhost~]#dfClh#检察已用空间巨细
[root@localhost~]#umount/dev/myvg/mylv1#卸载分区
[root@localhost~]#e2fsck-f/dev/myvg/mylv1#强迫反省文件体系
[root@localhost~]#resize2fs/dev/myvg/mylv11G#缩减逻辑巨细
[root@localhost~]#lvreduce-L1G/dev/myvg/mylv1#缩减物理界限巨细
[root@localhost~]#lvs#检察逻辑卷
/dev/cdrom:openfailed:Nomediumfound
LVVGAttrLSizeOriginSnap%MoveLogCopy%Convert
mylv1myvg-wi-ao1.00G
[root@localhost~]#mount/dev/myvg/mylv1/mydata
[root@localhost~]#ls/mydata/
index.htmllost+found
[root@localhost~]#cat/mydata/index.html
test
<divclass="linenumber16index15alt1">[root@localhost~] |
|