xref: /aosp_15_r20/external/erofs-utils/README (revision 33b1fccf6a0fada2c2875d400ed01119b7676ee5)
1*33b1fccfSAndroid Build Coastguard Workererofs-utils
2*33b1fccfSAndroid Build Coastguard Worker===========
3*33b1fccfSAndroid Build Coastguard Worker
4*33b1fccfSAndroid Build Coastguard WorkerUserspace tools for EROFS filesystem, currently including:
5*33b1fccfSAndroid Build Coastguard Worker
6*33b1fccfSAndroid Build Coastguard Worker  mkfs.erofs    filesystem formatter
7*33b1fccfSAndroid Build Coastguard Worker  erofsfuse     FUSE daemon alternative
8*33b1fccfSAndroid Build Coastguard Worker  dump.erofs    filesystem analyzer
9*33b1fccfSAndroid Build Coastguard Worker  fsck.erofs    filesystem compatibility & consistency checker as well
10*33b1fccfSAndroid Build Coastguard Worker                as extractor
11*33b1fccfSAndroid Build Coastguard Worker
12*33b1fccfSAndroid Build Coastguard Worker
13*33b1fccfSAndroid Build Coastguard WorkerEROFS filesystem overview
14*33b1fccfSAndroid Build Coastguard Worker-------------------------
15*33b1fccfSAndroid Build Coastguard Worker
16*33b1fccfSAndroid Build Coastguard WorkerEROFS filesystem stands for Enhanced Read-Only File System.  It aims to
17*33b1fccfSAndroid Build Coastguard Workerform a generic read-only filesystem solution for various read-only use
18*33b1fccfSAndroid Build Coastguard Workercases instead of just focusing on storage space saving without
19*33b1fccfSAndroid Build Coastguard Workerconsidering any side effects of runtime performance.
20*33b1fccfSAndroid Build Coastguard Worker
21*33b1fccfSAndroid Build Coastguard WorkerTypically EROFS could be considered in the following use scenarios:
22*33b1fccfSAndroid Build Coastguard Worker  - Firmwares in performance-sensitive systems, such as system
23*33b1fccfSAndroid Build Coastguard Worker    partitions of Android smartphones;
24*33b1fccfSAndroid Build Coastguard Worker
25*33b1fccfSAndroid Build Coastguard Worker  - Mountable immutable images such as container images for effective
26*33b1fccfSAndroid Build Coastguard Worker    metadata & data access compared with tar, cpio or other local
27*33b1fccfSAndroid Build Coastguard Worker    filesystems (e.g. ext4, XFS, btrfs, etc.)
28*33b1fccfSAndroid Build Coastguard Worker
29*33b1fccfSAndroid Build Coastguard Worker  - FSDAX-enabled rootfs for secure containers (Linux 5.15+);
30*33b1fccfSAndroid Build Coastguard Worker
31*33b1fccfSAndroid Build Coastguard Worker  - Live CDs which need a set of files with another high-performance
32*33b1fccfSAndroid Build Coastguard Worker    algorithm to optimize startup time; others files for archival
33*33b1fccfSAndroid Build Coastguard Worker    purposes only are not needed;
34*33b1fccfSAndroid Build Coastguard Worker
35*33b1fccfSAndroid Build Coastguard Worker  - and more.
36*33b1fccfSAndroid Build Coastguard Worker
37*33b1fccfSAndroid Build Coastguard WorkerNote that all EROFS metadata is uncompressed by design, so that you
38*33b1fccfSAndroid Build Coastguard Workercould take EROFS as a drop-in read-only replacement of ext4, XFS,
39*33b1fccfSAndroid Build Coastguard Workerbtrfs, etc. without any compression-based dependencies and EROFS can
40*33b1fccfSAndroid Build Coastguard Workerbring more effective filesystem accesses to users with reduced
41*33b1fccfSAndroid Build Coastguard Workermetadata.
42*33b1fccfSAndroid Build Coastguard Worker
43*33b1fccfSAndroid Build Coastguard WorkerFor more details of EROFS filesystem itself, please refer to:
44*33b1fccfSAndroid Build Coastguard Workerhttps://www.kernel.org/doc/html/next/filesystems/erofs.html
45*33b1fccfSAndroid Build Coastguard Worker
46*33b1fccfSAndroid Build Coastguard WorkerFor more details on how to build erofs-utils, see `docs/INSTALL.md`.
47*33b1fccfSAndroid Build Coastguard Worker
48*33b1fccfSAndroid Build Coastguard WorkerFor more details about filesystem performance, see
49*33b1fccfSAndroid Build Coastguard Worker`docs/PERFORMANCE.md`.
50*33b1fccfSAndroid Build Coastguard Worker
51*33b1fccfSAndroid Build Coastguard Worker
52*33b1fccfSAndroid Build Coastguard Workermkfs.erofs
53*33b1fccfSAndroid Build Coastguard Worker----------
54*33b1fccfSAndroid Build Coastguard Worker
55*33b1fccfSAndroid Build Coastguard WorkerTwo main kinds of EROFS images can be generated: (un)compressed images.
56*33b1fccfSAndroid Build Coastguard Worker
57*33b1fccfSAndroid Build Coastguard Worker - For uncompressed images, there will be no compressed files in these
58*33b1fccfSAndroid Build Coastguard Worker   images.  However, an EROFS image can contain files which consist of
59*33b1fccfSAndroid Build Coastguard Worker   various aligned data blocks and then a tail that is stored inline in
60*33b1fccfSAndroid Build Coastguard Worker   order to compact images [1].
61*33b1fccfSAndroid Build Coastguard Worker
62*33b1fccfSAndroid Build Coastguard Worker - For compressed images, it will try to use the given algorithms first
63*33b1fccfSAndroid Build Coastguard Worker   for each regular file and see if storage space can be saved with
64*33b1fccfSAndroid Build Coastguard Worker   compression. If not, it will fall back to an uncompressed file.
65*33b1fccfSAndroid Build Coastguard Worker
66*33b1fccfSAndroid Build Coastguard WorkerNote that EROFS supports per-file compression configuration, proper
67*33b1fccfSAndroid Build Coastguard Workerconfiguration options need to be enabled to parse compressed files by
68*33b1fccfSAndroid Build Coastguard Workerthe Linux kernel.
69*33b1fccfSAndroid Build Coastguard Worker
70*33b1fccfSAndroid Build Coastguard WorkerHow to generate EROFS images
71*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72*33b1fccfSAndroid Build Coastguard Worker
73*33b1fccfSAndroid Build Coastguard WorkerCompression algorithms could be specified with the command-line option
74*33b1fccfSAndroid Build Coastguard Worker`-z` to build a compressed EROFS image from a local directory:
75*33b1fccfSAndroid Build Coastguard Worker $ mkfs.erofs -zlz4hc foo.erofs.img foo/
76*33b1fccfSAndroid Build Coastguard Worker
77*33b1fccfSAndroid Build Coastguard WorkerSupported algorithms by the Linux kernel:
78*33b1fccfSAndroid Build Coastguard Worker - LZ4 (Linux 5.3+);
79*33b1fccfSAndroid Build Coastguard Worker - LZMA (Linux 5.16+);
80*33b1fccfSAndroid Build Coastguard Worker - DEFLATE (Linux 6.6+);
81*33b1fccfSAndroid Build Coastguard Worker - Zstandard (Linux 6.10+).
82*33b1fccfSAndroid Build Coastguard Worker
83*33b1fccfSAndroid Build Coastguard WorkerAlternatively, generate an uncompressed EROFS from a local directory:
84*33b1fccfSAndroid Build Coastguard Worker $ mkfs.erofs foo.erofs.img foo/
85*33b1fccfSAndroid Build Coastguard Worker
86*33b1fccfSAndroid Build Coastguard WorkerAdditionally, you can specify a higher compression level to get a
87*33b1fccfSAndroid Build Coastguard Worker(slightly) smaller image than the default level:
88*33b1fccfSAndroid Build Coastguard Worker $ mkfs.erofs -zlz4hc,12 foo.erofs.img foo/
89*33b1fccfSAndroid Build Coastguard Worker
90*33b1fccfSAndroid Build Coastguard WorkerMulti-threaded support can be explicitly enabled with the ./configure
91*33b1fccfSAndroid Build Coastguard Workeroption `--enable-multithreading`; otherwise, single-threaded compression
92*33b1fccfSAndroid Build Coastguard Workerwill be used for now.  It may take more time on multiprocessor platforms
93*33b1fccfSAndroid Build Coastguard Workerif multi-threaded support is not enabled.
94*33b1fccfSAndroid Build Coastguard Worker
95*33b1fccfSAndroid Build Coastguard WorkerCurrently, both `-Efragments` (not `-Eall-fragments`) and `-Ededupe`
96*33b1fccfSAndroid Build Coastguard Workerdon't support multi-threading due to time limitations.
97*33b1fccfSAndroid Build Coastguard Worker
98*33b1fccfSAndroid Build Coastguard WorkerReproducible builds
99*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~
100*33b1fccfSAndroid Build Coastguard Worker
101*33b1fccfSAndroid Build Coastguard WorkerReproducible builds are typically used for verification and security,
102*33b1fccfSAndroid Build Coastguard Workerensuring the same binaries/distributions to be reproduced in a
103*33b1fccfSAndroid Build Coastguard Workerdeterministic way.
104*33b1fccfSAndroid Build Coastguard Worker
105*33b1fccfSAndroid Build Coastguard WorkerImages generated by the same version of `mkfs.erofs` will be identical
106*33b1fccfSAndroid Build Coastguard Workerto previous runs if the same input is specified, and the same options
107*33b1fccfSAndroid Build Coastguard Workerare used.
108*33b1fccfSAndroid Build Coastguard Worker
109*33b1fccfSAndroid Build Coastguard WorkerSpecifically, variable timestamps and filesystem UUIDs can result in
110*33b1fccfSAndroid Build Coastguard Workerunreproducible EROFS images.  `-T` and `-U` can be used to fix them.
111*33b1fccfSAndroid Build Coastguard Worker
112*33b1fccfSAndroid Build Coastguard WorkerHow to generate EROFS big pcluster images (Linux 5.13+)
113*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114*33b1fccfSAndroid Build Coastguard Worker
115*33b1fccfSAndroid Build Coastguard WorkerBy default, EROFS formatter compresses data into separate one-block
116*33b1fccfSAndroid Build Coastguard Worker(e.g. 4KiB) filesystem physical clusters for outstanding random read
117*33b1fccfSAndroid Build Coastguard Workerperformance.  In other words, each EROFS filesystem block can be
118*33b1fccfSAndroid Build Coastguard Workerindependently decompressed.  However, other similar filesystems
119*33b1fccfSAndroid Build Coastguard Workertypically compress data into "blocks" of 128KiB or more for much smaller
120*33b1fccfSAndroid Build Coastguard Workerimages.  Users may prefer smaller images for archiving purposes, even if
121*33b1fccfSAndroid Build Coastguard Workerrandom performance is compromised with those configurations, and even
122*33b1fccfSAndroid Build Coastguard Workerworse when using 4KiB blocks.
123*33b1fccfSAndroid Build Coastguard Worker
124*33b1fccfSAndroid Build Coastguard WorkerIn order to fulfill users' needs, big plusters has been introduced
125*33b1fccfSAndroid Build Coastguard Workersince Linux 5.13, in which each physical clusters will be more than one
126*33b1fccfSAndroid Build Coastguard Workerblocks.
127*33b1fccfSAndroid Build Coastguard Worker
128*33b1fccfSAndroid Build Coastguard WorkerSpecifically, `-C` is used to specify the maximum size of each pcluster
129*33b1fccfSAndroid Build Coastguard Workerin bytes:
130*33b1fccfSAndroid Build Coastguard Worker $ mkfs.erofs -zlz4hc -C65536 foo.erofs.img foo/
131*33b1fccfSAndroid Build Coastguard Worker
132*33b1fccfSAndroid Build Coastguard WorkerThus, in this case, pcluster sizes can be up to 64KiB.
133*33b1fccfSAndroid Build Coastguard Worker
134*33b1fccfSAndroid Build Coastguard WorkerNote that large pcluster size can degrade random performance (though it
135*33b1fccfSAndroid Build Coastguard Workermay improve sequential read performance for typical storage devices), so
136*33b1fccfSAndroid Build Coastguard Workerplease evaluate carefully in advance.  Alternatively, you can make
137*33b1fccfSAndroid Build Coastguard Workerper-(sub)file compression strategies according to file access patterns
138*33b1fccfSAndroid Build Coastguard Workerif needed.
139*33b1fccfSAndroid Build Coastguard Worker
140*33b1fccfSAndroid Build Coastguard WorkerHow to generate EROFS images with multiple algorithms
141*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142*33b1fccfSAndroid Build Coastguard Worker
143*33b1fccfSAndroid Build Coastguard WorkerIt's possible to generate an EROFS image with files in different
144*33b1fccfSAndroid Build Coastguard Workeralgorithms due to various purposes.  For example, LZMA for archival
145*33b1fccfSAndroid Build Coastguard Workerpurposes and LZ4 for runtime purposes.
146*33b1fccfSAndroid Build Coastguard Worker
147*33b1fccfSAndroid Build Coastguard WorkerIn order to use alternative algorithms, just specify two or more
148*33b1fccfSAndroid Build Coastguard Workercompressing configurations together separated by ':' like below:
149*33b1fccfSAndroid Build Coastguard Worker    -zlzma:lz4hc,12:lzma,9 -C32768
150*33b1fccfSAndroid Build Coastguard Worker
151*33b1fccfSAndroid Build Coastguard WorkerAlthough mkfs still choose the first one by default, you could try to
152*33b1fccfSAndroid Build Coastguard Workerwrite a compress-hints file like below:
153*33b1fccfSAndroid Build Coastguard Worker    4096  1 .*\.so$
154*33b1fccfSAndroid Build Coastguard Worker    32768 2 .*\.txt$
155*33b1fccfSAndroid Build Coastguard Worker    4096    sbin/.*$
156*33b1fccfSAndroid Build Coastguard Worker    16384 0 .*
157*33b1fccfSAndroid Build Coastguard Worker
158*33b1fccfSAndroid Build Coastguard Workerand specify with `--compress-hints=` so that ".so" files will use
159*33b1fccfSAndroid Build Coastguard Worker"lz4hc,12" compression with 4k pclusters, ".txt" files will use
160*33b1fccfSAndroid Build Coastguard Worker"lzma,9" compression with 32k pclusters, files  under "/sbin" will use
161*33b1fccfSAndroid Build Coastguard Workerthe default "lzma" compression with 4k plusters and other files will
162*33b1fccfSAndroid Build Coastguard Workeruse "lzma" compression with 16k pclusters.
163*33b1fccfSAndroid Build Coastguard Worker
164*33b1fccfSAndroid Build Coastguard WorkerNote that the largest pcluster size should be specified with the "-C"
165*33b1fccfSAndroid Build Coastguard Workeroption (here 32k pcluster size), otherwise all larger pclusters will be
166*33b1fccfSAndroid Build Coastguard Workerlimited.
167*33b1fccfSAndroid Build Coastguard Worker
168*33b1fccfSAndroid Build Coastguard WorkerHow to generate well-compressed EROFS images
169*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170*33b1fccfSAndroid Build Coastguard Worker
171*33b1fccfSAndroid Build Coastguard WorkerEven if EROFS is not designed for such purposes in the beginning, it
172*33b1fccfSAndroid Build Coastguard Workercould still produce some smaller images (not always) compared to other
173*33b1fccfSAndroid Build Coastguard Workerapproaches with better performance (see `docs/PERFORMANCE.md`).  In
174*33b1fccfSAndroid Build Coastguard Workerorder to build well-compressed EROFS images, try the following options:
175*33b1fccfSAndroid Build Coastguard Worker -C1048576                     (5.13+)
176*33b1fccfSAndroid Build Coastguard Worker -Eztailpacking                (5.16+)
177*33b1fccfSAndroid Build Coastguard Worker -Efragments / -Eall-fragments ( 6.1+);
178*33b1fccfSAndroid Build Coastguard Worker -Ededupe                      ( 6.1+).
179*33b1fccfSAndroid Build Coastguard Worker
180*33b1fccfSAndroid Build Coastguard WorkerAlso EROFS uses lz4hc level 9 by default, whereas some other approaches
181*33b1fccfSAndroid Build Coastguard Workeruse lz4hc level 12 by default.  So please explicitly specify
182*33b1fccfSAndroid Build Coastguard Worker`-zlz4hc,12 ` for comparison purposes.
183*33b1fccfSAndroid Build Coastguard Worker
184*33b1fccfSAndroid Build Coastguard WorkerHow to generate legacy EROFS images (Linux 4.19+)
185*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186*33b1fccfSAndroid Build Coastguard Worker
187*33b1fccfSAndroid Build Coastguard WorkerDecompression inplace and compacted indexes have been introduced in
188*33b1fccfSAndroid Build Coastguard WorkerLinux v5.3, which are not forward-compatible with older kernels.
189*33b1fccfSAndroid Build Coastguard Worker
190*33b1fccfSAndroid Build Coastguard WorkerIn order to generate _legacy_ EROFS images for old kernels,
191*33b1fccfSAndroid Build Coastguard Workerconsider adding "-E legacy-compress" to the command line, e.g.
192*33b1fccfSAndroid Build Coastguard Worker
193*33b1fccfSAndroid Build Coastguard Worker $ mkfs.erofs -E legacy-compress -zlz4hc foo.erofs.img foo/
194*33b1fccfSAndroid Build Coastguard Worker
195*33b1fccfSAndroid Build Coastguard WorkerFor Linux kernel >= 5.3, legacy EROFS images are _NOT recommended_
196*33b1fccfSAndroid Build Coastguard Workerdue to runtime performance loss compared with non-legacy images.
197*33b1fccfSAndroid Build Coastguard Worker
198*33b1fccfSAndroid Build Coastguard WorkerObsoleted erofs.mkfs
199*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~
200*33b1fccfSAndroid Build Coastguard Worker
201*33b1fccfSAndroid Build Coastguard WorkerThere is an original erofs.mkfs version developed by Li Guifu,
202*33b1fccfSAndroid Build Coastguard Workerwhich was replaced by the new erofs-utils implementation.
203*33b1fccfSAndroid Build Coastguard Worker
204*33b1fccfSAndroid Build Coastguard Workergit://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git -b obsoleted_mkfs
205*33b1fccfSAndroid Build Coastguard Worker
206*33b1fccfSAndroid Build Coastguard WorkerPLEASE NOTE: This version is highly _NOT recommended_ now.
207*33b1fccfSAndroid Build Coastguard Worker
208*33b1fccfSAndroid Build Coastguard Worker
209*33b1fccfSAndroid Build Coastguard Workererofsfuse
210*33b1fccfSAndroid Build Coastguard Worker---------
211*33b1fccfSAndroid Build Coastguard Worker
212*33b1fccfSAndroid Build Coastguard Workererofsfuse is introduced to support EROFS format for various platforms
213*33b1fccfSAndroid Build Coastguard Worker(including older linux kernels) and new on-disk features iteration.
214*33b1fccfSAndroid Build Coastguard WorkerIt can also be used as an unpacking tool for unprivileged users.
215*33b1fccfSAndroid Build Coastguard Worker
216*33b1fccfSAndroid Build Coastguard WorkerIt supports fixed-sized output decompression *without* any in-place
217*33b1fccfSAndroid Build Coastguard WorkerI/O or in-place decompression optimization. Also like the other FUSE
218*33b1fccfSAndroid Build Coastguard Workerimplementations, it suffers from most common performance issues (e.g.
219*33b1fccfSAndroid Build Coastguard Workersignificant I/O overhead, double caching, etc.)
220*33b1fccfSAndroid Build Coastguard Worker
221*33b1fccfSAndroid Build Coastguard WorkerTherefore, NEVER use it if performance is the top concern.
222*33b1fccfSAndroid Build Coastguard Worker
223*33b1fccfSAndroid Build Coastguard WorkerHow to mount an EROFS image with erofsfuse
224*33b1fccfSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
225*33b1fccfSAndroid Build Coastguard Worker
226*33b1fccfSAndroid Build Coastguard WorkerAs the other FUSE implementations, it's quite easy to mount by using
227*33b1fccfSAndroid Build Coastguard Workererofsfuse, e.g.:
228*33b1fccfSAndroid Build Coastguard Worker $ erofsfuse foo.erofs.img foo/
229*33b1fccfSAndroid Build Coastguard Worker
230*33b1fccfSAndroid Build Coastguard WorkerAlternatively, to make it run in foreground (with debugging level 3):
231*33b1fccfSAndroid Build Coastguard Worker $ erofsfuse -f --dbglevel=3 foo.erofs.img foo/
232*33b1fccfSAndroid Build Coastguard Worker
233*33b1fccfSAndroid Build Coastguard WorkerTo debug erofsfuse (also automatically run in foreground):
234*33b1fccfSAndroid Build Coastguard Worker $ erofsfuse -d foo.erofs.img foo/
235*33b1fccfSAndroid Build Coastguard Worker
236*33b1fccfSAndroid Build Coastguard WorkerTo unmount an erofsfuse mountpoint as a non-root user:
237*33b1fccfSAndroid Build Coastguard Worker $ fusermount -u foo/
238*33b1fccfSAndroid Build Coastguard Worker
239*33b1fccfSAndroid Build Coastguard Worker
240*33b1fccfSAndroid Build Coastguard Workerdump.erofs and fsck.erofs
241*33b1fccfSAndroid Build Coastguard Worker-------------------------
242*33b1fccfSAndroid Build Coastguard Worker
243*33b1fccfSAndroid Build Coastguard Workerdump.erofs and fsck.erofs are used to analyze, check, and extract
244*33b1fccfSAndroid Build Coastguard WorkerEROFS filesystems. Note that extended attributes and ACLs are still
245*33b1fccfSAndroid Build Coastguard Workerunsupported when extracting images with fsck.erofs.
246*33b1fccfSAndroid Build Coastguard Worker
247*33b1fccfSAndroid Build Coastguard WorkerNote that fragment extraction with fsck.erofs could be slow now and
248*33b1fccfSAndroid Build Coastguard Workerit needs to be optimized later.  If you are interested, contribution
249*33b1fccfSAndroid Build Coastguard Workeris, as always, welcome.
250*33b1fccfSAndroid Build Coastguard Worker
251*33b1fccfSAndroid Build Coastguard Worker
252*33b1fccfSAndroid Build Coastguard WorkerContribution
253*33b1fccfSAndroid Build Coastguard Worker------------
254*33b1fccfSAndroid Build Coastguard Worker
255*33b1fccfSAndroid Build Coastguard Workererofs-utils is a part of EROFS filesystem project, which is completely
256*33b1fccfSAndroid Build Coastguard Workercommunity-driven open source software.  If you have interest in EROFS,
257*33b1fccfSAndroid Build Coastguard Workerfeel free to send feedback and/or patches to:
258*33b1fccfSAndroid Build Coastguard Worker  linux-erofs mailing list   <[email protected]>
259*33b1fccfSAndroid Build Coastguard Worker
260*33b1fccfSAndroid Build Coastguard Worker
261*33b1fccfSAndroid Build Coastguard WorkerComments
262*33b1fccfSAndroid Build Coastguard Worker--------
263*33b1fccfSAndroid Build Coastguard Worker
264*33b1fccfSAndroid Build Coastguard Worker[1] According to the EROFS on-disk format, the tail blocks of files
265*33b1fccfSAndroid Build Coastguard Worker    could be inlined aggressively with their metadata (called
266*33b1fccfSAndroid Build Coastguard Worker    tail-packing) in order to minimize the extra I/Os and the storage
267*33b1fccfSAndroid Build Coastguard Worker    space.
268