怎样给centos系统扩展磁盘分区的实现方法
问题/故障/场景/需求
eve-ng的虚拟机ova的硬盘只有38G,需要增加空间,在vmware直接扩展硬盘后,重启系统,使用fdisk-l可以看到硬盘扩大了,但文件系统并没有扩大,还需要将这些新增的空间扩展分配到某个文件系统才行。下面记录了整个扩展过程
解决方法/步骤
在VM里扩大磁盘到250G重启系统后,查看当前的文件系统的情况
root@eve-ng:~#df-h
FilesystemSizeUsedAvailUse%Mountedon
udev7.9G07.9G0%/dev
tmpfs1.6G19M1.6G2%/run
/dev/mapper/eve--ng--vg-root38G13G23G36%/
tmpfs7.9G07.9G0%/dev/shm
tmpfs5.0M05.0M0%/run/lock
tmpfs7.9G07.9G0%/sys/fs/cgroup
/dev/sda1472M83M365M19%/boot
root@eve-ng:~#fdisk-l
...省略部分内容
Disk/dev/sda:250GiB,268435456000bytes,524288000sectors//可以看到已经有250G了
Units:sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Disklabeltype:dos
Diskidentifier:0x3e3ca055
DeviceBootStartEndSectorsSizeIdType
/dev/sda1*2048999423997376487M83Linux
/dev/sda21001470838840318288256239.5G5Extended
/dev/sda51001472838840318288256039.5G8eLinuxLVM
Disk/dev/mapper/eve--ng--vg-root:38.6GiB,41406169088bytes,80871424sectors
Units:sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Disk/dev/mapper/eve--ng--vg-swap_1:980MiB,1027604480bytes,2007040sectors
Units:sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
//下面执行分区
root@eve-ng:~#fdisk/dev/sda
Welcometofdisk(util-linux2.27.1).
Changeswillremaininmemoryonly,untilyoudecidetowritethem.
Becarefulbeforeusingthewritecommand.
Command(mforhelp):n
Partitiontype
pprimary(1primary,1extended,2free)
llogical(numberedfrom5)
Select(defaultp):p
Partitionnumber(3,4,default3):3
Firstsector(999424-524287999,default999424):83884032//注意,这里是之前分配的最后一块(sda5end)加一(83884031+1)
Lastsector,+sectorsor+size{K,M,G,T,P}(83884032-524287999,default524287999)://注意看这是不是最后一块
Createdanewpartition3oftype'Linux'andofsize210GiB.
Command(mforhelp):t
Partitionnumber(1-3,5,default5):33
Partitiontype(typeLtolistalltypes):8e
Changedtypeofpartition'Linux'to'LinuxLVM'.
Command(mforhelp):w
Thepartitiontablehasbeenaltered.
Callingioctl()tore-readpartitiontable.
Re-readingthepartitiontablefailed.:Deviceorresourcebusy
Thekernelstillusestheoldtable.Thenewtablewillbeusedatthenextrebootorafteryourunpartprobe(8)orkpartx(8).
root@eve-ng:~#reboot
root@eve-ng:~#pvcreate/dev/sda3
Physicalvolume"/dev/sda3"successfullycreated
root@eve-ng:~#vgdisplay
---Volumegroup---
VGNameeve-ng-vg
SystemID
Formatlvm2
MetadataAreas1
MetadataSequenceNo3
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV2
OpenLV2
MaxPV0
CurPV1
ActPV1
VGSize39.52GiB
PESize4.00MiB
TotalPE10117
AllocPE/Size10117/39.52GiB
FreePE/Size0/0
VGUUIDEvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI
root@eve-ng:~#vgextendeve-ng-vg/dev/sda3
Volumegroup"eve-ng-vg"successfullyextended
root@eve-ng:~#vgdisplay
---Volumegroup---
VGNameeve-ng-vg
SystemID
Formatlvm2
MetadataAreas2
MetadataSequenceNo4
VGAccessread/write
VGStatusresizable
MAXLV0
CurLV2
OpenLV2
MaxPV0
CurPV2
ActPV2
VGSize249.52GiB
PESize4.00MiB
TotalPE63877
AllocPE/Size10117/39.52GiB
FreePE/Size53760/210.00GiB
VGUUIDEvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI
root@eve-ng:~#lvdisplay
---Logicalvolume---
LVPath/dev/eve-ng-vg/root
LVNameroot
VGNameeve-ng-vg
LVUUIDktUpR0-VpqS-rJJv-a1FC-u6Gd-U8yN-2WYQ53
LVWriteAccessread/write
LVCreationhost,timeeve-ng,2018-03-2102:25:21+0200
LVStatusavailable
#open1
LVSize38.56GiB
CurrentLE9872
Segments1
Allocationinherit
Readaheadsectorsauto
-currentlysetto256
Blockdevice253:0
//扩展逻辑卷
root@eve-ng:~#lvextend-l+100%FREE/dev/eve-ng-vg/root
Sizeoflogicalvolumeeve-ng-vg/rootchangedfrom38.56GiB(9872extents)to248.56GiB(63632extents).
Logicalvolumerootsuccessfullyresized.
root@eve-ng:~#df-h
FilesystemSizeUsedAvailUse%Mountedon
udev7.9G07.9G0%/dev
tmpfs1.6G19M1.6G2%/run
/dev/mapper/eve--ng--vg-root38G13G23G36%/
tmpfs7.9G07.9G0%/dev/shm
tmpfs5.0M05.0M0%/run/lock
tmpfs7.9G07.9G0%/sys/fs/cgroup
/dev/sda1472M83M365M19%/boot
//在线扩容,要先查看当前的文件系统的类型,可以通过cat/etc/fstab来查看
root@eve-ng:~#resize2fs/dev/eve-ng-vg/root
resize2fs1.42.13(17-May-2015)
Filesystemat/dev/eve-ng-vg/rootismountedon/;on-lineresizingrequired
old_desc_blocks=3,new_desc_blocks=16
Thefilesystemon/dev/eve-ng-vg/rootisnow65159168(4k)blockslong.
root@eve-ng:~#df-h
FilesystemSizeUsedAvailUse%Mountedon
udev7.9G07.9G0%/dev
tmpfs1.6G19M1.6G2%/run
/dev/mapper/eve--ng--vg-root245G13G222G6%/
tmpfs7.9G07.9G0%/dev/shm
tmpfs5.0M05.0M0%/run/lock
tmpfs7.9G07.9G0%/sys/fs/cgroup
/dev/sda1472M83M365M19%/boot
参考
在线扩容
使用resize2fs或xfs_growfs对挂载目录在线扩容
- resize2fs针对文件系统ext2ext3ext4
- xfs_growfs针对文件系统xfs
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。