原来/dev/sda是500G,后续扩展到了1T ,查看硬盘信息,Disk /dev/sda: 1099.5 GB可以看到容量已经添加进来。

[root@master-99 ~]# fdisk -l

Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 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: 0x000a052c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1048575999   523238400   8e  Linux LVM

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 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: 0x000e2d5c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048575999   524286976   8e  Linux LVM

Disk /dev/mapper/centos-root: 531.6 GB, 531628032000 bytes, 1038336000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/VolGroup_master99-pv_master99: 515.4 GB, 515396075520 bytes, 1006632960 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

如果fdisk -l看不到新增加容量,可以执行

ls /sys/class/scsi_disk/
0:0:0:0
echo 1 >/sys/class/scsi_disk/0\:0\:0\:0/device/rescan
#注意这里的对应磁盘关系
#[root@master-99 ~]# ls /sys/class/scsi_disk/
#0:0:0:0  0:0:1:0
#[root@master-99 ~]# 
#这个机器显示有两个盘

image
此次添加容量的方式为添加pv组,再来扩展

添加分区

[root@master-99 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 1
Value out of range.
Partition number (3,4, default 3): 3
First sector (1048576000-2147483647, default 1048576000): 
Using default value 1048576000
Last sector, +sectors or +size{K,M,G} (1048576000-2147483647, default 2147483647): 
Using default value 2147483647
Partition 3 of type Linux and of size 524 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 8e
Partition number (1-3, default 3): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for 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: Device or resource 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)
Syncing disks.

查看是否生效

[root@master-99 ~]# fdisk -l

Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 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: 0x000a052c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1048575999   523238400   8e  Linux LVM
/dev/sda3      1048576000  2147483647   549453824   8e  Linux LVM

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 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: 0x000e2d5c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048575999   524286976   8e  Linux LVM

Disk /dev/mapper/centos-root: 531.6 GB, 531628032000 bytes, 1038336000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/VolGroup_master99-pv_master99: 515.4 GB, 515396075520 bytes, 1006632960 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

/dev/sda3已经生成

添加pv

查看现有的pv

[root@master-99 ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <499.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              127743
  Free PE               1
  Allocated PE          127742
  PV UUID               dqCdkC-5dIt-1oFV-1dfo-rtby-37Gz-8HRVUI
   
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               VolGroup_master99
  PV Size               <500.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              127999
  Free PE               5119
  Allocated PE          122880
  PV UUID               ENqOjD-gr6J-mfqM-GVYC-zMsc-2BNY-3jDuXK

创建pv,partprobe是同步磁盘状态命令必须要,否则报找不到sda3的报错

[root@master-99 ~]# partprobe
[root@master-99 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.

Pv创建成功

创建vg

查看vg

[root@master-99 ~]# 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               <499.00 GiB
  PE Size               4.00 MiB
  Total PE              127743
  Alloc PE / Size       127742 / 498.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               fbJzNI-33fm-gAdr-wYnU-6fcg-HcRm-qG6WPV
   
  --- Volume group ---
  VG Name               VolGroup_master99
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <500.00 GiB
  PE Size               4.00 MiB
  Total PE              127999
  Alloc PE / Size       122880 / 480.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               DftoEH-sjvA-Qx8A-J0WE-Hv3y-UX5J-SW3431

centos在这里对应的是根目录的lv挂载,所以对名为centos的vg进行扩展

[root@master-99 ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended

扩展lv

查看lv卷

[root@master-99 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                aAfIij-18cD-v0m3-WbOl-lieu-J50M-gI2yNZ
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-12-23 18:52:05 +0800
  LV Status              available
  # open                 1
  LV Size                <495.12 GiB
  Current LE             126750
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                OeW85N-8fPQ-CTcj-Atfs-Kv2L-sHF4-R5dbtp
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-12-23 18:52:06 +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/VolGroup_master99/pv_master99
  LV Name                pv_master99
  VG Name                VolGroup_master99
  LV UUID                5Gkijh-dxNB-rctp-ogkN-zUcl-gC9L-JhYeQB
  LV Write Access        read/write
  LV Creation host, time master-99, 2022-03-31 23:28:53 +0800
  LV Status              available
  # open                 1
  LV Size                480.00 GiB
  Current LE             122880
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

/dev/centos/root对应的vg为centos,所以对/dev/centos/root进行扩展

[root@master-99 ~]# lvextend -l +100%free /dev/centos/root
  Size of logical volume centos/root changed from <495.12 GiB (126750 extents) to <1019.12 GiB (260894 extents).
  Logical volume centos/root successfully resized.
[root@master-99 ~]# df -h |grep -v var
Filesystem                                 Size  Used Avail Use% Mounted on
devtmpfs                                    16G     0   16G   0% /dev
tmpfs                                       16G     0   16G   0% /dev/shm
tmpfs                                       16G   14M   16G   1% /run
tmpfs                                       16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root                    495G  324G  172G  66% /
/dev/sda1                                 1014M  153M  862M  16% /boot
/dev/mapper/VolGroup_master99-pv_master99  473G   64G  386G  15% /root/tools
tmpfs                                      3.2G     0  3.2G   0% /run/user/0

刷新磁盘

[root@master-99 ~]#  xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=32448000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=129792000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=63375, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 129792000 to 267155456

查看效果,可以看到/dev/mapper/centos-root已经扩展到1T

[root@master-99 ~]# df -h |grep -v var
Filesystem                                 Size  Used Avail Use% Mounted on
devtmpfs                                    16G     0   16G   0% /dev
tmpfs                                       16G     0   16G   0% /dev/shm
tmpfs                                       16G   14M   16G   1% /run
tmpfs                                       16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root                   1019G  324G  696G  32% /
/dev/sda1                                 1014M  153M  862M  16% /boot
/dev/mapper/VolGroup_master99-pv_master99  473G   64G  386G  15% /root/tools
tmpfs                                      3.2G     0  3.2G   0% /run/user/0

Q.E.D.


知之为知之