磁盘扩容
说明
使用官方的系统镜像安装好openwrt后,磁盘分区只有几百兆(因为磁盘布局默认是和镜像里面的一致),大量的存储空间都未使用。比如我下面的设备,实际有110GB,但是只有300M的空间被使用了:
为了解决这个问题,需要手动对磁盘空间进行扩容。
扩容方案
使用ssh登录到后台,执行fdisk -l
命令查看分区情况:
bash
root@ImmortalWrt:~# fdisk -l
GPT PMBR size mismatch (680479 != 234441647) will be corrected by write.
The backup GPT table is not on the end of the device.
Disk /dev/sda: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: CUSO C5S-EVO 120
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: gpt
Disk identifier: B83072DC-F739-83CF-499B-39C2B2550F00
Device Start End Sectors Size Type
/dev/sda1 512 66047 65536 32M Linux filesystem
/dev/sda2 66048 680447 614400 300M Linux filesystem
/dev/sda128 34 511 478 239K BIOS boot
Partition table entries are not in disk order.
分成了3个分区:
/dev/sda1
:32M,不知道干嘛用的/dev/sda2
:300M,根分区,实际openwrt系统的分区/dev/sda128
:239K,boot分区
总共只使用了不到1G的容量,剩余110G都是未分配。接下来就需要把这未使用的110G分配出来作为根分区使用,替换掉300M的分区。
分配磁盘分区
使用fdisk
命令对磁盘进行分区:
bash
root@ImmortalWrt:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (680479 != 234441647) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
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): n
Partition number (3-127, default 3):
First sector (680448-234441614, default 681984):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (681984-234441614, default 234440703):
Created a new partition 3 of type 'Linux filesystem' and of size 111.5 GiB.
Partition #3 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
Command (m for help): w
The partition table has been altered.
Syncing disks.
交互的指令说明:
p
查看当前分区表d
删除最后一个分区n
创建新分区p
选择主分区- 分区号选择原来的号码
- 起始扇区按默认(回车)
- 结束扇区按默认(回车),使用全部可用空间
w
写入修改并退出
新分配的盘符为/dev/sda3
,空间为所有剩余空间。使用mkfs.ext4
格式化分区:
bash
root@ImmortalWrt:~# mkfs.ext4 /dev/sda3
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 29219840 4k blocks and 7307264 inodes
Filesystem UUID: f0fcea64-d3a1-4a7d-8eeb-40097d27603d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
命令执行完后,分区就已经分配并格式化好了。可以使用fdisk -l
命令确认下是否已经分配好。
添加挂载点
用浏览器登录到路由器,进入系统-挂载点页面:
点击新增添加一个挂载点,选择刚刚创建好的磁盘挂载到根分区,点击保存即可:
TIP
注意顺序是先保存,然后再执行下面的命令 保存的时候注意把启用的开关开启
这里注意刚刚创建好的盘里面是没有openwrt系统文件的,因此需要执行命令手动把系统文件都拷贝进去。页面中已经把相应的命令展示出来了,把第四行的/dev/sda1
替换成实际的分区路径执行:
js
mkdir -p /tmp/introot
mkdir -p /tmp/extroot
mount --bind / /tmp/introot
mount /dev/sda1 /tmp/extroot
mount /dev/sda3 /tmp/extroot
tar -C /tmp/introot -cvf - . | tar -C /tmp/extroot -xf -
umount /tmp/introot
umount /tmp/extroot
执行完成后重启设备即可完成扩容: