sky_cheng

导航

 

一、首先exsi管理台里对目标虚拟机进行硬盘扩容

 

 

从原来的20GB扩容到50GB

二、将新扩容的30GB空间进行fdisk分区,或者直接使用pvcreate 建立物理卷

建立物理卷:pvcreate /dev/sdb

成功后,跳过以下fdisk分区,执行第三步

  

lsblk可以看到硬盘变成50GB,但是分区还是sda1和sda2共20GB,利用fdisk对sda进行分区,将扩容空间创建为新的sda3分区

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

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


命令(输入 m 获取帮助):p

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0000131f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

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

 

 分区操作后,先输入p,查看下分区表无误后,再执行w命令写入

命令(输入 m 获取帮助):p

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0000131f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040   104857599    31457280   83  Linux

可以看到新的30GB空间已经分区完成为/dev/sda3,执行w 写入

命令(输入 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)
正在同步磁盘。

提示设备忙,需要reboot重启生效,执行reboot重启虚拟机

再次查看

[root@GlusterFS01 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  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]
└─sda3            8:3    0   30G  0 part 
sdb               8:16   0   10G  0 disk 
└─sdb1            8:17   0   10G  0 part /home/glusterfs/brick
sdc               8:32   0   10G  0 disk 
sr0              11:0    1  4.4G  0 rom  

可以看到sda3分区完成

三、将扩容的分区添加到需要扩容的卷组中

查看卷组

[root@GlusterFS01 ~]# vgs
-bash: vgs: 未找到命令

需要安装lvm2

[root@GlusterFS01 ~]# yum install lvm2 -y

再次查看卷组

[root@GlusterFS01 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <19.00g    0 

当前虚拟机有一个卷组centos 

查看物理卷

[root@GlusterFS01 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <19.00g    0 

一个物理卷/dev/sda2输入卷组centos 

利用vgextend命令将新的分区添加到目标卷组centos中

[root@GlusterFS01 ~]# vgextend centos /dev/sda3
  Physical volume "/dev/sda3" successfully created.
  Volume group "centos" successfully extended

再次查看卷组

[root@GlusterFS01 ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree  
  centos   2   2   0 wz--n- 48.99g <30.00g
[root@GlusterFS01 ~]# 

可以看到容量已经扩到50GB。

四、将扩容的空间添加到目标逻辑卷

查看逻辑卷

[root@GlusterFS01 ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <17.00g                                                    
  swap centos -wi-ao----   2.00g  

详细查看使用lvdisplay

[root@GlusterFS01 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                S0HfnK-0gVQ-GVvr-ko0D-Jduv-6WOZ-MfExEz
  LV Write Access        read/write
  LV Creation host, time glusterfs01, 2022-02-07 17:11:56 +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                D08Q3p-VIO7-YqVV-FYRV-0W7k-FbUi-yP4s0f
  LV Write Access        read/write
  LV Creation host, time glusterfs01, 2022-02-07 17:11:56 +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

使用lvextend命令进行逻辑卷扩容

[root@GlusterFS01 ~]# lvextend -l +100%FREE /dev/centos/root   
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <46.00 GiB (11775 extents).
  Logical volume centos/root successfully resized.

使用lsblk命令查看

[root@GlusterFS01 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   19G  0 part 
│ ├─centos-root 253:0    0   46G  0 lvm  /
│ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
└─sda3            8:3    0   30G  0 part 
  └─centos-root 253:0    0   46G  0 lvm  /
sdb               8:16   0   10G  0 disk 
└─sdb1            8:17   0   10G  0 part /home/glusterfs/brick
sdc               8:32   0   10G  0 disk 
sr0              11:0    1  4.4G  0 rom  

发现/dev/sda3已经扩容到centos-root逻辑卷中,现在逻辑卷容量为46G.

五、创建文件系统

查看当前文件系统

ca[root@localhost ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed May 31 07:57:57 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/centos-root   /                       xfs     defaults        0 0
UUID=dca29ff8-a6e2-4ca0-9258-c4f2d787bc7d /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap   none                    swap    defaults        0 0

根目录为xfs文件系统,使用xfs_growfs命令进行扩容

[root@GlusterFS01 ~]# xfs_growfs /dev/mapper/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 12057600

再次查看磁盘

[root@GlusterFS01 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 3.9G     0  3.9G    0% /dev
tmpfs                    3.9G     0  3.9G    0% /dev/shm
tmpfs                    3.9G  9.3M  3.9G    1% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root   46G   17G   30G   37% /
/dev/sda1               1014M  137M  878M   14% /boot
/dev/sdb1                9.8G   38M  9.2G    1% /home/glusterfs/brick
tmpfs                    799M     0  799M    0% /run/user/1002
tmpfs                    799M     0  799M    0% /run/user/0
[root@GlusterFS01 ~]# 

根目录已经扩容。

 

posted on 2022-10-17 13:57  sky_cheng  阅读(1015)  评论(0编辑  收藏  举报