ESXI 虚拟机在线扩容
虚拟机中刷新scsi
| ls /sys/class/scsi_disk/ |
| 0:0:0:0 |
| echo 1 >/sys/class/scsi_disk/0\:0\:0\:0/device/rescan |
检查磁盘大小以及扩容分区
[root@localhost ~]# df -lh
| Filesystem Size Used Avail Use% Mounted on |
| devtmpfs 3.9G 0 3.9G 0% /dev |
| tmpfs 3.9G 0 3.9G 0% /dev/shm |
| tmpfs 3.9G 8.5M 3.9G 1% /run |
| tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup |
| /dev/mapper/centos-root 35G 1.9G 34G 6% / |
| /dev/sda2 1014M 150M 865M 15% /boot |
| tmpfs 783M 0 783M 0% /run/user/0 |
分区
[root@localhost ~]# fdisk /dev/sda
| 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 # n 新建分区 |
| Partition type: |
| p primary (3 primary, 0 extended, 1 free) |
| e extended |
| Select (default e): p 权限创建一个主分区 |
| Selected partition 4 |
| First sector (75511808-209715199, default 75511808): |
| Using default value 75511808 |
| Last sector, +sectors or +size (75511808-209715199, default 209715199): |
| Using default value 209715199 |
| Partition 4 of type Linux and of size 64 GiB is set |
| |
| Command (m for help): t ## t 修改分区类型 |
| Partition number (1-4, default 4): 4 #选择上面创建的分区id |
| Hex code (type L to list all codes): 8e # 8e 就是lvm格式的分区 |
| Changed type of partition 'Linux' to 'Linux LVM' |
| |
| Command (m for help): w #保存并退出 |
| The partition table has been altered! |
| |
| Calling ioctl() to re-read partition table. |
| |
| WARNING: Re-reading the partition table failed with error 16: Device or resource busy. |
| 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) |
| Syncing disks. |
[root@localhost ~]# vgdisplay #查看卷组
| |
| VG Name centos |
| System ID |
| Format lvm2 |
| Metadata Areas 1 |
| Metadata Sequence No 2 |
| VG Access read/write |
| VG Status resizable |
| MAX LV 0 |
| Cur LV 1 |
| Open LV 1 |
| Max PV 0 |
| Cur PV 1 |
| Act PV 1 |
| VG Size 35.00 GiB |
| PE Size 4.00 MiB |
| Total PE 8960 |
| Alloc PE / Size 8960 / 35.00 GiB |
| Free PE / Size 0 / 0 |
| VG UUID MTYErK-tViu-6Cef-r9Da-k9LV-wJjM-9hLSXj |
将新分区加入到卷组
[root@localhost ~]# vgextend centos /dev/sda4 #
| Device /dev/sda4 not found. |
[root@localhost ~]# partprobe # 无法读取分区,重启或者执行partprobe
[root@localhost ~]# vgextend centos /dev/sda4
| Physical volume "/dev/sda4" successfully created. |
| Volume group "centos" successfully extended |
[root@localhost ~]#
[root@localhost ~]# vgdisplay #查看卷组
| |
| VG Name centos |
| System ID |
| Format lvm2 |
| Metadata Areas 2 |
| Metadata Sequence No 3 |
| VG Access read/write |
| VG Status resizable |
| MAX LV 0 |
| Cur LV 1 |
| Open LV 1 |
| 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 8960 / 35.00 GiB |
| Free PE / Size 16382 / 63.99 GiB |
| VG UUID MTYErK-tViu-6Cef-r9Da-k9LV-wJjM-9hLSXj |
[root@localhost ~]# lvdisplay
| --- Logical volume --- |
| LV Path /dev/centos/root |
| LV Name root |
| VG Name centos |
| LV UUID P1iSJx-KMPv-JYhc-9HpX-ABNr-h2K3-wpZzFD |
| LV Write Access read/write |
| LV Creation host, time localhost, 2021-11-23 16:03:58 +0800 |
| LV Status available |
| # open 1 |
| LV Size 35.00 GiB |
| Current LE 8960 |
| Segments 1 |
| Allocation inherit |
| Read ahead sectors auto |
| - currently set to 8192 |
| Block device 253:0 |
加入剩余所有空间
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
| Size of logical volume centos/root changed from 35.00 GiB (8960 extents) to 98.99 GiB (25342 extents). |
| Logical volume centos/root successfully resized. |
重新识别分区大小
[root@localhost ~]# xfs_growfs /dev/centos/root
| meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2293760 blks |
| = sectsz=512 attr=2, projid32bit=1 |
| = crc=1 finobt=0 spinodes=0 |
| data = bsize=4096 blocks=9175040, imaxpct=25 |
| = sunit=0 swidth=0 blks |
| naming =version 2 bsize=4096 ascii-ci=0 ftype=1 |
| log =internal bsize=4096 blocks=4480, version=2 |
| = sectsz=512 sunit=0 blks, lazy-count=1 |
| realtime =none extsz=4096 blocks=0, rtextents=0 |
| data blocks changed from 9175040 to 25950208 |
验证磁盘空间
[root@localhost ~]# df -lh
| Filesystem Size Used Avail Use% Mounted on |
| devtmpfs 3.9G 0 3.9G 0% /dev |
| tmpfs 3.9G 0 3.9G 0% /dev/shm |
| tmpfs 3.9G 8.5M 3.9G 1% /run |
| tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup |
| /dev/mapper/centos-root 99G 1.9G 98G 2% / |
| /dev/sda2 1014M 150M 865M 15% /boot |
| tmpfs 783M 0 783M 0% /run/user/0 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通