在 VMWare ESXi 或者类似虚拟机扩容 Ubuntu 根目录
最近下载的大模型越来越多,硬盘已经扛不住了,直接在 VMWare 中修改硬盘配置居然没有生效。查阅了一下资料原来需要修改配置后需要在 Ubuntu 中扩容下 ubuntu-vg 。
以下是具体的操作步骤。
1. VMWare 的操作就不累述了,大家都会。
2. SSH 登录服务器,使用 sudo -s
提权。如果你有直接使用 root
用户的“不良习惯”的话,不需要提权了(废话。
3. 执行 fdisk -l
,你会发现有行红字。如果没有的话,请检查下你的虚拟机扩容操作。

4. 执行 fdisk /dev/sda
,依次输入 n -> 默认回车 -> 默认回车 -> 默认回车 -> w
$ fdisk /dev/sda Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. GPT PMBR size mismatch (2147483647 != 4294967295) will be corrected by write. Command (m for help): n Partition number (6-128, default 6): First sector (2147483615-4294967262, default 2147483648): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2147483648-4294967262, default 4294967262): Created a new partition 6 of type 'Linux filesystem' and of size 1024 GiB. Command (m for help): w The partition table has been altered. Syncing disks.
5. 接着执行下 fdisk -l
,你会看到你新扩容的 Disk,我这里是 /dev/sda6

6. 接下来,要使用 /dev/sda6
扩容 ubuntu-vg
分区。
执行:vgextend ubuntu-vg /dev/sda6
# 这里提示,输入y WARNING: ext4 signature detected on /dev/sda6 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sda6. Physical volume "/dev/sda6" successfully created. Volume group "ubuntu-vg" successfully extended
执行 vgdisplay
,检查一下扩容是否完成。
--- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size <2.00 TiB PE Size 4.00 MiB Total PE 523901 Alloc PE / Size 261758 / 1022.49 GiB Free PE / Size 262143 / <1024.00 GiB # 主要看上方的 Free PE / Size 是否大于0,尺寸应该就是你需要扩容的容量。
7. 使用 df -TH
获取你系统中 Ubuntu 主分区的名字,我这里是 /dev/mapper/ubuntu--vg-ubuntu--lv
$ df -TH Filesystem Type Size Used Avail Use% Mounted on udev devtmpfs 34G 0 34G 0% /dev tmpfs tmpfs 6.8G 1.7M 6.8G 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 1.1T 776G 260G 75% / ...
执行以下2个命令完成扩容。
$ lvextend /dev/mapper/ubuntu--vg-ubuntu--lv /dev/sda6 $ resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
8. 最后使用 df -h
检查主分区容量是否已经成功扩容。
$ df -h Filesystem Size Used Avail Use% Mounted on udev 32G 0 32G 0% /dev tmpfs 6.3G 1.6M 6.3G 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 2.0T 723G 1.2T 38% /
大功告成~