pve拓展虚拟机磁盘空间

扩展分区和文件系统

1. 安装 gdisk

sudo apt install gdisk

2. 查看当前分区

sudo gdisk /dev/sda

p 以显示分区信息。

3. 删除分区

假设要删除的是 sda3(即第3个分区):

Command (? for help): d
Partition number (1-3): 3

4. 新建分区

Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-62914526, default = 1054720) or {+-}size{KMGTP}:
Last sector (1054720-62914526, default = 62914526) or {+-}size{KMGTP}:
Hex code or GUID (L to show codes, Enter = 8300):

保持当前类型为 8300(Linux 文件系统),按 Enter 确认。

5. 保存更改

Command (? for help): w

确认保存时输入 Y

6. 重新加载分区表

sudo partprobe

7. 扩展文件系统

sudo resize2fs /dev/sda3

8. 验证更改

查看文件系统使用情况:

df -h

示例输出

以下是命令执行过程的示例输出:

rainsc01@master:~$ 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): p
Disk /dev/sda: 62914560 sectors, 30.0 GiB
Model: QEMU HARDDISK
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 02890ECE-0F3B-4490-874F-E03A3FE3C115
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 62914526
Partitions will be aligned on 2048-sector boundaries
Total free space is 20975549 sectors (10.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1054719   513.0 MiB   EF00  EFI System Partition
   3         1054720        41940991   19.5 GiB    8300

Command (? for help): d
Partition number (1-3): 3

Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-62914526, default = 1054720) or {+-}size{KMGTP}:
Last sector (1054720-62914526, default = 62914526) 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): 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.

rainsc01@master:~$ df -h
文件系统        大小  已用  可用 已用% 挂载点
/dev/sda3        20G   19G  2.8M  100% /

扩展文件系统后,重新查看文件系统使用情况:

rainsc01@master:~$ sudo resize2fs /dev/sda3
resize2fs 1.46.5 (30-Dec-2021)
/dev/sda3 上的文件系统已被挂载于 /;需要进行在线调整大小
old_desc_blocks = 3, new_desc_blocks = 4
/dev/sda3 上的文件系统大小已经调整为 7732475 个块(每块 4k)。

rainsc01@master:~$ df -h
文件系统        大小  已用  可用 已用% 挂载点
/dev/sda3        29G   19G  9.5G   66% /

posted @ 2024-10-08 14:40  rainsc  阅读(30)  评论(0编辑  收藏  举报