VMware ESXi 中的 linux 虚拟机硬盘扩容

注意:
以下操作可能会丢失数据,应该先备份数据。

  1. 把虚拟机关机
  2. 在 esxi 中增加硬盘容量
  3. 把虚拟机开机
  4. 使用 fdisk -l 查看硬盘大小
    2024032619443031.png
  5. 执行 fdisk /dev/sda,进行操作,使用 p 查看分区详情、使用 d 删除当前分区、使用 n 新建分区、使用 w 保存分区设置。具体过程如下:
    fdisk /dev/sda
     
    Welcome to fdisk (util-linux 2.38.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
     
    This disk is currently in use - repartitioning is probably a bad idea.
    It's recommended to umount all file systems, and swapoff all swap
    partitions on this disk.
     
     
    Command (m for help): p
     
    Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 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: dos
    Disk identifier: 0xfe21000f
     
    Device Boot Start End Sectors Size Id Type
    /dev/sda1 2048 33554431 33552384 16G 83 Linux
     
    Command (m for help): d
    Selected partition 1
    Partition 1 has been deleted.
     
    Command (m for help): n
    Partition type
    p primary (0 primary, 0 extended, 4 free)
    e extended (container for logical partitions)
    Select (default p):
     
    Using default response p.
    Partition number (1-4, default 1):
    First sector (2048-134217727, default 2048):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-134217727, default 134217727):
     
    Created a new partition 1 of type 'Linux' and of size 64 GiB.
    Partition #1 contains a ext4 signature.
     
    Do you want to remove the signature? [Y]es/[N]o: y
     
    The signature will be removed by a write command.
     
    Command (m for help): w
    The partition table has been altered.
    Syncing disks.
  6. 使用 resize2fs /dev/sda1 扩展文件系统为分区大小