文章介绍:解决云上dd成vyos的虚拟机硬盘只有2G,磁盘容易占满,不能下载存储文件的问题,需要扩容磁盘。

一、查看当前磁盘

lsblk

yydy_2024-08-07_17-49-10

二、调整分区大小

2.1、切换root权限

sudo -i

2.2、调整分区

sudo fdisk /dev/vda

yydy_2024-08-07_19-22-05

输出应类似于:

Disk /dev/vda: 40 GiB, ...
...
Device     Boot Start       End   Sectors Size Id Type
/dev/vda1  *     2048  4194303  4192256   2G 83 Linux

2.3、删除现有分区

Command (m for help): d

yydy_2024-08-07_19-23-01

2.4、创建新分区

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-83886079, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-83886079, default 83886079): <press Enter>

yydy_2024-08-07_19-23-49

2.5、保留现有文件系统的签名

Do you want to remove the signature? [Y]es/[N]o: N

yydy_2024-08-07_19-25-12

2.6、写入更改并退出

Command (m for help): w

yydy_2024-08-07_19-26-00

2.7、扩展文件系统

sudo resize2fs /dev/vda1

2.8、验证结果

df -h

示例输出:

Filesystem      Size  Used Avail Use% Mounted on
udev            976M     0  976M   0% /dev
tmpfs           199M  1.3M  198M   1% /run
/dev/vda1        40G  1.9G   38G   5% /usr/lib/live/mount/persistence
/dev/loop0      386M  386M     0 100% /usr/lib/live/mount/rootfs/1.5-rolling-202408060021.squashfs
tmpfs           993M     0  993M   0% /usr/lib/live/mount/overlay
overlay          40G  1.9G   38G   5% /
tmpfs           993M   84K  993M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           993M     0  993M   0% /tmp
tmpfs           993M  256K  993M   1% /var/tmp
none            993M     0  993M   0% /etc/cni/net.d
none            993M   44K  993M   1% /opt/vyatta/config
tmpfs           199M     0  199M   0% /run/user/1003

三、查看当前磁盘

lsblk

yydy_2024-08-07_19-30-14