实施的时候,有时候客户会让对linux的磁盘做扩容操作,以下简述下linux的 lvm磁盘扩容,后面有空水一贴非lvm的磁盘扩容 
 
扩容第一块磁盘从20G扩容30G 
[root@localhost ~]# df -h  
文件系统                 容量  已用  可用 已用% 挂载点 
devtmpfs                 475M     0  475M    0% /dev 
tmpfs                    487M     0  487M    0% /dev/shm 
tmpfs                    487M  7.7M  479M    2% /run 
tmpfs                    487M     0  487M    0% /sys/fs/cgroup 
/dev/mapper/centos-root   17G  1.3G   16G    8% / 
/dev/sda1               1014M  138M  877M   14% /boot 
tmpfs                     98M     0   98M    0% /run/user/0 
[root@localhost ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT 
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot 
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  / 
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP] 
sr0              11:0    1  4.4G  0 rom 
可以看到,sda第一块磁盘从20G扩容到了30G 
给扩容的容量进行临时分区,分到sda3 
[root@localhost ~]# fdisk /dev/sda 
欢迎使用 fdisk (util-linux 2.23.2)。 
 
更改将停留在内存中,直到您决定将更改写入磁盘。 
使用写入命令前请三思。 
 
 
命令(输入 m 获取帮助):n 
Partition type: 
   p   primary (2 primary, 0 extended, 2 free) 
   e   extended 
Select (default p): p 
分区号 (3,4,默认 3):3 
起始 扇区 (41943040-62914559,默认为 41943040): 
将使用默认值 41943040 
Last 扇区, +扇区 or +size{K,M,G} (41943040-62914559,默认为 62914559): 
将使用默认值 62914559 
分区 3 已设置为 Linux 类型,大小设为 10 GiB 
 
命令(输入 m 获取帮助):p 
 
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区 
Units = 扇区 of 1 * 512 = 512 bytes 
扇区大小(逻辑/物理):512 字节 / 512 字节 
I/O 大小(最小/最佳):512 字节 / 512 字节 
磁盘标签类型:dos 
磁盘标识符:0x000ad079 
 
   设备 Boot      Start         End      Blocks   Id  System 
/dev/sda1   *        2048     2099199     1048576   83  Linux 
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM 
/dev/sda3        41943040    62914559    10485760   83  Linux 
 
命令(输入 m 获取帮助):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 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) 
正在同步磁盘。 
[root@localhost ~]# partprobe /dev/sda 此处刷新磁盘sda分区 
[root@localhost ~]# pvcreate /dev/sda3 此处将sda3转换成pv 
查看当前VG 
[root@localhost ~]# 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               <19.00 GiB 
  PE Size               4.00 MiB 
  Total PE              4863 
  Alloc PE / Size       4863 / <19.00 GiB 
  Free  PE / Size       0 / 0 
  VG UUID               PuLHU1-ZYs4-xUi7-Tfr6-BhjE-a83Z-3hgWwH 
将/dev/sda3的pv加入VG centos 
[root@localhost ~]# vgextend centos /dev/sda3 
  Volume group "centos" successfully extended 
查看当前的lv,结合之前lsblk的数据,判断/分区为/dev/centos(vg)/root(lv) 
[root@localhost ~]# lvdisplay 
  --- Logical volume --- 
  LV Path                /dev/centos/root 
  LV Name                root 
  VG Name                centos 
  LV UUID                h2eSXx-b5sS-Lftq-Kode-YxAP-eRmd-IoHl41 
  LV Write Access        read/write 
  LV Creation host, time localhost.localdomain, 2021-01-17 02:58:25 +0800 
  LV Status              available 
  # open                 1 
  LV Size                <17.00 GiB 
  Current LE             4351 
  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                nZUeUY-svYo-VHGK-QjXz-q3Oe-qWZ0-w2er6g 
  LV Write Access        read/write 
  LV Creation host, time localhost.localdomain, 2021-01-17 02:58:25 +0800 
  LV Status              available 
  # open                 2 
  LV Size                2.00 GiB 
  Current LE             512 
  Segments               1 
  Allocation             inherit 
  Read ahead sectors     auto 
  - currently set to     8192 
  Block device           253:1 
 
将root lv进行扩容剩余的全部容量 
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root 
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 26.99 GiB (6910 extents). 
  Logical volume centos/root successfully resized. 
刷新lv  
[root@localhost ~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks 
         =                       sectsz=512   attr=2, projid32bit=1 
         =                       crc=1        finobt=0 spinodes=0 
data     =                       bsize=4096   blocks=4455424, imaxpct=25 
         =                       sunit=0      swidth=0 blks 
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1 
log      =internal               bsize=4096   blocks=2560, version=2 
         =                       sectsz=512   sunit=0 blks, lazy-count=1 
realtime =none                   extsz=4096   blocks=0, rtextents=0 
data blocks changed from 4455424 to 7075840 
重新查看磁盘分区大小 
[root@localhost ~]# df -h 
文件系统                 容量  已用  可用 已用% 挂载点 
devtmpfs                 475M     0  475M    0% /dev 
tmpfs                    487M     0  487M    0% /dev/shm 
tmpfs                    487M  7.7M  479M    2% /run 
tmpfs                    487M     0  487M    0% /sys/fs/cgroup 
/dev/mapper/centos-root   27G  1.3G   26G    5% / 
/dev/sda1               1014M  138M  877M   14% /boot 
 
tmpfs                     98M     0   98M    0% /run/user/0 |