之前安裝 Ubuntu 虛擬機器時使用的都是預設配置,虛擬機器硬碟分配了 60 GB。後來想要擴容,特此記錄一下擴容過程。
首先在 VMware 中修改虛擬機器硬碟大小。
然後使用 gdisk -l
來檢視硬碟分割槽情況。
$ sudo gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.8
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found 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 Name
1 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.8
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found 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): w
Final 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.