1、VMware修改硬盘大小
关闭客户机
右键需要扩容的服务器——编辑——磁盘 修改大小
2、确认状态
# fdisk -l
可以看到“Disk /dev/sda: 400 GB”,已经扩展了300G空间。
ESXI修改完磁盘大小后,增加的磁盘空间表现为当前磁盘剩余未分配空间,需要使用剩余未分配空间新建分区
1. 创建新分区
# fdisk /dev/sda n (新建分区) p (选择分区类型主分区或扩展分区) 3 (选择分区编号) 回车 回车 t (修改分区类型) 3 (选择分区) 8e (Changed type of partition 'Linux' to 'Linux LVM',修改成LVM类型) 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)
正在同步磁盘。
使用命令重新读取分区表,或者重启机器 # partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
格式化新磁盘分区 xfs文件系统 # mkfs.xfs /dev/sda3 (此处分区格式要与已有的LVM卷中分区格式一致) EXT4文件系统 # mkfs.ext4 /dev/sda3 查看分区格式 cat /etc/fstab
2. 添加新LVM分区到已有的LVM组,实现扩容
[root@jason_test ~]# lvm lvm> pvcreate /dev/sda3 WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sda3. Physical volume "/dev/sda3" successfully created. lvm> vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <15.00 GiB PE Size 4.00 MiB Total PE 3839 Alloc PE / Size 3839 / <15.00 GiB Free PE / Size 0 / 0 VG UUID Dw2t3d-lOmX-GwB8-r7z2-X2S2-2vzf-gn1ncn lvm> vgextend centos /dev/sda3 Volume group "centos" successfully extended lvm> 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 98.99 GiB PE Size 4.00 MiB Total PE 25342 Alloc PE / Size 3839 / <15.00 GiB Free PE / Size 21503 / <84.00 GiB VG UUID Dw2t3d-lOmX-GwB8-r7z2-X2S2-2vzf-gn1ncn lvm> lvextend -l +21503 /dev/mapper/centos-root (想要扩容的分区) Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 97.39 GiB (24932 extents). Logical volume centos/root successfully resized. lvm> pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size <15.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 3839 Free PE 0 Allocated PE 3839 PV UUID 0khpbf-D1I8-hdt0-U78f-ELax-V2xR-eOL8g9 --- Physical volume --- PV Name /dev/sda3 VG Name centos PV Size 84.00 GiB / not usable 4.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 21503 Free PE 0 Allocated PE 21503 PV UUID lCHa3l-XXpa-B1OY-6gEq-CBAl-2NxS-CzrCn2 lvm> quit
3. 文件系统扩容
xfs文件系统
[root@jason_test ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=877824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=3511296, 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 3511296 to 25530368
EXT4文件系统
resize2fs /dev/mapper/centos-root
[root@jason_test ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 98G 11G 87G 11% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 9.3M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda1 1014M 182M 833M 18% /boot tmpfs 1.6G 0 1.6G 0% /run/user/0
参考: https://www.lucissfer.com/2018/06/12/ESXI虚拟机磁盘在线扩容/
https://www.cnblogs.com/zengming/p/11498322.html
https://blog.csdn.net/linmengmeng_1314/article/details/124848863
ESXI编辑设置硬盘为灰色无法修改大小

解决办法:这是由于当前虚拟机存在快照,从而锁定了磁盘空间容量,删除快照即可解决此问题
esxi5.5、esxi6.0 更改磁盘大小,需要关闭虚拟机再操作(否则报错:failed to extend disk)
![]()
lvextend(选项)(参数)
-L:指定逻辑卷的大小,单位为“kKmMgGtT”字节;
-l:指定逻辑卷的大小(LE数)
lvextend -L +100G 增加100G容量
lvextend -L 100G 扩展至100G容量
Esxi虚拟机磁盘扩容失败 提示“设备“3”的操作无效”的问题解决

解决:
删除该服务器的所有快照
Ubuntu系统
以下是针对 ESXi 6.7 虚拟机中 Ubuntu 25 系统 扩展 /dev/mapper/ubuntu--vg-ubuntu--lv 逻辑卷的完整操作步骤: 一、ESXi 层面扩展虚拟磁盘 1. 关闭虚拟机 在 vSphere Client 中确认虚拟机处于关机状态。 2. 扩展虚拟磁盘容量 • 右键虚拟机 → 编辑设置 → 选择现有磁盘 → 修改 磁盘容量 为更大值(如从 20GB 扩容至 40GB)→ 勾选 “立即分配所有空间” → 确认保存。 3. 启动虚拟机 完成扩容后启动虚拟机,进入 Ubuntu 系统。 二、Ubuntu 系统内操作 1. 确认新磁盘空间已识别 lsblk # 查看磁盘列表,确认新增空间(如 /dev/sda 新增未分配区域) fdisk -l # 检查磁盘总容量是否匹配 ESXi 设置
jason@aiyaya-bi:~$ sudo fdisk -l
GPT PMBR size mismatch (104857599 != 209715199) will be corrected by write.
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: Virtual disk
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: gpt
Disk identifier: A77751EF-70C8-40B2-AAB8-567B70D9AC45
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 104855551 100657152 48G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 24 GiB, 25765609472 bytes, 50323456 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
jason@aiyaya-bi:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 739M 1.5M 737M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 24G 19G 3.6G 84% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-resolved.service
tmpfs 3.7G 0 3.7G 0% /tmp
/dev/sda2 2.0G 213M 1.6G 12% /boot
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-networkd.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service
tmpfs 739M 12K 739M 1% /run/user/1000
jason@aiyaya-bi:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-uRNTMdylbz7eSyCAvC13eriTNXaDwNpJI11d083eW6kpNmCiSeunLmGO5dFmT5Ld / ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/ad9a6247-85d3-4c7d-8030-fd5399020813 /boot ext4 defaults 0 1
/swap.img none swap sw 0 0
jason@aiyaya-bi:~$ sudo parted /dev/sda
GNU Parted 3.6
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 2150MB 2147MB ext4
3 2150MB 53.7GB 51.5GB
(parted) resizepart 3 100%
(parted) quit
Information: You may need to update /etc/fstab.
jason@aiyaya-bi:~$ sudo partprobe /dev/sda
jason@aiyaya-bi:~$ sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
jason@aiyaya-bi:~$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <98.00 GiB / not usable 16.50 KiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25087
Free PE 18944
Allocated PE 6143
PV UUID 3ewprj-IcFr-iGCy-0y0G-XFFw-tlZP-5DEJpX
jason@aiyaya-bi:~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <24.00 GiB (6143 extents) to <98.00 GiB (25087 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
jason@aiyaya-bi:~$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID I11d08-3eW6-kpNm-CiSe-unLm-GO5d-FmT5Ld
LV Write Access read/write
LV Creation host, time ubuntu-server, 2025-07-02 13:48:39 +0800
LV Status available
# open 1
LV Size <98.00 GiB
Current LE 25087
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
-
EXT4 文件系统:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv -
XFS 文件系统:
sudo xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv
jason@aiyaya-bi:~$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.47.2 (1-Jan-2025)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 25689088 (4k) blocks long.
jason@aiyaya-bi:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 739M 1.5M 737M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 97G 19G 74G 21% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-resolved.service
tmpfs 3.7G 0 3.7G 0% /tmp
/dev/sda2 2.0G 213M 1.6G 12% /boot
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-networkd.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service
tmpfs 739M 12K 739M 1% /run/user/1000
浙公网安备 33010602011771号