Centos 系统盘不足扩容

  1. 查看磁盘空间大小, 使用df -h命令:
[root@centos ~]# df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   19G   19G  173M 100% /
devtmpfs                             7.8G     0  7.8G   0% /dev
...

看到 /dev/mapper/centos-root 满了

  1. 增加磁盘空间后查看可用大小, 使用fdisk -l命令
  2. 使用fdisk /dev/vda,创建新分区
[root@centos ~]# fdisk /dev/vda 
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 (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): p
Selected partition 4
No free sectors available

Command (m for help): 

发现无可用盘符,因为所有盘符被占满了

  1. 通过fdisk -l查看下
[root@centos~]# fdisk -l

Disk /dev/vda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x00042553

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        4095        1024   83  Linux
/dev/vda2   *        4096     2101247     1048576   83  Linux
/dev/vda3         2101248     6297599     2098176   82  Linux swap / Solaris
/dev/vda4         6297600    83886079    38794240    5  Extended
/dev/vda5         6299648     6561791      131072    6  FAT16
/dev/vda6         6563840    83886079    38661120   8e  Linux LVM

发现vda3是交换分区,可以删除

  1. 执行swapoff /dev/vda3关闭交换分区
  2. 执行fdisk /dev/vda,进入磁盘管理,输入命令n, 再输入3删除/dev/vda3
  3. 再次执行步骤3创建新分区,创建完成后reboot重启,不重启的话后面扩容只能扩2G
  4. 创建物理卷, 执行pvcreate /dev/vda3
[root@centos~]# pvcreate /dev/vda3
  Physical volume "/dev/vda3" successfully created.
  1. 查看物理卷信息, 执行pvdisplay命令
[root@centos~]# pvdisplay 
  "/dev/vda3" is a new physical volume of "984.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vda3
  VG Name               
  PV Size               984.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               nUy8Gx-HcYl-gh19-nYPi-0uBi-rxXs-7HwnFX
  1. 将新增加的分区/dev/vda3加入到根目录分区centos中, 执行vgextend centos /dev/vda3命令
[root@centos~]# vgextend centos /dev/vda3
  Volume group "centos" successfully extended
  1. 查看卷组信息, 执行vgdisplay命令
[root@centos~]# vgdisplay 
  --- 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               1020.86 GiB
  PE Size               4.00 MiB
  Total PE              261341
  Alloc PE / Size       9438 / <36.87 GiB
  Free  PE / Size       251903 / <984.00 GiB
  VG UUID               QV9fKw-Kp9p-Y20n-jWBj-yYG4-QW6M-s3D7Y5
  1. 增加centos大小, 增加900G,执行lvresize -L +900G /dev/centos/root命令
[root@centos~]# lvresize -L +900G /dev/centos/root 
  Size of logical volume centos/root changed from 18.43 GiB (4719 extents) to 918.43 GiB (235119 extents).
  Logical volume centos/root successfully resized.
  1. 重新识别centos大小,执行xfs_growfs /dev/centos/root命令
[root@centos~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1208064 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4832256, 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 4832256 to 240761856
  1. 查看扩容后的大小, 执行df -h命令
[root@centos~]# df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  919G   19G  901G   2% /
devtmpfs                             7.8G     0  7.8G   0% /dev
...

你可能感兴趣的:(Centos 系统盘不足扩容)