这篇文章主要介绍“Linux系统中怎么扩展根分区”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Linux系统中怎么扩展根分区”文章能帮助大家解决问题。

环境:

VMware虚拟机Red Hat 6.5

技术:

逻辑卷管理(LVM)

具体步骤:1.查看磁盘空间

[root@localhost~]#df-h#查看磁盘空间,根分区的大小是18G,已经用了43%。FilesystemSizeUsedAvailUse%Mountedon/dev/mapper/VolGroup-lv_root18G7.0G9.5G43%/tmpfs2.0G76K2.0G1%/dev/shm/dev/sda1485M40M421M9%/boot/dev/sr03.6G3.6G0100%/media/cdrom2.创建磁盘分区

[root@localhost~]#fdisk-lDisk/dev/sda:21.5GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00083529DeviceBootStartEndBlocksIdSystem/dev/sda1*16451200083LinuxPartition1doesnotendoncylinderboundary./dev/sda2642611204584968eLinuxLVM#/dev/sdb盘还有足够的空间Disk/dev/sdb:21.5GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00000000Disk/dev/mapper/VolGroup-lv_root:18.8GB,18798870528bytes255heads,63sectors/track,2285cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00000000Disk/dev/mapper/VolGroup-lv_swap:2147MB,2147483648bytes255heads,63sectors/track,261cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00000000[root@localhost~]#fdisk/dev/sdbDevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabelBuildinganewDOSdisklabelwithdiskidentifier0xac7c929b.Changeswillremaininmemoryonly,untilyoudecidetowritethem.Afterthat,ofcourse,thepreviouscontentwon'tberecoverable.Warning:invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite)WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedtoswitchoffthemode(command'c')andchangedisplayunitstosectors(command'u').Command(mforhelp):pDisk/dev/sdb:21.5GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0xac7c929bDeviceBootStartEndBlocksIdSystemCommand(mforhelp):nCommandactioneextendedpprimarypartition(1-4)pPartitionnumber(1-4):1#分区号Firstcylinder(1-2610,default1):#回车用默认的Usingdefaultvalue1Lastcylinder,+cylindersor+size{K,M,G}(1-2610,default2610):#回车用默认的Usingdefaultvalue2610Command(mforhelp):t#改变类型Selectedpartition1Hexcode(typeLtolistcodes):8e#LVM的分区代码Changedsystemtypeofpartition1to8e(LinuxLVM)Command(mforhelp):pDisk/dev/sdb:21.5GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0xac7c929bDeviceBootStartEndBlocksIdSystem/dev/sdb11261020964793+8eLinuxLVMCommand(mforhelp):wThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.Syncingdisks.[root@localhost~]#partprobe#将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表,有些小报错不要紧。Warning:WARNING:thekernelfailedtore-readthepartitiontableon/dev/sda(Deviceorresourcebusy).Asaresult,itmaynotreflectallofyourchangesuntilafterreboot.Warning:WARNING:thekernelfailedtore-readthepartitiontableon/dev/sdb(Deviceorresourcebusy).Asaresult,itmaynotreflectallofyourchangesuntilafterreboot.Warning:Unabletoopen/dev/sr0read-write(Read-onlyfilesystem)./dev/sr0hasbeenopenedread-only.Warning:Unabletoopen/dev/sr0read-write(Read-onlyfilesystem)./dev/sr0hasbeenopenedread-only.Error:Invalidpartitiontable-recursivepartitionon/dev/sr0.3.创建物理卷

[root@localhost~]#fdisk-lDisk/dev/sda:21.5GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00083529DeviceBootStartEndBlocksIdSystem/dev/sda1*16451200083LinuxPartition1doesnotendoncylinderboundary./dev/sda2642611204584968eLinuxLVMDisk/dev/sdb:21.5GB,21474836480bytes255heads,63sectors/track,2610cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0xac7c929bDeviceBootStartEndBlocksIdSystem/dev/sdb11261020964793+8eLinuxLVMDisk/dev/mapper/VolGroup-lv_root:18.8GB,18798870528bytes255heads,63sectors/track,2285cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00000000Disk/dev/mapper/VolGroup-lv_swap:2147MB,2147483648bytes255heads,63sectors/track,261cylindersUnits=cylindersof16065*512=8225280bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00000000[root@localhost~]#pvcreate/dev/sdb1#由fdisk-l查到LVM卷是/dev/sdb1,所以用/dev/sdb1来创建物理卷。Physicalvolume"/dev/sdb1"successfullycreated4.扩展卷组

[root@localhost~]#pvdisplay---Physicalvolume---PVName/dev/sda2VGNameVolGroupPVSize19.51GiB/notusable3.00MiBAllocatableyes(butfull)PESize4.00MiBTotalPE4994FreePE0AllocatedPE4994PVUUIDqkBdcn-RQaR-ZliO-Ja2S-RhMC-stw8-CO213I"/dev/sdb1"isanewphysicalvolumeof"19.99GiB"---NEWPhysicalvolume---PVName/dev/sdb1VGNamePVSize19.99GiBAllocatableNOPESize0TotalPE0FreePE0AllocatedPE0PVUUIDH7tDqG-6AZv-yBSA-U0ov-Ni0y-dlPA-kAA83i[root@localhost~]#vgextendVolGroup/dev/sdb1Volumegroup"VolGroup"successfullyextendedYouhavenewmailin/var/spool/mail/root[root@localhost~]#vgdisplay---Volumegroup---VGNameVolGroupSystemIDFormatlvm2MetadataAreas2MetadataSequenceNo4VGAccessread/writeVGStatusresizableMAXLV0CurLV2OpenLV2MaxPV0CurPV2ActPV2VGSize39.50GiBPESize4.00MiBTotalPE10112AllocPE/Size4994/19.51GiBFreePE/Size5118/19.99GiBVGUUIDdc0vI9-KzGu-4S59-A1xv-NM4Y-rYBF-3jDNRn5.扩展逻辑卷

[root@localhost~]#lvextend-l+100%free/dev/mapper/VolGroup-lv_root#free也可以大写FREEExtendinglogicalvolumelv_rootto37.50GiBLogicalvolumelv_rootsuccessfullyresized[root@localhost~]#blkid/dev/mapper/VolGroup-lv_root#查看分区文件系统类型/dev/mapper/VolGroup-lv_root:UUID="972fdddd-ddb8-469f-a342-e075eaeabeb2"TYPE="ext4"[root@localhost~]#e2fsck-f/dev/mapper/VolGroup-lv_root#e2fsck-f检查分区e2fsck1.41.12(17-May-2010)/dev/mapper/VolGroup-lv_rootismounted.e2fsck:Cannotcontinue,aborting.[root@localhost~]#resize2fs/dev/mapper/VolGroup-lv_root#如果分区是xfs系统,则用xfs_growfs命令对文件系统进行扩展resize2fs1.41.12(17-May-2010)Filesystemat/dev/mapper/VolGroup-lv_rootismountedon/;on-lineresizingrequiredolddesc_blocks=2,new_desc_blocks=3Performinganon-lineresizeof/dev/mapper/VolGroup-lv_rootto9830400(4k)blocks.Thefilesystemon/dev/mapper/VolGroup-lv_rootisnow9830400blockslong.[root@localhost~]#df-h#查看磁盘空间,根分区已扩展到37G。FilesystemSizeUsedAvailUse%Mountedon/dev/mapper/VolGroup-lv_root37G7.0G29G20%/tmpfs2.0G224K2.0G1%/dev/shm/dev/sda1485M40M421M9%/boot/dev/sr03.6G3.6G0100%/media/cdrom

关于“Linux系统中怎么扩展根分区”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。