查看rootfs所在分区:
cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00020000 "bootloader"
mtd1: 00040000 00020000 "romfile"
mtd2: 00300000 00020000 "kernel"
mtd3: 01400000 00020000 "rootfs"
通过nc将mtd rootfs分区发送到远程机器上:
nc -l -p 3333 > rootfs.bin
cat /dev/mtd3 | nc 192.168.1.8 3333
查看确认备份的文件头部是squashfs格式:
head -c 4 rootfs.bin |hexdump -C
00000000 68 73 71 73 |hsqs|
查看squashfs打包参数:
binwalk rootfs.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 17975011 bytes, 2288 inodes, blocksize: 131072 bytes, created: 2020-06-22 04:04:58
用binwalk解压:
binwalk -e rootfs.bin
ls _rootfs.bin.extracted/
#0.squashfs为真正大小文件,其它空间为FF填充
0.squashfs squashfs-root
用unsquashfs解压,推荐使用:
unsquashfs rootfs.bin
修改squashfs-root目录内文件后重新打包,使用之前查看的参数:
mksquashfs squashfs-root rootfs-new.bin -comp lzma -b 131072
将修改的rootfs用mtd刷入:
mtd write rootfs-new.bin rootfs
校验下:
mtd verify rootfs-new.bin rootfs
注意:有的机器固件包含签名验证,修改后不能正常开机。
参考:
https://www.callmewing.com/2018/10/03/%E9%80%86%E5%90%91PT632_G2%E5%85%89%E7%8C%AB%E5%9B%BA%E4%BB%B6/
https://akbwe.com/posts/trying-to-modify-f7607p-rootfs/
https://github.com/csersoft/HWFW_GUI