找回Openwrt分区(扩容)

发布时间:2023年12月22日


概要

使用一个编译好的Openwrt 固件烧写系统启动后,发现用户分区只有812M, 但实际上硬件eMMC存储为32G,可以通过修改固件分区表来调整,但是比较麻烦,本文验证一种更为简便的方法来找回消失的eMMc存储。


问题分析

启动系统后查看分区信息如下:

#df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       812M  664M   91M  88% /
tmpfs           512K     0  512K   0% /dev
tmpfs           987M   19M  968M   2% /tmp
cgroup          987M     0  987M   0% /sys/fs/cgroup

#lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
mmcblk0      179:0    0 28.9G  0 disk 
├─mmcblk0p1  179:1    0    4M  0 part 
├─mmcblk0p2  179:2    0    4M  0 part 
├─mmcblk0p3  179:3    0   64M  0 part 
├─mmcblk0p4  179:4    0   64M  0 part 
├─mmcblk0p5  179:5    0   32M  0 part 
├─mmcblk0p6  179:6    0    6G  0 part /
├─mmcblk0p7  179:7    0  128M  0 part 
└─mmcblk0p8  179:8    0 22.6G  0 part 
mmcblk0boot0 179:32   0    4M  1 disk 
mmcblk0boot1 179:64   0    4M  1 disk 
zram0        254:0    0    0B  0 disk 

可以看出,分区mmcblk0p6被挂载为根分区,22.6G的mmcblk0p8闲在那儿呢。

解决

执行下以命令,挂载mmcblk0p8, 发现并未显示实际大小。

mount /dev/mmcblk0p8 /mnt/
df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       812M  664M   91M  88% /
tmpfs           512K     0  512K   0% /dev
tmpfs           987M   20M  967M   2% /tmp
cgroup          987M     0  987M   0% /sys/fs/cgroup
/dev/mmcblk0p8   23G   24K   21G   1% /mnt

#df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       812M  664M   91M  88% /
tmpfs           512K     0  512K   0% /dev
tmpfs           987M   19M  968M   2% /tmp
cgroup          987M     0  987M   0% /sys/fs/cgroup
/dev/mmcblk0p8  4.0M  283K  3.5M   8% /mnt

先对/dev/mmcblk0p8进行格式化,再次重新mount后分区大小显示正常了。

#mkfs.ext4 /dev/mmcblk0p8
mke2fs 1.46.5 (30-Dec-2021)
/dev/mmcblk0p8 contains a ext2 file system labelled 'userdata'
	last mounted on Wed Dec 20 16:54:25 2023
Proceed anyway? (y,N) y
Discarding device blocks: done                            
Creating filesystem with 5926904 4k blocks and 1482752 inodes
Filesystem UUID: af5f8523-e705-4b11-8615-7c28df16aecb
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done  

#umount /mnt/
#mount /dev/mmcblk0p8 /mnt/
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       812M  664M   91M  88% /
tmpfs           512K     0  512K   0% /dev
tmpfs           987M   20M  967M   2% /tmp
cgroup          987M     0  987M   0% /sys/fs/cgroup
/dev/mmcblk0p8   23G   24K   21G   1% /mnt

# lsblk 
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
mmcblk0      179:0    0 28.9G  0 disk 
├─mmcblk0p1  179:1    0    4M  0 part 
├─mmcblk0p2  179:2    0    4M  0 part 
├─mmcblk0p3  179:3    0   64M  0 part 
├─mmcblk0p4  179:4    0   64M  0 part 
├─mmcblk0p5  179:5    0   32M  0 part 
├─mmcblk0p6  179:6    0    6G  0 part /
├─mmcblk0p7  179:7    0  128M  0 part 
└─mmcblk0p8  179:8    0 22.6G  0 part /root
mmcblk0boot0 179:32   0    4M  1 disk 
mmcblk0boot1 179:64   0    4M  1 disk 
zram0        254:0    0    0B  0 disk

配置永久生效

先导出fstab配置。

#block detect > /etc/config/fstab
#cat  /etc/config/fstab 
config 'global'
	option	anon_swap	'0'
	option	anon_mount	'0'
	option	auto_swap	'1'
	option	auto_mount	'1'
	option	delay_root	'5'
	option	check_fs	'0'

config 'mount'
	option	target	'/mnt'
	option	uuid	'af5f8523-e705-4b11-8615-7c28df16aecb'
	option	enabled	'0'

修改/etc/config/fstab内容如下,使能系统自动mount mmcblk0p8到 /root。

config 'mount'
	option	target	'/root'
	option	uuid	'af5f8523-e705-4b11-8615-7c28df16aecb'
	option	enabled	'1'

重启系统后生效,

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       812M  608M  147M  81% /
tmpfs           512K     0  512K   0% /dev
tmpfs           987M   18M  969M   2% /tmp
cgroup          987M     0  987M   0% /sys/fs/cgroup
/dev/mmcblk0p8   23G   57M   21G   1% /root
文章来源:https://blog.csdn.net/seaneer/article/details/135123158
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。