第一步
通过web ui中调整磁盘大小功能,先设置分配给虚拟机的磁盘空间,如下图
第二步
进入虚拟机系统,我这里的系统是CentOS,其他Linux系统应该类似。
查看磁盘信息,可以看到磁盘的总大小已经变化了,但是下边两个分区没有变
root@OpenWrt:/lib/firmware# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): p
Disk /dev/sdb: 4.25 GiB, 4563927040 bytes, 8913920 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x198b5c3b
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 512 524799 524288 256M 83 Linux
/dev/sdb2 526336 2622464 2096128 2G 83 Linux
第三步
给/dev/sdb2分区增加空间,注意里边的命令 resizepart 2 100% ,是把剩余的空间全部给到/dev/sdb2
root@OpenWrt:/lib/firmware# parted /dev/sdb
GNU Parted 3.6
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 4564MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 262kB 269MB 268MB primary ext2 boot
2 269MB 2416MB 2147MB primary
(parted) resizepart 2 100%
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 4564MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 262kB 269MB 268MB primary ext2 boot
2 269MB 4564MB 4295MB primary
(parted) quit
Information: You may need to update /etc/fstab.
接下来你就可以看到/dev/sda2分区的大小已经变化,看End值
root@OpenWrt:/etc/openclash/core# fdisk -l
Disk /dev/loop0: 3.72 GiB, 3992780800 bytes, 7798400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 4.25 GiB, 4563927040 bytes, 8913920 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x198b5c3b
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 512 524799 524288 256M 83 Linux
/dev/sdb2 525312 8913919 8388608 4G 83 Linux
Disk /dev/zram0: 487 MiB, 510656512 bytes, 124672 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes