您的位置:首页 > 运维架构 > Linux

Linux LVM学习总结——放大LV容量

2015-09-01 16:31 453 查看
本篇介绍LVM管理中的命令lvresize,我们先创建一个卷组VGVolGroup02,它建立在磁盘/dev/sdc(大小为8G)上。创建逻辑卷LV时,我们故意只使用了一小部分。具体情况如下所示

[root@localhost~]#vgdisplay
---Volumegroup---
VGNameVolGroup02
SystemID
Formatlvm2
MetadataAreas1
MetadataSequenceNo1
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV0
OpenLV0
MaxPV0
CurPV1
ActPV1
VGSize7.97GiB
PESize32.00MiB
TotalPE255
AllocPE/Size0/0
FreePE/Size255/7.97GiB
VGUUIDSETgjx-dobd-Uayt-AWgN-HKID-hsYe-tEotIS
[root@localhost~]#lvcreate-L7.97-nLogVol00VolGroup02
Roundingupsizetofullphysicalextent32.00MiB
Logicalvolume"LogVol00"created
[root@localhost~]#mkfs-text4/dev/VolGroup02/LogVol00
mke2fs1.41.12(17-May-2010)
Filesystemlabel=
OStype:Linux
Blocksize=1024(log=0)
Fragmentsize=1024(log=0)
Stride=0blocks,Stripewidth=0blocks
8192inodes,32768blocks
1638blocks(5.00%)reservedforthesuperuser
Firstdatablock=1
Maximumfilesystemblocks=33554432
4blockgroups
8192blockspergroup,8192fragmentspergroup
2048inodespergroup
Superblockbackupsstoredonblocks:
8193,24577
Writinginodetables:done
Creatingjournal(4096blocks):done
Writingsuperblocksandfilesystemaccountinginformation:done
Thisfilesystemwillbeautomaticallycheckedevery23mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.
[root@localhost~]#cd/
[root@localhost/]#mkdir/u01
[root@localhost/]#mount/dev/VolGroup02/LogVol00/u01
[root@localhost/]#vi/etc/fstab
#
#/etc/fstab
#CreatedbyanacondaonMonAug1715:08:212015
#
#Accessiblefilesystems,byreference,aremaintainedunder'/dev/disk'
#Seemanpagesfstab(5),findfs(8),mount(8)and/orblkid(8)formoreinfo
#
UUID=3440ad55-6486-45ed-876f-e942b08013bf/ext4defaults11
UUID=d3abb655-db70-4c42-967d-57c421abfda0/bootext4defaults12
UUID=660624ff-335d-42ca-b779-f130a80d9da8/homeext4defaults12
UUID=6f534bf0-e486-4937-84ae-ed1221cf34f1swapswapdefaults00
/dev/VolGroup02/LogVol00/u01ext4defaults11
tmpfs/dev/shmtmpfsdefaults00
devpts/dev/ptsdevptsgid=5,mode=62000
sysfs/syssysfsdefaults00
proc/procprocdefaults00




此时,我们要放大文件系统/u01的大小,那么就需要使用到lvresize放大LV容量

[root@localhost~]#lvscan
ACTIVE'/dev/VolGroup02/LogVol00'[32.00MiB]inherit
[root@localhost~]#lvdisplay/dev/VolGroup02/LogVol00
---Logicalvolume---
LVPath/dev/VolGroup02/LogVol00
LVNameLogVol00
VGNameVolGroup02
LVUUIDOCHwx1-EL9P-6C5J-RNuz-2Xu5-4215-H3xt5s
LVWriteAccessread/write
LVCreationhost,timelocalhost.localdomain,2015-09-0110:50:10+0800
LVStatusavailable
#open1
LVSize32.00MiB
CurrentLE1
Segments1
Allocationinherit
Readaheadsectorsauto
-currentlysetto256
Blockdevice253:0
[root@localhost~]#lvresize-L+7.89G/dev/VolGroup02/LogVol00
Roundingsizetoboundarybetweenphysicalextents:7.91GiB
SizeoflogicalvolumeVolGroup02/LogVol00changedfrom32.00MiB(1extents)to7.94GiB(254extents).
LogicalvolumeLogVol00successfullyresized






[root@localhost~]#resize2fs-p/dev/VolGroup02/LogVol00
resize2fs1.41.12(17-May-2010)
Filesystemat/dev/VolGroup02/LogVol00ismountedon/u01;on-lineresizingrequired
olddesc_blocks=1,new_desc_blocks=32
Performinganon-lineresizeof/dev/VolGroup02/LogVol00to8323072(1k)blocks.
Thefilesystemon/dev/VolGroup02/LogVol00isnow8323072blockslong.
[root@localhost~]#df-h
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda227G6.0G20G24%/
tmpfs5.9G05.9G0%/dev/shm
/dev/sda1477M32M420M8%/boot
/dev/sdb199G60M94G1%/home
/dev/mapper/VolGroup02-LogVol00
7.7G2.7M7.3G1%/u01




如果我们此时在虚拟机上将磁盘从8G扩展为10G,那么要如何利用扩展的磁盘空间呢?




[root@localhostu01]#fdisk-l
Disk/dev/sda:42.9GB,42949672960bytes
64heads,32sectors/track,40960cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x000462cf
DeviceBootStartEndBlocksIdSystem
/dev/sda1*250151200083Linux
Partition1doesnotendoncylinderboundary.
/dev/sda2502286722884710483Linux
Partition2doesnotendoncylinderboundary.
/dev/sda328673409601258291282Linuxswap/Solaris
Partition3doesnotendoncylinderboundary.
Disk/dev/sdc:8589MB,8589934592bytes
64heads,32sectors/track,8192cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x98c391fe
DeviceBootStartEndBlocksIdSystem
/dev/sdc118192838859283Linux
Disk/dev/sdb:107.4GB,107374182400bytes
255heads,63sectors/track,13054cylinders
Units=cylindersof16065*512=8225280bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x0002488e
DeviceBootStartEndBlocksIdSystem
/dev/sdb111305510485657683Linux
Disk/dev/mapper/VolGroup02-LogVol00:33MB,33554432bytes
255heads,63sectors/track,4cylinders
Units=cylindersof16065*512=8225280bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x00000000




重启过后才能看到/dev/sdc的空间变化情况。



新建分区


[code][root@localhost~]#fdisk/dev/sdc
WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedto
switchoffthemode(command'c')andchangedisplayunitsto
sectors(command'u').
Command(mforhelp):p
Disk/dev/sdc:10.7GB,10737418240bytes
64heads,32sectors/track,10240cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x98c391fe
DeviceBootStartEndBlocksIdSystem
/dev/sdc118192838859283Linux
Command(mforhelp):n
Commandaction
eextended
pprimarypartition(1-4)
p
Partitionnumber(1-4):2
Firstcylinder(8193-10240,default8193):
Usingdefaultvalue8193
Lastcylinder,+cylindersor+size{K,M,G}(8193-10240,default10240):
Usingdefaultvalue10240
Command(mforhelp):p
Disk/dev/sdc:10.7GB,10737418240bytes
64heads,32sectors/track,10240cylinders
Units=cylindersof2048*512=1048576bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x98c391fe
DeviceBootStartEndBlocksIdSystem
/dev/sdc118192838859283Linux
/dev/sdc2819310240209715283Linux
Command(mforhelp):w
Thepartitiontablehasbeenaltered!
Callingioctl()tore-readpartitiontable.
WARNING:Re-readingthepartitiontablefailedwitherror16:Deviceorresourcebusy.
Thekernelstillusestheoldtable.Thenewtablewillbeusedat
thenextrebootorafteryourunpartprobe(8)orkpartx(8)
Syncingdisks.

新建物理卷PV

[root@localhost~]#pvcreate/dev/sdc2
Physicalvolume"/dev/sdc2"successfullycreated

放大VG容量

[root@localhost~]#vgextend/dev/mapper/VolGroup02/dev/sdc2
Volumegroup"VolGroup02"successfullyextended


放大LV容量

[root@localhost~]#pvscan
PV/dev/sdc1VGVolGroup02lvm2[7.97GiB/32.00MiBfree]
PV/dev/sdc2VGVolGroup02lvm2[1.97GiB/1.97GiBfree]
Total:2[9.94GiB]/inuse:2[9.94GiB]/innoVG:0[0]
[root@localhost~]#pvdisplay/dev/sdc2
---Physicalvolume---
PVName/dev/sdc2
VGNameVolGroup02
PVSize2.00GiB/notusable32.00MiB
Allocatableyes
PESize32.00MiB
TotalPE63
FreePE63
AllocatedPE0
PVUUIDqP1PGl-krr9-vCTY-vWgN-MsKL-rn1x-zAhmmc
[root@localhost~]#lvextend-L+1.97G/dev/VolGroup02/LogVol00
Roundingsizetoboundarybetweenphysicalextents:2.00GiB
SizeoflogicalvolumeVolGroup02/LogVol00changedfrom7.94GiB(254extents)to9.94GiB(318extents).
LogicalvolumeLogVol00successfullyresized
[root@localhost~]#resize2fs/dev/VolGroup02/LogVol00
resize2fs1.41.12(17-May-2010)
Filesystemat/dev/VolGroup02/LogVol00ismountedon/u01;on-lineresizingrequired
olddesc_blocks=32,new_desc_blocks=40
Performinganon-lineresizeof/dev/VolGroup02/LogVol00to10420224(1k)blocks.
Thefilesystemon/dev/VolGroup02/LogVol00isnow10420224blockslong.
[root@localhost~]#df-h
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda227G6.0G20G24%/
tmpfs5.9G05.9G0%/dev/shm
/dev/sda1477M32M420M8%/boot
/dev/sdb199G60M94G1%/home
/dev/mapper/VolGroup02-LogVol00
9.7G2.5M9.2G1%/u01
[root@localhost~]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: