Linux system disk expansion

This machine is CentOS7.9, and the Linux system disk is expanded in the virtual machine environment. Directly adding a hard disk cannot be used, and a disk mount operation needs to be performed inside the system.

  1. Add disk to virtual machine
    add disk
  2. View system disk partition type
[root@Para110 ~]# fdisk /dev/sda  //列出系统分区
欢迎使用 fdisk (util-linux 2.23.2)

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):p  //查看分区信息

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b146f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

命令(输入 m 获取帮助):q  //不保存退出
  1. Partition the new hard disk and set the partition type
[root@Para110 ~]# lsblk  //列出所有可用块设备的信息
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   40G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   39G  0 part 
  ├─centos-root 253:0    0   35G  0 lvm  /
  └─centos-swap 253:1    0    4G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
└─sdb1            8:17   0    5G  0 part 
sr0              11:0    1  4.5G  0 rom 
  1. view partition
[root@Para110 ~]# pvcreate /dev/sdb1  //将物理硬盘分区初始化为物理卷
  Physical volume "/dev/sdb1" successfully created.
  1. Let the newly added hard disk partition support LVM technology
[root@Para110 ~]# pvcreate /dev/sdb1  //将物理硬盘分区初始化为物理卷
  Physical volume "/dev/sdb1" successfully created.
  1. View the volume group of the current system, and add the /dev/sdb1 hard disk partition to the volume group
[root@Para110 ~]# vgdisplay  //显示LVM卷组的信息
  --- 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               <39.00 GiB
  PE Size               4.00 MiB
  Total PE              9983
  Alloc PE / Size       9983 / <39.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               upMhKG-R5K4-zRdM-myqH-sZJ7-BDDx-0cBXEH
   
[root@Para110 ~]# vgextend centos /dev/sdb1  //把/dev/sdb1硬盘分区加入到centos卷组中
  Volume group "centos" successfully extended
[root@Para110 ~]# vgdisplay  //显示LVM卷组的信息
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               43.99 GiB
  PE Size               4.00 MiB
  Total PE              11262
  Alloc PE / Size       9983 / <39.00 GiB
  Free  PE / Size       1279 / <5.00 GiB
  VG UUID               upMhKG-R5K4-zRdM-myqH-sZJ7-BDDx-0cBXEH
  1. View current logical volume information
[root@Para110 ~]# lvdisplay  //查看当前逻辑卷信息
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                bIb4Xp-ooix-2LXp-6HcD-ylES-tB2N-vYHomd
  LV Write Access        read/write
  LV Creation host, time para110, 2022-09-26 10:16:02 +0800
  LV Status              available
  # open                 2
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                uwUG8o-QTWK-um0m-UVpW-Y7rW-Nj0z-pilNtY
  LV Write Access        read/write
  LV Creation host, time para110, 2022-09-26 10:16:02 +0800
  LV Status              available
  # open                 1
  LV Size                <35.00 GiB
  Current LE             8959
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
  1. Expand the root logical volume
[root@Para110 ~]# lvextend -l +1279 /dev/centos/root
  Insufficient free space: 1279 extents needed, but only 959 available
[root@Para110 ~]# lvextend -l +959 /dev/centos/root  //进行扩容
  Size of logical volume centos/root changed from <36.25 GiB (9279 extents) to 39.99 GiB (10238 extents).
  Logical volume centos/root successfully resized.
[root@Para110 ~]# lvdisplay  //显示逻辑卷属性
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                bIb4Xp-ooix-2LXp-6HcD-ylES-tB2N-vYHomd
  LV Write Access        read/write
  LV Creation host, time para110, 2022-09-26 10:16:02 +0800
  LV Status              available
  # open                 2
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                uwUG8o-QTWK-um0m-UVpW-Y7rW-Nj0z-pilNtY
  LV Write Access        read/write
  LV Creation host, time para110, 2022-09-26 10:16:02 +0800
  LV Status              available
  # open                 1
  LV Size                39.99 GiB
  Current LE             10238
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  1. Reset the size of the root logical volume
[root@Para110 ~]# df -h  //显示磁盘使用的文件系统信息
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 3.8G     0  3.8G    0% /dev
tmpfs                    3.9G   16K  3.9G    1% /dev/shm
tmpfs                    3.9G   13M  3.8G    1% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root   35G   11G   25G   30% /
/dev/sda1               1014M  186M  829M   19% /boot
tmpfs                    781M     0  781M    0% /run/user/0
tmpfs                    781M   12K  781M    1% /run/user/42
[root@Para110 ~]# xfs_growfs /dev/centos/root  //重置root逻辑卷大小
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2293504 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9174016, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4479, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9174016 to 10483712
  1. Linux system disk expansion operation completed
 [root@Para110 ~]# df -h  //显示磁盘使用的文件系统信息
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 3.8G     0  3.8G    0% /dev
tmpfs                    3.9G   16K  3.9G    1% /dev/shm
tmpfs                    3.9G   13M  3.8G    1% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root   40G   11G   30G   26% /
/dev/sda1               1014M  186M  829M   19% /boot
tmpfs                    781M     0  781M    0% /run/user/0
tmpfs                    781M   12K  781M    1% /run/user/42
 [root@Para110 ~]# pvs //格式化输出物理卷信息报表
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <39.00g    0 
  /dev/sdb1  centos lvm2 a--   <5.00g    0 

Guess you like

Origin blog.csdn.net/ahaahaj/article/details/127861293