ESXI虚拟机磁盘扩容

2024-07-03 124 0

系统盘:原34G 扩容至100G
数据盘:原70G 扩容至48T
文件系统:XFS

注意事项:数据重要,操作请做好备份,打快照...

原磁盘信息

root@store53:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.2M  1.6G   1% /run
/dev/sda2        34G  9.2G   25G  28% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sdb         70G  104M   70G   1% /data
/dev/sda1       464M  122M  315M  28% /boot
tmpfs           1.6G     0  1.6G   0% /run/user/0
tmpfs           1.6G     0  1.6G   0% /run/user/1000
tmpfs           1.6G     0  1.6G   0% /run/user/1001

首先在esxi对磁盘进行扩容

image.png

root@store53:~# fdisk -l
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x06b5cd13

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   999423   997376  487M 83 Linux
/dev/sda2       999424 71301119 70301696 33.5G 83 Linux

Disk /dev/sdb: 48 TiB, 52776558133248 bytes, 103079215104 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
root@store53:~# xfs_growfs /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=2196928 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=8787712, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4290, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

数据盘扩容

数据盘由于当时没分区,独立整块磁盘为一个分区,所以扩容很简单

root@store53:~# xfs_growfs /dev/sdb
root@store53:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.2M  1.6G   1% /run
/dev/sda2        34G  9.2G   25G  28% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sdb         48T   50G   48T   1% /data
/dev/sda1       464M  122M  315M  28% /boot
tmpfs           1.6G     0  1.6G   0% /run/user/0
tmpfs           1.6G     0  1.6G   0% /run/user/1000
tmpfs           1.6G     0  1.6G   0% /run/user/1001

系统盘扩容

由于系统盘划分了分区,所以直接xfs_growfs是不成功

root@store53:~# xfs_growfs /dev/sda
xfs_growfs: /dev/sda is not a mounted XFS filesystem
root@store53:~# xfs_growfs /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=2196928 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=8787712, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4290, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
# 执行成功 但容量没发生变化 还是34G

系统盘无损扩容操作步骤

注意提交备份,防操作失误

1.使用fdisk /dev/sda 输入p 查看磁盘分区信息

root@store53:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x06b5cd13

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   999423   997376  487M 83 Linux
/dev/sda2       999424 71301119 70301696 33.5G 83 Linux

2.删除分区同时创建分区

通过将/dev/sda2 删除,再创建新更大分区(也是/dev/sda2) 实现分区合并,d删除分区时,其实未真正删除,w保存才开始清空数据。

这里可以记录在 /dev/sda2 的开始扇区是999424, 所以使用d删除 /dev/sda2 分区后,n新建分区 默认也是从999424 开始的, 注意新建确认不要移除标记(signature) 要键入N

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 
First sector (999424-209715199, default 999424): 
Last sector, +sectors or +size{K,M,G,T,P} (999424-209715199, default 209715199): 

Created a new partition 2 of type 'Linux' and of size 99.5 GiB.
Partition #2 contains a xfs signature.

Do you want to remove the signature? [Y]es/[N]o: N  # 注意不要移除标记

Command (m for help): w

The partition table has been altered.
Syncing disks.

3.使用partprobe命令在不重启的情况下对分区信息进行重新读取,否则可能会出现xfs_growfs无法进行分区更新调整

root@store53:~# partprobe
root@store53:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.1M  1.6G   1% /run
/dev/sda2        34G  9.2G   25G  28% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sdb         48T   50G   48T   1% /data
/dev/sda1       464M  122M  315M  28% /boot
tmpfs           1.6G     0  1.6G   0% /run/user/0
tmpfs           1.6G     0  1.6G   0% /run/user/1001

4.使用xfs_growfs /dev/sda3对需要扩容的分区进行更新扩容

root@store53:~# xfs_growfs /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=2196928 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=8787712, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4290, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 8787712 to 26089472

root@store53:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.1M  1.6G   1% /run
/dev/sda2       100G  9.2G   91G  10% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sdb         48T   50G   48T   1% /data
/dev/sda1       464M  122M  315M  28% /boot
tmpfs           1.6G     0  1.6G   0% /run/user/0
tmpfs           1.6G     0  1.6G   0% /run/user/1001

操作成功

相关文章

ESXI 热加载CPU核数
ESXI不重启热加载新增硬盘空间
ESXI 7.0 开启嵌套虚拟化 Centos7 KVM

发布评论