Explain Centos7 Expansion Disk Space (LVM Management)

This article introduces Centos7 extended disk space (LVM management), and share it with you, as follows:

Check disk condition

# fdisk -l /dev/sda
Disk /dev/sda:21.5 GB,21474836480 bytes,41943040 sectors
Units = sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk label type: dos
Disk identifier:0x00063fa6

 Device Boot   Start     End   Blocks  Id System
/dev/sda1  *2048102604751200083 Linux
/dev/sda2     1026048209715199972736  8e Linux LVM
/dev/sda3    209715204194303910485760  8e Linux LVM

The disk size is now 21.5 GB. The disk usage is:

# df -h
Filesystem        Size Used Avail Use% Mounted on
/dev/mapper/centos-root  19G 8.1G  11G 44% /
devtmpfs         482M   0 482M  0%/dev
tmpfs          497M  88K 497M  1%/dev/shm
tmpfs          497M 7.0M 490M  2%/run
tmpfs          497M   0 497M  0%/sys/fs/cgroup
/dev/sda1        497M 157M 341M 32%/boot
Share          103G  36G  67G 35%/media/sf_Share
tmpfs          100M 4.0K 100M  1%/run/user/42
tmpfs          100M  12K 100M  1%/run/user/0

Try to use the dd command to create a block file with a size of 1GB:

# dd if=/dev/zero of=1.0G.img bs=1M count=1000
dd: writing `1.0G.img': No space left on device
1+0 records in0+0 records out
8192 bytes(8.2 kB) copied,0.00300509 s,2.7 MB/s

It prompts that the disk space is insufficient, indicating that although enough space has been allocated to the virtual machine, the system does not recognize the space.

Next, adjust the file system of the virtual machine operating system to make it recognize the newly added space

  1. Create new partition
# fdisk /dev/sda
n {newpartition}
p {primary partition}3{partition number}[At this time, you will be prompted to modify the size, select the default and press Enter directly]
t {change partition id}3{partition number}
8 e {Linux LVM partition}
w

If there is a prompt to set the size, just press Enter.

After completion, if prompted:

PS: After actual testing, there is no such prompt, but you still have to restart the system to see if the disk space has been recognized.

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)

Just restart the system.

  1. Check whether the newly added sda3 is marked as LVM, if not, reboot is required

PS: After actual testing, sda3 is already LVM, but the system still does not recognize the disk space.
3. Resize LVM

View Volume Group name

# vgdisplay
 - - - Volume group ---
 VG Name        centos
 System ID       
 Format        lvm2
  1. Create a new physical volume for the newly allocated space
# pvcreate /dev/sda3
  1. Use the new physical volume to extend the LVM VolGroup
# vgextend centos /dev/sda3
 No physical volume label read from/dev/sda3
 Writing physical volume data to disk "/dev/sda3"
 Physical volume "/dev/sda3" successfully created
 Volume group "vg_aimin" successfully extended
  1. Extend the LVM logical volume centos-root

First look at the logical volume:

# lvdisplay
 - - - Logical volume ---
 LV Path        /dev/centos/root
 LV Name        root
 VG Name        centos
# lvextend /dev/centos/root /dev/sda3
  1. Resize the logical volume
# xfs_growfs /dev/centos/root

PS: I don't know if it is adjustment or synchronization. After actual testing, you need to use the xfs_growfs command instead of the resize2fs command

  1. View Results
# lvscan
 ACTIVE      '/dev/centos/root'[18.46 GiB] inherit
 ACTIVE      '/dev/centos/swap'[1.00 GiB] inherit

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Explain Centos7 Expansion Disk Space (LVM Management)
Centos7 creates LVM disk management
LVM disk expansion problem of Centos7 in Linux
Ways to clear disk space on CentOS 6 or CentOS 7
centos system management
Online expansion of file system by LVM under Centos7
Centos system process management