700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > CentOS7的LVM动态扩容

CentOS7的LVM动态扩容

时间:2021-03-06 01:33:23

相关推荐

CentOS7的LVM动态扩容

问题

CentOS7上面的磁盘空间有点紧张,需要扩容。

解决

查询当前磁盘状态

[root@xxx ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTfd02:0 1 4K 0 disk sda8:0 0 200G 0 disk ├─sda1 8:1 0 500M 0 part /boot└─sda2 8:2 0 15.5G 0 part ├─centos-swap 253:0 0 1.6G 0 lvm [SWAP]└─centos-root 253:1 0 13.9G 0 lvm /sr0 11:0 1 1024M 0 rom loop0 7:0 0 4.3G 0 loop /mnt/iso

查询当前文件系统状态

[root@xxx ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 14G 14G 20K 100% /devtmpfs 3.8G0 3.8G 0% /devtmpfs3.9G0 3.9G 0% /dev/shmtmpfs3.9G 442M 3.4G 12% /runtmpfs3.9G0 3.9G 0% /sys/fs/cgroup/dev/sda1497M 295M 202M 60% /boottmpfs782M 12K 782M 1% /run/user/42/dev/loop04.3G 4.3G0 100% /mnt/isotmpfs782M0 782M 0% /run/user/0

查看当前磁盘分区情况

[root@xxx ~]# gdisk /dev/sdaGPT fdisk (gdisk) version 0.8.10Partition table scan:MBR: MBR onlyBSD: not presentAPM: not presentGPT: not present***************************************************************Found invalid GPT and valid MBR; converting MBR to GPT formatin memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit bytyping 'q' if you don't want to convert your MBR partitionsto GPT format!***************************************************************Command (? for help): pDisk /dev/sda: 419430400 sectors, 200.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): FE64D670-2841-445E-974F-12A258105C57Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 419430366Partitions will be aligned on 2048-sector boundariesTotal free space is 385877949 sectors (184.0 GiB)Number Start (sector) End (sector) Size Code Name1 2048 1026047 500.0 MiB 8300 Linux filesystem2 1026048 33554431 15.5 GiB 8E00 Linux LVM

lvm扩容

创建8e

[root@xxx ~]# gdisk /dev/sdaGPT fdisk (gdisk) version 0.8.10Partition table scan:MBR: MBR onlyBSD: not presentAPM: not presentGPT: not present***************************************************************Found invalid GPT and valid MBR; converting MBR to GPT formatin memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit bytyping 'q' if you don't want to convert your MBR partitionsto GPT format!***************************************************************Command (? for help): nPartition number (3-128, default 3): First sector (34-419430366, default = 33554432) or {+-}size{KMGTP}: Last sector (33554432-419430366, default = 419430366) or {+-}size{KMGTP}: +84GCurrent type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): L0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot 4200 Windows LDM data4201 Windows LDM metadata 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem8301 Linux reserved8302 Linux /home 8400 Intel Rapid Start8e00 Linux LVM a500 FreeBSD disklabela501 FreeBSD boota502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID a580 Midnight BSD dataa581 Midnight BSD boota582 Midnight BSD swap a583 Midnight BSD UFSa584 Midnight BSD ZFSa585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap a902 NetBSD FFSa903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+af01 Apple RAID af02 Apple RAID offline af03 Apple label af04 AppleTV recoveryaf05 Apple Core Storage be00 Solaris boot bf00 Solaris rootbf01 Solaris /usr & Mac Z bf02 Solaris swap bf03 Solaris backup bf04 Solaris /varbf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partitPress the <Enter> key to see more codes: 8e00ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash pfd00 Linux RAID Hex code or GUID (L to show codes, Enter = 8300): 8e00Changed type of partition to 'Linux LVM'Command (? for help): pDisk /dev/sda: 419430400 sectors, 200.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): F8A75D30-20AF-412A-A7CD-F66D4A57D232Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 419430366Partitions will be aligned on 2048-sector boundariesTotal free space is 209717181 sectors (100.0 GiB)Number Start (sector) End (sector) Size Code Name1 2048 1026047 500.0 MiB 8300 Linux filesystem2 1026048 33554431 15.5 GiB 8E00 Linux LVM3 33554432 209715199 84.0 GiB 8E00 Linux LVMCommand (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): yOK; writing new GUID partition table (GPT) to /dev/sda.Warning: The kernel is still using the old partition table.The new table will be used at the next reboot.The operation has completed successfully.

这里需要注意的地方就是,扩容了84G,并且使用8e00。

更新8e

[root@xxx ~]# partprobe -s/dev/sda: gpt partitions 1 2 3[root@xxx ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTfd02:0 1 4K 0 disk sda8:0 0 200G 0 disk ├─sda1 8:1 0 500M 0 part /boot├─sda2 8:2 0 15.5G 0 part │ ├─centos-swap 253:0 0 1.6G 0 lvm [SWAP]│ └─centos-root 253:1 0 13.9G 0 lvm /└─sda3 8:3 0 84G 0 part sr0 11:0 1 1024M 0 rom loop0 7:0 0 4.3G 0 loop /mnt/iso

验证8e

[root@xxx ~]# gdisk -l /dev/sdaGPT fdisk (gdisk) version 0.8.10Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Disk /dev/sda: 419430400 sectors, 200.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): F8A75D30-20AF-412A-A7CD-F66D4A57D232Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 419430366Partitions will be aligned on 2048-sector boundariesTotal free space is 209717181 sectors (100.0 GiB)Number Start (sector) End (sector) Size Code Name1 2048 1026047 500.0 MiB 8300 Linux filesystem2 1026048 33554431 15.5 GiB 8E00 Linux LVM3 33554432 209715199 84.0 GiB 8E00 Linux LVM

PV阶段

现有PV

[root@xxx ~]# pvdisplay--- Physical volume ---PV Name/dev/sda2VG NamecentosPV Size15.51 GiB / not usable 3.00 MiBAllocatable yes (but full)PE Size4.00 MiBTotal PE 3970Free PE0Allocated PE3970PV UUIDS13vMN-W0wQ-HCae-fPKa-bClZ-RzW0-39xc9C

现在PV的大小是15G。

创建PV

[root@xxx ~]# pvcreate /dev/sda3Physical volume "/dev/sda3" successfully created.

验证PV

[root@xxx ~]# pvdisplay --- Physical volume ---PV Name/dev/sda2VG NamecentosPV Size15.51 GiB / not usable 3.00 MiBAllocatable yes (but full)PE Size4.00 MiBTotal PE 3970Free PE0Allocated PE3970PV UUIDS13vMN-W0wQ-HCae-fPKa-bClZ-RzW0-39xc9C"/dev/sda3" is a new physical volume of "84.00 GiB"--- NEW Physical volume ---PV Name/dev/sda3VG NamePV Size84.00 GiBAllocatable NOPE Size0 Total PE 0Free PE0Allocated PE0PV UUIDSsb5Y6-gD5q-heAE-sil9-oIU3-kdX8-B0pqLS

VG阶段

现有VG

[root@xxx ~]# vgdisplay--- Volume group ---VG NamecentosSystem ID Formatlvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV0Cur LV2Open LV2Max PV0Cur PV1Act PV1VG Size<15.51 GiBPE Size4.00 MiBTotal PE 3970Alloc PE / Size 3970 / <15.51 GiBFree PE / Size 0 / 0 VG UUIDF3IvIs-uz92-m9d6-XYYL-0QvN-xqs8-qxD9fC

VG也是15G。

扩容VG

[root@xxx ~]# vgextend centos /dev/sda3Volume group "centos" successfully extended

在这个阶段遇到Couldn't create temporary archive name.问题,只需要清理一部分无用文件腾出一点点磁盘空间即可。

验证VG

[root@xxx ~]# vgdisplay --- Volume group ---VG NamecentosSystem ID Formatlvm2Metadata Areas 2Metadata Sequence No 5VG Access read/writeVG Status resizableMAX LV0Cur LV2Open LV2Max PV0Cur PV2Act PV2VG Size99.50 GiBPE Size4.00 MiBTotal PE 25473Alloc PE / Size 3970 / <15.51 GiBFree PE / Size 21503 / <84.00 GiBVG UUIDF3IvIs-uz92-m9d6-XYYL-0QvN-xqs8-qxD9fC

Free部分已经不是0了。

LV阶段

现有LV

[root@xxx ~]# lvdisplay --- Logical volume ---LV Path/dev/centos/swapLV NameswapVG NamecentosLV UUIDc2sXrl-GC3c-nXbi-lED4-MqXx-5FPx-872laMLV Write Access read/writeLV Creation host, time , -06-26 12:02:56 +0800LV Status available# open 2LV Size1.60 GiBCurrent LE 410Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:0--- Logical volume ---LV Path/dev/centos/rootLV NamerootVG NamecentosLV UUIDr2qZe6-X3zx-D7te-U0t0-iJDF-VyWf-xl5by8LV Write Access read/writeLV Creation host, time , -06-26 12:02:57 +0800LV Status available# open 1LV Size<13.91 GiBCurrent LE 3560Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:1

这里主要扩容这个LV:/dev/centos/root。

扩容LV

[root@xxx ~]# lvresize -L +83.99GB /dev/centos/rootRounding size to boundary between physical extents: 83.99 GiB.Size of logical volume centos/root changed from <13.91 GiB (3560 extents) to <97.90 GiB (25062 extents).Logical volume centos/root successfully resized

验证LV

[root@xxx ~]# lvdisplay --- Logical volume ---LV Path/dev/centos/swapLV NameswapVG NamecentosLV UUIDc2sXrl-GC3c-nXbi-lED4-MqXx-5FPx-872laMLV Write Access read/writeLV Creation host, time , -06-26 12:02:56 +0800LV Status available# open 2LV Size1.60 GiBCurrent LE 410Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:0--- Logical volume ---LV Path/dev/centos/rootLV NamerootVG NamecentosLV UUIDr2qZe6-X3zx-D7te-U0t0-iJDF-VyWf-xl5by8LV Write Access read/writeLV Creation host, time , -06-26 12:02:57 +0800LV Status available# open 1LV Size<97.90 GiBCurrent LE 25062Segments2Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:1

更新扩容

[root@xxx ~]# xfs_growfs /meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=911360 blks= sectsz=512 attr=2, projid32bit=1= crc=0 finobt=0 spinodes=0data= bsize=4096 blocks=3645440, imaxpct=25= sunit=0swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log=internalbsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 3645440 to 25663488

验证扩容

[root@xxx ~]# df -lh文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 98G 14G 84G 15% /devtmpfs 3.8G0 3.8G 0% /devtmpfs3.9G0 3.9G 0% /dev/shmtmpfs3.9G 442M 3.4G 12% /runtmpfs3.9G0 3.9G 0% /sys/fs/cgroup/dev/sda1497M 295M 202M 60% /boottmpfs782M 12K 782M 1% /run/user/42/dev/loop04.3G 4.3G0 100% /mnt/isotmpfs782M0 782M 0% /run/user/0

总结

主要就是创建8e分区,然后用pvcreate命令创建PV,再使用vgextend命令来扩容VG,再使用lvresize命令扩容LV,最后使用xfs_growfs命令更新扩容。

参考

第十四章、磁碟配額(Quota)與進階檔案系統管理

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。