背景
这里使用的是x86的64位ext4的OpenWrt镜像。下面是OpenWrt下载地址:
https://downloads.openwrt.org/releases/19.07.4/targets/x86/64/
使用OpenWrt的ext4镜像制作好U盘镜像文件后,然后,再对u盘进行分区扩容。
默认分区
OpenWrt默认就2个分区:
/dev/sda1
是16MB大小的 ext4格式的/boot
分区,用于存储GRUB和内核。/dev/sda2
是一个256MB大小分区,其中包含squasfs根文件系统和可读写的f2fs文件系统或ext4根文件系统(取决于您选择的映像)。
我们的目标就是要扩展/dev/sda2
这个256MB的分区,将这个分区扩完u盘的最大空间即可。
分区扩容
这里主要使用fdisk软件进行分区扩容。**注意:**这里的u盘镜像是外挂到一个linux系统下面进行扩容的,使用过程中的OpenWrt系统是不能动态扩容的。
root@OpenWrt:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdb: 7.2 GiB, 7751073792 bytes, 15138816 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
Disklabel type: dos
Disk identifier: 0xcbad8a62
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 512 33279 32768 16M 83 Linux
/dev/sdb2 33792 558079 524288 256M 83 Linux
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (33280-15138815, default 34816): 33792
Last sector, +sectors or +size{K,M,G,T,P} (33792-15138815, default 15138815):
Created a new partition 2 of type 'Linux' and of size 7.2 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): w
The partition table has been altered.
Syncing disks.
root@OpenWrt:~# resize2fs /dev/sdb2