目标:挂载cramfs为rw,可读可写,解包cramfs,重新打包cramfs
file
命令查看一下文件信息: /home/susu/mtd2: Linux Compressed ROM File System data, little endian size 9654272 version #2 sorted_dirs CRC 0x352b4d9b, edition 0, 5834 blocks, 818 files
/mnt/test
,需要确保该目录存在,即在/mnt
目录下有一个叫test
的空文件夹~/mtd2
到/mnt/test
:sudo mount ~/mtd2 /mnt/test
/mnt/test
是只读的,需要把文件复制出来做编辑~/cram
~/cram
:sudo cp -r /mnt/test/* ~/cram
~/cram
目录中做编辑操作就可以,比如添加文件删除文件。我是在里面添加了一个文件。~/cram
为镜像~/mtd2new
:sudo mkfs.cramfs -b 4096 ~/cram ~/mtd2new
/home/susu/mtd2new: Linux Compressed ROM File System data, little endian size 9666560 version #2 sorted_dirs CRC 0xa37105a6, edition 0, 5835 blocks, 819 files
有一个问题就是mkfs.cramfs的时候有一个参数-b,指定blocksize,目前还不太懂,好像是默认是用PAGE_CACHE_SIZE作为blocksize(参考1 - patch,参考2 - fs-cramfs-readme)。获取PAGESIZE的方法:
第一种:
$ getconf PAGESIZE
4096
第二种:
$ grep -i pagesize /proc/1/smaps
KernelPageSize: 4 kB
MMUPageSize: 4 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
目标编辑squashfs文件系统镜像,解包squashfs文件系统并重新打包
file
命令和unsquashfs -s
命令查看文件信息:$ file mtd2
mtd2: Squashfs filesystem, little endian, version 4.0, 14144357 bytes, 1122 inodes, blocksize: 131072 bytes, created: Fri Apr 14 06:43:01 2017
$ unsquashfs -s mtd2
Found a valid SQUASHFS 4:0 superblock on mtd2.
Creation or last append time Fri Apr 14 14:43:01 2017
Filesystem size 13812.85 Kbytes (13.49 Mbytes)
Compression lzo
Block size 131072
Filesystem is exportable via NFS
Inodes are compressed
Data is compressed
Fragments are not stored
Xattrs are compressed
Duplicates are removed
Number of fragments 0
Number of inodes 1122
Number of ids 1
可以看到压缩方式lzo,blocksize131072,参数-comp lzo -b 131072 -no-fragments(这部分可以对照mksquashfs -h
帮助分析)
2. 解包命令:unsquashfs mtd2
会解包到当前目录下的squashfs-root
文件夹
3. 在squashfs-root
文件夹中做需要的修改,我是添加了两个文件进去
4. 打包命令:mksquashfs ./squashfs-root mtd2new -comp lzo -b 131072 -no-fragments
5. 打包前后文件信息对比:
$ unsquashfs -s mtd2
Found a valid SQUASHFS 4:0 superblock on mtd2.
Creation or last append time Fri Apr 14 14:43:01 2017
Filesystem size 13812.85 Kbytes (13.49 Mbytes)
Compression lzo
Block size 131072
Filesystem is exportable via NFS
Inodes are compressed
Data is compressed
Fragments are not stored
Xattrs are compressed
Duplicates are removed
Number of fragments 0
Number of inodes 1122
Number of ids 1
$ unsquashfs -s mtd2new
Found a valid SQUASHFS 4:0 superblock on mtd2new.
Creation or last append time Wed Mar 10 16:41:48 2021
Filesystem size 13812.81 Kbytes (13.49 Mbytes)
Compression lzo
Block size 131072
Filesystem is exportable via NFS
Inodes are compressed
Data is compressed
Fragments are not stored
Xattrs are compressed
Duplicates are removed
Number of fragments 0
Number of inodes 1124
Number of ids 1