Squashfs的设计是专门为一般的只读文件系统的使用而设计,它可应用于数据备份,或是系统资源紧张的电脑上使用。
最初版本的Squashfs采用 gzip 的数据压缩。版本 2.6.34 之后的Linux内核增加了对 LZMA[1] 和 LZO [2]压缩算法的支持,版本 2.6.38 的内核增加了对LZMA2的支持,该算法同时也是xz使用的压缩算法。
squashfs 系统支持以回环(loopback)的方式挂载,然后便可以访问其上的文件了,在访问这些文件时,它们就会被解压缩并装载在 RAM 中,而不需要将整个文件解压缩后才去访问其中的文件,这样一来访问速度就快多了。
1 内核squashfs相关配置
1.1 kernel配置
Linux中打开squashfs功能:
File systems
->Miscellaneous filesystems
->SquashFS 4.0 - Squashed file system support
->File decompression options (Decompress file data into an intermediate buffer)
->Decompressor parallelisation options (Single threaded compression)
->Squashfs XATTR support
->Include support for ZLIB compressed file systems
->Include support for LZ4 compressed file systems
->Include support for LZO compressed file systems
->Include support for XZ compressed file systems
->Include support for ZSTD compressed file systems
->Use 4K device block size?
->Additional option for memory-constrained systems
1.2 作为rootfs挂载
在bootargs上增加如下命令:
root=/dev/mtdblock20 ro rootfstype=squashfs rootwait
通过mount命令加载squashfs:
mount -t squashfs /dev/mtdblock20 /rootfs
2 Buildroot生成squashfs镜像
Buildroot配置如下:
Filesystem images
squashfs root filesystem
block size (128k)
pad to a 4K boundary
Compression algorithm (gzip)
extreme compression when available
使能squashfs后编译mksquashfs工具,使用方法如下:
SYNTAX:./output/host/bin/mksquashfs source1 source2 ... dest [options] [-e list of exclude
dirs/files]
Filesystem build options:
-tar read uncompressed tar file from standard in (stdin)
-no-strip act like tar, and do not strip leading directories
from source files
-tarstyle alternative name for -no-strip
-cpiostyle act like cpio, and read files from standard in (stdin)
-cpiostyle0 like -cpiostyle, but filenames are null terminated
-comp
Compressors available:
gzip (default)
lzma
lzo
lz4
xz
zstd
-b
Optionally a suffix of K or M can be given to specify
Kbytes or Mbytes respectively
...
Filesystem filter options:
...
Filesystem append options:
-noappend do not append to existing filesystem--创建全新文件系统。
-root-becomes
original root become a subdirectory in the new root
called
to the original root
Mksquashfs runtime options:
-version print version, licence and copyright message
-exit-on-error treat normally ignored errors as fatal
-recover
-no-recovery don't generate a recovery file
-recovery-path
-quiet no verbose output
-info print files written to filesystem
-no-progress don't display the progress bar
-progress display progress bar when using the -info option
-throttle
This can be used to reduce the I/O and CPU consumption
of Mksquashfs
-limit
This can be used to reduce the I/O and CPU consumption
of Mksquashfs (alternative to -throttle)
-processors
processors available
-mem
Optionally a suffix of K, M or G can be given to specify
Kbytes, Mbytes or Gbytes respectively
Miscellaneous options:
...
Compressors available and compressor specific options:--压缩算法的子选项,提供更精细的配置。
gzip (default)
-Xcompression-level
-Xwindow-size
-Xstrategy strategy1,strategy2,...,strategyN
Compress using strategy1,strategy2,...,strategyN in turn
and choose the best compression.
Available strategies: default, filtered, huffman_only,
run_length_encoded and fixed
lzma (no options)
lzo
-Xalgorithm
Where
lzo1x_1
lzo1x_1_11
lzo1x_1_12
lzo1x_1_15
lzo1x_999 (default)
-Xcompression-level
Only applies to lzo1x_999 algorithm
lz4
-Xhc
Compress using LZ4 High Compression
xz
-Xbcj filter1,filter2,...,filterN
Compress using filter1,filter2,...,filterN in turn
(in addition to no filter), and choose the best compression.
Available filters: x86, arm, armthumb, powerpc, sparc, ia64
-Xdict-size
Use
can be specified as a percentage of the block size, or as an
absolute value. The dictionary size must be less than or equal
to the block size and 8192 bytes or larger. It must also be
storable in the xz header as either 2^n or as 2^n+2^(n+1).
Example dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K
etc.
zstd
-Xcompression-level
在fs/squashfs/squashfs.mk中定义了生成squashfs镜像流程:
ROOTFS_SQUASHFS_ARGS = \
-noappend \
-processors $(PARALLEL_JOBS) \
-b $(call qstrip,$(BR2_TARGET_ROOTFS_SQUASHFS_BS)) \
$(call qstrip,$(BR2_TARGET_ROOTFS_SQUASHFS_COMP_OPTS))
ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS_PAD),)
ROOTFS_SQUASHFS_ARGS += -nopad
endif
ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZ4),y)
ROOTFS_SQUASHFS_ARGS += -comp lz4
else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZO),y)
ROOTFS_SQUASHFS_ARGS += -comp lzo
else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZMA),y)
ROOTFS_SQUASHFS_ARGS += -comp lzma
else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_XZ),y)
ROOTFS_SQUASHFS_ARGS += -comp xz
else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_ZSTD),y)
ROOTFS_SQUASHFS_ARGS += -comp zstd
else
ROOTFS_SQUASHFS_ARGS += -comp gzip
endif
define ROOTFS_SQUASHFS_CMD
$(HOST_DIR)/bin/mksquashfs $(TARGET_DIR) $@ $(ROOTFS_SQUASHFS_ARGS)
endef
参考文档:《[OpenWrt Wiki] The OpenWrt Flash Layout》、《Squash Fs Comparisons - eLinux.org》、《Understanding SquashFS and How to Mount a SquashFS Filesystem | Baeldung on Linux》。
- 山海经中记载的16个上古神话人物,黄帝战蚩尤,祝融战共工《山海经》记载了几场惊心动魄的上古战争,例如黄帝战蚩尤,祝融战共工,以及大禹战相柳。女魃是涿鹿之战的第一功臣,她帮助应龙战胜了...
- 老板和方太燃气灶哪个好在厨电市场中,老板和方太作为两大知名品牌,其燃气灶产品备受消费者关注。两者各有千秋,下面将从多个维度进行详细对比,以帮助消费者...
- 天子令0.1折主宰特权:2025年4月21日开启的超级福利狂欢盛典 亲爱的《天子令》玩家们,2025年4月21日将迎来一场前所未有的游戏福利盛宴!为了感谢大家一直以来的支持与热爱,我们特别推出了“0.1折主...
- 正史中,关羽到底斩杀了多少大将?其实只有这两位!在小说名著《三国演义》里,作者(罗贯中)将关羽塑造成为一个忠义仁勇、手持青龙偃月刀的武将形象,高大威猛且武艺不凡,出场时与刘备...
- 《幻想江湖》2025年夏日盛典:侠客集结·巅峰对决限时开启 活动详情 活动时间:2025年6月13日 10:00 - 2025年6月20日 23:59 活动范围:全服玩家(含新区) 活动背景: 江湖传闻,「天机阁」现世,...
- 年轻人为什么选择雄安?他们告诉你→雄安新区:打造创新高地和创业热土 青春绽放在“未来之城” 早上8点,雄安宣武医院中医科诊室内,医生刘爽的指腹搭在患者寸关尺处,凝神...
- 什么是三网合一?三网合一如何建设?很多朋友多次提到什么是三网合一?在我们弱电vip技术群中也经常讨论三网合一如何建设?今天我们一起来看下。 一、什么是三网融合? 三网...
- #扭胯 Videos+10k usersSweetDream.ai•Sponsored•4.9/5Live NowMeet Your AI SoulmateExperience genuine connections with an AI companion who understands you. Chat anytime, share moments. Emotional connec...
- 国际足联取消世预赛巴西阿根廷补赛 处罚两国足协新华社里约热内卢8月16日电(记者赵焱、陈威华)据巴西环球体育网16日报道,国际足联最终确认取消世界杯预选赛南美区去年9月被中断的一场...
- 如何檢查電腦上的 Internet Explorer 版本 - Internet Explorer警告 已淘汰、不受支援的 Internet Explorer 11 傳統型應用程式已於特定 Windows 10 版本透過 Microsoft Edge 更新永久停用。 如需詳細資訊,請參閱 Internet...