This is the 9th day of my participation in Gwen Challenge
One, foreword
Mysql: /home/mysql: /home/mysql: /home/mysql: /home/mysql: /home
[superadmin@localhost ~]# LSBLK NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:00600G 0 Disk ├─sda1 8:101g 0 Part / boot └ ─ sda2 0 0 199 G lo part ├ ─ centos - root 253:50 G 0 0 0 LVM / ├ ─ centos - swap 253:3.9 G 1 0 0 LVM/swap └ ─ centos - home 253:2 145.1g 0 LVM /home SR0 11:01 4.5g 0 ROMCopy the code
[superadmin@localhost home]# du -h --max-depth=1 |grep 'G' |sort
118G ./mysql8
145G .
25G ./nacos
Copy the code
On disk, we can see that SDA allocated 600GB of memory, but only two SDA1 and SDA2 are allocated. 400GB of memory is still unallocated, which is very wasteful, so we need to create a new partition first.
2. Create a partition
After the new partition is created, you need to refresh the partition to see the new partition Sda3.
Allocate 300GB of memory to the new partition and 100GB to spare.
[superadmin@localhost home]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2) Changes stay in memory until you decide to write them to disk. Think twice before using write commands. N Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default P): P Partition number (3,4, default 3) : 3 Start sector (419430400-1258291199, default 419430400) : 419430400 Last sector, + sector or +size{K,M,G} (419430400-1258291199, default 1258291199) : 1048575999 Partition 3 has been set to Linux and The size has been set to 300 GiB command (enter m to obtain help) : w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: The device or resource is busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or Kpartx (8) is synchronizing disks. [superadmin@localhost home]# LSBLK NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:00600G 0 Disk ├─ Sda1 8:101g 0 Part / boot └ ─ sda2 0 0 199 G lo part ├ ─ centos - root 253:50 G 0 0 0 LVM / ├ ─ centos - swap 253:3.9 G 1 0 0 LVM/swap └ ─ centos - home 253:20 145.1g 0 LVM /home sr0 11:01 4.5g 0 ROM [superadmin@localhost home]# partprobe /dev/sda [superadmin@localhost Home]# LSBLK NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0000G 0 Disk ├─ Sda1 8:101g 0 Part/Boot ├─sda2 8:20 199 G 0 part │ ├ ─ centos - root 253:50 G 0 0 0 LVM / │ ├ ─ centos - swap 253:3.9 G 1 0 0 LVM/swap │ └ ─ centos - home 253:2 0 145.1 G 0 LVM/home └ ─ sda3 and 0 0 300 G part sr0 11:0 1 4.5 G 0 ROMCopy the code
Allocate memory
1. Create the sDA3 partition as a physical volume
[superadmin@localhost home]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
Copy the code
2. Expand the created physical volume to the volume group where /home resides
[superadmin@localhost home]# vgdisplay -v --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size <199.00 GiB PE Size 4.00 MiB Total PE 50943 Alloc PE/Size 50942/198.99 GiB Free PE/Size 1/4.00 MiB VG UUID ditVGC-NFOL-cOTM-fW4Z-Btv4-yKLW-T1riU6 --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID DHEcu3-r7yQ-dcKB-ZvBV-1aZl-gbPT-CFGmf0 LV Write Access read/write LV Creation host, time localhost, 2020-06-15 23:32:37 +0800 LV Status available # open 2 LV Size <3.88 GiB Current LE 992 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/home # LV Name home VG Name centos # LV UUID kv17cJ-XC2V-OLzV-5TL0-w1qm-UD5y-c8PBwo LV Write Access read/write LV Creation host, time localhost, 2020-06-15 23:32:37 +0800 LV Status available # open 1 LV Size <145.12 GiB Current LE 37150 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/centos/root = /dev/root = /dev/root = /dev/root = /dev/root bA2a4N-7Alz-xNyU-FcWX-t8eX-Q4E8-ELqf8o LV Write Access read/write LV Creation host, time localhost, 2020-06-15 23:32:37 +0800 LV Status available # open 1 LV Size 50.00 GiB Current LE 12800 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Physical volumes --- PV Name /dev/sda2 PV UUID hpbzq1-xMEL-PeVv-veFD-hrB2-13be-hjzcZr PV Status allocatable Total PE / Free PE 50943 / 1Copy the code
Expanding volume group capacity:
[superadmin@localhost home]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
Copy the code
3. Expand the logical volume path mounted to the /home partition and make the expansion take effect
/dev/centos/home [superadmin@localhost home]# lvextend -l +100%FREE /dev/centos/home Size of logical Volume centos/home changed from <145.12 GiB (37150 extents) to <445.12 GiB (113950 extents). Logical Volume centos/home successfully resized. [superadmin@localhost home]# xfs_growfs /dev/centos/home meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=9510400 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=38041600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=18575, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 38041600 to 116684800Copy the code
4. Check the capacity of the expanded /home partition
[superadmin@localhost home]# LSBLK NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:00600G 0 Disk ├─ Sda1 8:101g 0 Part / │ ├─ Heavy Metal Flag school - part │ ├─ Heavy metal Flag school - Heavy metal Flag school - Heavy metal Flag - Heavy metal Flag school - Heavy metal Flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag - Heavy metal flag └ ─ centos - home 253:445.1 G 2 0 0 LVM/home └ ─ sda3 and 0 0 300 G part └ ─ centos - home 253:445.1 G 2 0 0 LVM/home sr0 11:0 1 4.5 G 0 ROMCopy the code
Finally, you’re done!