之前安装 Ubuntu 虚拟机时使用的都是默认配置,虚拟机硬盘分配了 60 GB。后来想要扩容,特此记录一下扩容过程。
首先在 VMware 中修改虚拟机硬盘大小。
然后使用 gdisk -l
来查看硬盘分区情况。
$ sudo gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.8Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.
Disk /dev/sda: 134217728 sectors, 64.0 GiB
Model: Ubuntu Linux 22.
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 11AE34C9-947E-405F-A204-1BDAB7A8C48A
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 134217694
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)Number Start (sector) End (sector) Size Code Name1 2048 2203647 1.0 GiB EF00 2 2203648 134215679 62.9 GiB 8300
这里可以看到挂载在根目录 /
的是 /dev/sda3
(sda
是磁盘名,3
是分区号)。
接下来使用 gdisk
命令设置磁盘 sda
的分区。
$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.8Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help):
首先使用 d
选项删除分区。这里我们要删除 3
号分区,因此接下来的分区号填 3
。
Command (? for help): d
Partition number (1-3): 3
删除分区后,使用 n
选项新建分区。接下来要填写分区号,我们再次填写 3
以重建一个 3
号分区。之后会让你填写分区起始扇区号,默认就是
Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-1258291166, default = 1054720) or {+-}size{KMGTP}:
Last sector (1054720-1258291166, default = 1258291166) or {+-}size{KMGTP}:
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'Command (? for help):
Command (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.