linux系统磁盘扩容

[root@conda ~]# fdisk -l

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x8e14f6d0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM
/dev/sdb2         2099200     6293503     2097152   8e  Linux LVM
/dev/sdb3         6293504    12584959     3145728   8e  Linux LVM
/dev/sdb4        12584960    33556479    10485760    5  Extended
/dev/sdb5        12587008    16781311     2097152   83  Linux
/dev/sdb6        16783360    20977663     2097152   83  Linux

实践操作:将新分区用于扩容挂载的目录 /soft
使用场景:lvm管理的逻辑卷空间不够使用了,进行扩展,加容量

1、为新增的分区创建物理卷

[root@conda ~]# pvcreate /dev/sdb5
  Physical volume "/dev/sdb5" successfully created.
[root@conda ~]# pvs
  PV         VG     Fmt  Attr PSize    PFree
  /dev/sda2  centos lvm2 a--  <119.00g 4.00m
  /dev/sdb1  softvg lvm2 a--  1020.00m    0 
  /dev/sdb5         lvm2 ---     2.00g 2.00g


2、把新的物理卷加入 softvg 卷组中

[root@conda ~]# vgextend softvg /dev/sdb5
  Volume group "softvg" successfully extended
[root@conda ~]# vgs
  VG     #PV #LV #SN Attr   VSize    VFree 
  centos   1   3   0 wz--n- <119.00g  4.00m
  softvg   2   1   0 wz--n-    2.99g <2.00g
[root@conda ~]# vgdisplay softvg
  --- Volume group ---
  VG Name               softvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               2.99 GiB
  PE Size               4.00 MiB
  Total PE              766
  Alloc PE / Size       255 / 1020.00 MiB
  Free  PE / Size       511 / <2.00 GiB
  VG UUID               C5e8ql-sU2Y-UHyY-lSDh-6ZWg-xYlF-HuXOn7

[root@conda ~]# 



3、扩展逻辑卷 /dev/softvg/softlv

[root@conda ~]# lvextend -l 511 /dev/softvg/softlv
  Size of logical volume softvg/softlv changed from 1020.00 MiB (255 extents) to <2.00 GiB (511 extents).
  Logical volume softvg/softlv successfully resized.

[root@conda ~]# lvextend -l +255 /dev/softvg/softlv
  Size of logical volume softvg/softlv changed from <2.00 GiB (511 extents) to 2.99 GiB (766 extents).
  Logical volume softvg/softlv successfully resized.


4、将文件系统扩大
xfs_growfs /dev/softvg/softlv
resize2fs /dev/softvg/softlv

[root@conda ~]# resize2fs /dev/softvg/softlv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/softvg/softlv is mounted on /soft; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/softvg/softlv is now 784384 blocks long.

[root@conda ~]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   xfs        50G  2.0G   48G   5% /
devtmpfs                  devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                     tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                     tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                     tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                 xfs      1014M  146M  869M  15% /boot
/dev/mapper/centos-home   xfs        66G   16G   50G  24% /home
tmpfs                     tmpfs     378M     0  378M   0% /run/user/0
/dev/nvme0n1              ext4       20G   45M   19G   1% /data
/dev/mapper/softvg-softlv ext4      3.0G  3.0M  2.8G   1% /soft
[root@conda ~]# 


备注:
使用 resize2fs或xfs_growfs 对挂载目录在线扩容 
resize2fs 针对文件系统ext2 ext3 ext4 
xfs_growfs 针对文件系统xfs


 

你可能感兴趣的:(Linux,linux,运维,服务器)