CentOS7中怎么动态扩容LVM
这期内容当中小编将会给大家带来有关CentOS7中怎么动态扩容LVM,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
创新互联公司-专业网站定制、快速模板网站建设、高性价比潮安网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式潮安网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖潮安地区。费用合理售后完善,10余年实体公司更值得信赖。
问题
CentOS7上面的磁盘空间有点紧张,需要扩容。
解决
查询当前磁盘状态
[root@xxx ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8: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.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 442M 3.4G 12% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 497M 295M 202M 60% /boot tmpfs 782M 12K 782M 1% /run/user/42 /dev/loop0 4.3G 4.3G 0 100% /mnt/iso tmpfs 782M 0 782M 0% /run/user/0
查看当前磁盘分区情况
[root@xxx ~]# gdisk /dev/sda GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! *************************************************************** Command (? for help): p Disk /dev/sda: 419430400 sectors, 200.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): FE64D670-2841-445E-974F-12A258105C57 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 419430366 Partitions will be aligned on 2048-sector boundaries Total free space is 385877949 sectors (184.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1026047 500.0 MiB 8300 Linux filesystem 2 1026048 33554431 15.5 GiB 8E00 Linux LVM
lvm扩容
创建8e
[root@xxx ~]# gdisk /dev/sda GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! *************************************************************** Command (? for help): n Partition number (3-128, default 3): First sector (34-419430366, default = 33554432) or {+-}size{KMGTP}: Last sector (33554432-419430366, default = 419430366) or {+-}size{KMGTP}: +84G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): L 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS a903 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 recovery af05 Apple Core Storage be00 Solaris boot bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var bf05 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 partit Press thekey to see more codes: 8e00 ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p fd00 Linux RAID Hex code or GUID (L to show codes, Enter = 8300): 8e00 Changed type of partition to 'Linux LVM' Command (? for help): p Disk /dev/sda: 419430400 sectors, 200.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): F8A75D30-20AF-412A-A7CD-F66D4A57D232 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 419430366 Partitions will be aligned on 2048-sector boundaries Total free space is 209717181 sectors (100.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1026047 500.0 MiB 8300 Linux filesystem 2 1026048 33554431 15.5 GiB 8E00 Linux LVM 3 33554432 209715199 84.0 GiB 8E00 Linux LVM Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; 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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8: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/sda GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/sda: 419430400 sectors, 200.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): F8A75D30-20AF-412A-A7CD-F66D4A57D232 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 419430366 Partitions will be aligned on 2048-sector boundaries Total free space is 209717181 sectors (100.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1026047 500.0 MiB 8300 Linux filesystem 2 1026048 33554431 15.5 GiB 8E00 Linux LVM 3 33554432 209715199 84.0 GiB 8E00 Linux LVM
PV阶段
现有PV
[root@xxx ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 15.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 3970 Free PE 0 Allocated PE 3970 PV UUID S13vMN-W0wQ-HCae-fPKa-bClZ-RzW0-39xc9C
现在PV的大小是15G。
创建PV
[root@xxx ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created.
验证PV
[root@xxx ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 15.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 3970 Free PE 0 Allocated PE 3970 PV UUID S13vMN-W0wQ-HCae-fPKa-bClZ-RzW0-39xc9C "/dev/sda3" is a new physical volume of "84.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 84.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID Ssb5Y6-gD5q-heAE-sil9-oIU3-kdX8-B0pqLS
VG阶段
现有VG
[root@xxx ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <15.51 GiB PE Size 4.00 MiB Total PE 3970 Alloc PE / Size 3970 / <15.51 GiB Free PE / Size 0 / 0 VG UUID F3IvIs-uz92-m9d6-XYYL-0QvN-xqs8-qxD9fC
VG也是15G。
扩容VG
[root@xxx ~]# vgextend centos /dev/sda3 Volume group "centos" successfully extended
在这个阶段遇到Couldn't create temporary archive name.
问题,只需要清理一部分无用文件腾出一点点磁盘空间即可。
验证VG
[root@xxx ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 99.50 GiB PE Size 4.00 MiB Total PE 25473 Alloc PE / Size 3970 / <15.51 GiB Free PE / Size 21503 / <84.00 GiB VG UUID F3IvIs-uz92-m9d6-XYYL-0QvN-xqs8-qxD9fC
Free部分已经不是0了。
LV阶段
现有LV
[root@xxx ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID c2sXrl-GC3c-nXbi-lED4-MqXx-5FPx-872laM LV Write Access read/write LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:56 +0800 LV Status available # open 2 LV Size 1.60 GiB Current LE 410 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID r2qZe6-X3zx-D7te-U0t0-iJDF-VyWf-xl5by8 LV Write Access read/write LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:57 +0800 LV Status available # open 1 LV Size <13.91 GiB Current LE 3560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1
这里主要扩容这个LV:/dev/centos/root。
扩容LV
[root@xxx ~]# lvresize -L +83.99GB /dev/centos/root Rounding 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/swap LV Name swap VG Name centos LV UUID c2sXrl-GC3c-nXbi-lED4-MqXx-5FPx-872laM LV Write Access read/write LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:56 +0800 LV Status available # open 2 LV Size 1.60 GiB Current LE 410 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID r2qZe6-X3zx-D7te-U0t0-iJDF-VyWf-xl5by8 LV Write Access read/write LV Creation host, time tamtest.hngytobacco.com, 2017-06-26 12:02:57 +0800 LV Status available # open 1 LV Size <97.90 GiB Current LE 25062 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block 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=0 data = bsize=4096 blocks=3645440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 3645440 to 25663488
验证扩容
[root@xxx ~]# df -lh 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 98G 14G 84G 15% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 442M 3.4G 12% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 497M 295M 202M 60% /boot tmpfs 782M 12K 782M 1% /run/user/42 /dev/loop0 4.3G 4.3G 0 100% /mnt/iso tmpfs 782M 0 782M 0% /run/user/0
总结
主要就是创建8e分区,然后用pvcreate命令创建PV,再使用vgextend命令来扩容VG,再使用lvresize命令扩容LV,最后使用xfs_growfs命令更新扩容。
上述就是小编为大家分享的CentOS7中怎么动态扩容LVM了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。
分享文章:CentOS7中怎么动态扩容LVM
路径分享:http://pwwzsj.com/article/igccej.html