记一次 openwrt 镜像扩容
在虚拟机中使用 openwrt,官方镜像通常只有 300MB 左右,很多时候空间不够用。
可以在安装前给镜像扩容,具体操作如下。
下载镜像
我使用的是 immortalwrt,直接下载 Generic x86/64 平台的 COMBINED (SQUASHFS-COMBINED.IMG.GZ)
格式的镜像。
不要下载 EFI 镜像,我使用 EFI 镜像时无法完成扩容。
复制镜像到 Linux 环境
我使用的是 PVE,我直接用终端工具把镜像传上去了。
需要安装 parted
工具,PVE 并没有自带这个工具。
apt install parted
解压镜像
gzip -kd immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img.gz
增大镜像空间
要增加多少 MB,count 后就填写多少。下面的命令将增加 675MB 大小的空间。
dd if=/dev/zero bs=1M count=675 >> immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img
扩展分区容量
使用 parted 打开 img 镜像。
parted immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img
输入 print
查看分区情况。
root@pve:~# parted immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img
GNU Parted 3.5
Using /root/immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: (file)
Disk /root/immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img: 1056MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 262kB 33.8MB 33.6MB primary ext2 boot
2 34.1MB 349MB 315MB primary
分区 2 就是要扩容的分区。
接下来输入 resizepart 2 100%
扩容,执行完成后输入 print
查看分区情况。
(parted) resizepart 2 100%
(parted) print
Model: (file)
Disk /root/immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img: 1056MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 262kB 33.8MB 33.6MB primary ext2 boot
2 34.1MB 1056MB 1022MB primary
可以看到已经完成扩容,最后输入 quit
退出即可。
导入磁盘到虚拟机
命令:qm disk import <虚拟机ID> <镜像文件> [存储]
qm disk import 103 immortalwrt-24.10.1-x86-64-generic-squashfs-combined.img local-zfs