CentOS7.9磁盘扩容操作

CentOS7.9磁盘扩容操作


文章目录

  • CentOS7.9磁盘扩容操作
  • 前言
  • 一、查看本机磁盘环境
  • 二、扩容操作
    • 2.1使用fdisk工具
    • 2.2创建物理卷并查看
    • 2.3将物理卷加入到卷组
    • 2.4同步到文件系统
  • 三、查看挂载情况


前言

随着时间的推移,生产环境因数据量的增加而导致磁盘空间不足以满足生产环境的需要,此时需要对现有的环境进行扩容,本次演示扩容操作,而不影响生产环境数据的丢失或者覆盖。


一、查看本机磁盘环境

[root@shigj data]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
devtmpfs                devtmpfs  2.0G     0  2.0G    0% /dev
tmpfs                   tmpfs     2.0G     0  2.0G    0% /dev/shm
tmpfs                   tmpfs     2.0G  8.6M  2.0G    1% /run
tmpfs                   tmpfs     2.0G     0  2.0G    0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        50G  1.5G   49G    3% /
/dev/sda1               xfs      1014M  138M  877M   14% /boot
/dev/mapper/centos-data xfs        46G  2.7G   43G    6% /data
tmpfs                   tmpfs     396M     0  396M    0% /run/user/0
[root@shigj data]# lsblk
sda(SCSI)是设备名称,其中sda1划分给了/boot;sda2划分给了根目录、swap空间、和/data目录;vda是未使用的磁盘
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
  └─centos-data 253:2    0 45.1G  0 lvm  /data
sr0              11:0    1 1024M  0 rom  
vda             252:0    0    2T  0 disk 

二、扩容操作

2.1使用fdisk工具

[root@shigj ~]# fdisk /dev/vda
欢迎使用 fdisk (util-linux 2.23.2)。

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

Device does not contain a recognized partition table
使用磁盘标识符 0x2ac651de 创建新的 DOS 磁盘标签。

WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-4294967295,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-4294967294,默认为 4294967294):
将使用默认值 4294967294
分区 1 已设置为 Linux 类型,大小设为 2 TiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

2.2创建物理卷并查看

创建物理卷
[root@shigj ~]# lvm
lvm> pvcreate /dev/vda1
  Physical volume "/dev/vda1" successfully created.
查看物理卷和卷组
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               1
  Allocated PE          25342
  PV UUID               cCLpUU-9rjK-6Acg-109k-ppLW-1aHU-877jxe
   
  "/dev/vda1" is a new physical volume of "<2.00 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/vda1
  VG Name               
  PV Size               <2.00 TiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               hu7rTC-pwMZ-Wtm6-GMnC-CxKO-UeLo-IJgVVZ
lvm> vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               A1FYBG-IVHe-TUSc-cR4c-WQo3-YNdp-SjxtON

2.3将物理卷加入到卷组

lvm> vgextend centos /dev/vda1
  Volume group "centos" successfully extended
将卷组剩余空间添加到逻辑卷/dev/centos/data
lvm> lvextend -l +100%FREE /dev/centos/data
  Size of logical volume centos/data changed from <45.12 GiB (11550 extents) to 2.04 TiB (535838 extents).
  Logical volume centos/data successfully resized.

2.4同步到文件系统

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

三、查看挂载情况

已经成功将2T文件系统同步到/data目录下了

[root@shigj ~]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
devtmpfs                devtmpfs  2.0G     0  2.0G    0% /dev
tmpfs                   tmpfs     2.0G     0  2.0G    0% /dev/shm
tmpfs                   tmpfs     2.0G  8.6M  2.0G    1% /run
tmpfs                   tmpfs     2.0G     0  2.0G    0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        50G  1.5G   49G    3% /
/dev/sda1               xfs      1014M  138M  877M   14% /boot
/dev/mapper/centos-data xfs       2.1T  2.7G  2.1T    1% /data
tmpfs                   tmpfs     396M     0  396M    0% /run/user/0

你可能感兴趣的:(虚拟化,centos,linux,运维)