centos Enterprise Flexible Expansion of the / home Directory (No Restart)

Requirements: On-line machine/home directory has insufficient memory and needs to expand memory to maintain the normal operation of the service

1. View the memory condition and configuration partition on the server

1. View disk information / home directory type is lvm logical volume

[root@GDI2154 ~]# lsblk
NAME                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   1.9T  0 disk 
├─sda1                    8:1    0     1G  0 part /boot
└─sda2                    8:2    0   1.9T  0 part     #sda2 is a logical volume
  ├─centos_gdi2154-root 253:0    0    50G  0 lvm  /
  ├─centos_gdi2154-swap 253:1    0  15.7G  0 lvm  [SWAP]
  └─centos_gdi2154-home 253:2    0   1.8T  0 lvm  /home
sdb                       8:16   0 931.5G  0 disk     #Free Disk
sdc                       8:32   0 931.5G  0 disk     #Free Disk

2. Partition the new disk sdb and sdc

[root@GDI2154 ~]# fdisk /dev/sdb
 Select n to create partitions - > Enter to allocate all memory by default - > w to save and exit (sdc same operation)
If the prompt is busy, the new partition information cannot be read. Partition tables can be re-read using the partprobe command

[root@GDI2154 ~]# lsblk 
NAME                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   1.9T  0 disk 
├─sda1                    8:1    0     1G  0 part /boot
└─sda2                    8:2    0   1.9T  0 part 
  ├─centos_gdi2154-root 253:0    0    50G  0 lvm  /
  ├─centos_gdi2154-swap 253:1    0  15.7G  0 lvm  [SWAP]
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home
sdb                       8:16   0 931.5G  0 disk 
└─sdb1                    8:17   0 931.5G  0 part 
sdc                       8:32   0 931.5G  0 disk 
└─sdc1                    8:33   0 931.5G  0 part 

2. Expanding the / home directory

1. Create SDB 1 and sdc1 as PV volumes

[root@GDI2154 ~]# pvcreate /dev/sdb1
[root@GDI2154 ~]# pvcreate /dev/sdc1

2. View VG Logical Volume Groups

[root@GDI2154 ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos_gdi2154    #Logical volume name
    ......

3. Add sdb1 and sdc1 to the logical volume centos_gdi2154 group

[root@GDI2154 ~]# vgextend centos_gdi2154 /dev/sdb1
[root@GDI2154 ~]# vgextend centos_gdi2154 /dev/sdc1

4. View the size of VG volume after expansion

[root@GDI2154 ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos_gdi2154
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               3.68 TiB    #After expansion, the capacity was increased from 1.8T to 3.7T.
  PE Size               4.00 MiB
  Total PE              965054
  Alloc PE / Size       965054 / 3.68 TiB
  Free  PE / Size       0 / 0   
  VG UUID               zEsTP2-8I61-FaU4-xMiI-ZpyL-x5Wv-ECcJhI

5. Look at the LV logical volume name and assign it all

[root@GDI2154 ~]# lvdisplay /dev/centos_gdi2154/home
  --- Logical volume ---
  LV Path                /dev/centos_gdi2154/home  #LV volume name
  LV Name                home
  VG Name                centos_gdi2154
    ......
[root@GDI2154 ~]# lvextend -l +100%FREE /dev/centos_gdi2154/home #Adding the remaining space to the logical volume

3. After expanding the logical volume, synchronize to the file system to achieve real directory expansion.

[root@GDI2154 ~]# Xfs_growfs/dev/centos_gdi2154/home (resize2fs/dev/centos_gdi2154/home is used in CentOS 6)

xfs_growfs Before command synchronization
[root@GDI2154 ~]# df -h
        ......
/dev/mapper/centos_gdi2154-home  1.8T  1.7T  187G  90% /home
    ......
    
xfs_growfs After command synchronization
[root@GDI2154 ~]# df -h
    ......
/dev/mapper/centos_gdi2154-home  3.7T  1.7T  2.0T  45% /home
    ......
    
//View the status of partitions
[root@GDI2154 ~]# lsblk 
NAME                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   1.9T  0 disk 
├─sda1                    8:1    0     1G  0 part /boot
└─sda2                    8:2    0   1.9T  0 part 
  ├─centos_gdi2154-root 253:0    0    50G  0 lvm  /
  ├─centos_gdi2154-swap 253:1    0  15.7G  0 lvm  [SWAP]
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home
sdb                       8:16   0 931.5G  0 disk 
└─sdb1                    8:17   0 931.5G  0 part 
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home`Insert code slices here`
sdc                       8:32   0 931.5G  0 disk 
└─sdc1                    8:33   0 931.5G  0 part 
  └─centos_gdi2154-home 253:2    0   3.6T  0 lvm  /home

So far, the expansion has been completed.

Note: 3. lvextend-l + 100% FREE can also be followed directly by the file system.
For example, "lvextend-l+100% FREE/dev/mapper/centos_gdi2154-home"
Or: "lvextend-l+100% FREE/dev/centos_gdi2154/home"
Later, synchronize with the xfs_growfs/dev/mapper/centos-root command

Tags: CentOS

Posted on Tue, 08 Oct 2019 14:20:12 -0700 by JamesWebster