home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / share / doc / squashfs.txt < prev    next >
Encoding:
Text File  |  2004-12-13  |  18.4 KB  |  458 lines

  1.     SQUASHFS 2.1 - A squashed read-only filesystem for Linux
  2.  
  3.     Copyright 2004 Phillip Lougher (plougher@users.sourceforge.net)
  4.  
  5.     Released under the GPL licence (version 2 or later).
  6.  
  7. Welcome to Squashfs version 2.1-r2.  Significant improvements to
  8. directory handling and numerous other smaller improvements have been made.
  9. Please see the README-2.1 and CHANGES files for further details.
  10.  
  11. Squashfs is a highly compressed read-only filesystem for Linux.
  12. It uses zlib compression to compress both files, inodes and directories.
  13. Inodes in the system are very small and all blocks are packed to minimise
  14. data overhead. Block sizes greater than 4K are supported up to a maximum
  15. of 64K.
  16.  
  17. Squashfs is intended for general read-only filesystem use, for archival
  18. use (i.e. in cases where a .tar.gz file may be used), and in constrained
  19. block device/memory systems (e.g. embedded systems) where low overhead is
  20. needed.
  21.  
  22. 1. SQUASHFS OVERVIEW
  23. --------------------
  24.  
  25. 1. Data, inodes and directories are compressed.
  26.  
  27. 2. Squashfs stores full uid/gids (32 bits), and file creation time.
  28.  
  29. 3. Files up to 2^32 bytes are supported.  Filesystems can be up to
  30.    2^32 bytes.
  31.  
  32. 4. Inode and directory data are highly compacted, and packed on byte
  33.    boundaries.  Each compressed inode is on average 8 bytes in length
  34.    (the exact length varies on file type, i.e. regular file, directory,
  35.    symbolic link, and block/char device inodes have different sizes).
  36.  
  37. 5. Squashfs can use block sizes up to 64K (the default size is 64K).
  38.    Using 64K blocks achieves greater compression ratios than the normal
  39.    4K block size.
  40.  
  41. 6. File duplicates are detected and removed.
  42.  
  43. 7. Both big and little endian architectures are supported.  Squashfs can
  44.    mount filesystems created on different byte order machines.
  45.  
  46.  
  47. 2. USING SQUASHFS
  48. -----------------
  49.  
  50. Squashfs filesystems should be mounted with 'mount' with the filesystem type
  51. 'squashfs'.  If the filesystem is on a block device, the filesystem can be
  52. mounted directly, e.g.
  53.  
  54. %mount -t squashfs /dev/sda1 /mnt
  55.  
  56. Will mount the squashfs filesystem on "/dev/sda1" under the directory "/mnt".
  57.  
  58. If the squashfs filesystem has been written to a file, the loopback device
  59. can be used to mount it (loopback support must be in the kernel), e.g.
  60.  
  61. %mount -t squashfs image /mnt -o loop
  62.  
  63. Will mount the squashfs filesystem in the file "image" under
  64. the directory "/mnt".
  65.  
  66.  
  67. 3. MKSQUASHFS
  68. -------------
  69.  
  70. 3.1 Mksquashfs options and overview.
  71. ------------------------------------
  72.  
  73. As squashfs is a read-only filesystem, the mksquashfs program must be used to
  74. create populated squashfs filesystems.
  75.  
  76. SYNTAX:mksquashfs source1 source2 ...  dest [options] [-e list of exclude
  77. dirs/files]
  78.  
  79. Options are
  80. -version        print version, licence and copyright message
  81. -info            print files written to filesystem
  82. -b <block_size>        set data block to <block_size>.  Default 65536 bytes
  83. -2.0            create a 2.0 filesystem
  84. -noI            do not compress inode table
  85. -noD            do not compress data blocks
  86. -noF            do not compress fragment blocks
  87. -no-fragments        do not use fragments
  88. -always-use-fragments    use fragment blocks for files larger than block size
  89. -no-duplicates        do not perform duplicate checking
  90. -noappend        do not append to existing filesystem
  91. -keep-as-directory    if one source directory is specified, create a root
  92.             directory containing that directory, rather than the
  93.             contents of the directory
  94. -root-becomes <name>    when appending source files/directories, make the
  95.             original root become a subdirectory in the new root
  96.             called <name>, rather than adding the new source items
  97.             to the original root
  98. -all-root        make all files owned by root
  99. -force-uid uid        set all file uids to uid
  100. -force-gid gid        set all file gids to gid
  101. -le            create a little endian filesystem
  102. -be            create a big endian filesystem
  103. -nopad            do not pad filesystem to a multiple of 4K
  104. -check_data        add checkdata for greater filesystem checks
  105. -root-owned        alternative name for -all-root
  106. -noInodeCompression    alternative name for -noI
  107. -noDataCompression    alternative name for -noD
  108. -noFragmentCompression    alternative name for -noF
  109. -sort <sort_file>    sort files according to priorities in <sort_file>.  One
  110.             file or dir with priority per line.  Priority -32768 to
  111.             32767, default priority 0
  112. -ef <exclude_file>    list of exclude dirs/files.  One per line
  113.  
  114. Source1 source2 ... are the source directories/files containing the
  115. files/directories that will form the squashfs filesystem.  If a single
  116. directory is specified (i.e. mksquashfs source output_fs) the squashfs
  117. filesystem will consist of that directory, with the top-level root
  118. directory corresponding to the source directory.
  119.  
  120. If multiple source directories or files are specified, mksquashfs will merge
  121. the specified sources into a single filesystem, with the root directory
  122. containing each of the source files/directories.  The name of each directory
  123. entry will be the basename of the source path.   If more than one source
  124. entry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where
  125. xxx is the original name.
  126.  
  127. To make this clear, take two example directories.  Source directory
  128. "/home/phillip/test" contains  "file1", "file2" and "dir1".
  129. Source directory "goodies" contains "goodies1", "goodies2" and "goodies3".
  130.  
  131. usage example 1:
  132.  
  133. %mksquashfs /home/phillip/test output_fs
  134.  
  135. This will generate a squashfs filesystem with root entries
  136. "file1", "file2" and "dir1".
  137.  
  138. example 2:
  139.  
  140. %mksquashfs /home/phillip/test goodies output_fs
  141.  
  142. This will create a squashfs filesystem with the root containing
  143. entries "test" and "goodies" corresponding to the source
  144. directories "/home/phillip/test" and "goodies".
  145.  
  146. example 3:
  147.  
  148. %mksquashfs /home/phillip/test goodies test output_fs
  149.  
  150. This is the same as the previous example, except a third
  151. source directory "test" has been specified.  This conflicts
  152. with the first directory named "test" and will be renamed "test_1".
  153.  
  154. Multiple sources allow filesystems to be generated without needing to
  155. copy all source files into a common directory.  This simplifies creating
  156. filesystems.
  157.  
  158. The -keep-as-directory option can be used when only one source directory
  159. is specified, and you wish the root to contain that directory, rather than
  160. the contents of the directory.  For example:
  161.  
  162. example 4:
  163.  
  164. %mksquashfs /home/phillip/test output_fs -keep-as-directory
  165.  
  166. This is the same as example 1, except for -keep-as-directory.
  167. This will generate a root directory containing directory "test",
  168. rather than the "test" directory contents "file1", "file2" and "dir1".
  169.  
  170. The Dest argument is the destination where the squashfs filesystem will be
  171. written.  This can either be a conventional file or a block device.  If the file
  172. doesn't exist it will be created, if it does exist and a squashfs
  173. filesystem exists on it, mksquashfs will append.  The -noappend option will
  174. write a new filesystem irrespective of whether an existing filesystem is
  175. present.
  176.  
  177. 3.2 Changing compression defaults used in mksquashfs
  178. ----------------------------------------------------
  179.  
  180. There are a large number of options that can be used to control the 
  181. compression in mksquashfs.  By and large the defaults are the most
  182. optimum settings and should only be changed in exceptional circumstances!
  183.  
  184. The -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression
  185. and -noFragmentCompression) can be used to force mksquashfs to not compress
  186. inodes/directories, data and fragments respectively.  Giving all options
  187. generates an uncompressed filesystem.
  188.  
  189. The -no-fragments tells mksquashfs to not generate fragment blocks, and rather
  190. generate a filesystem similar to a Squashfs 1.x filesystem.  It will of course
  191. still be a Squashfs 2.0 filesystem but without fragments, and so it won't be
  192. mountable on a Squashfs 1.x system.
  193.  
  194. The -always-use-fragments option tells mksquashfs to always generate
  195. fragments for files irrespective of the file length.  By default only small
  196. files less than the block size are packed into fragment blocks.  The ends of
  197. files which do not fit fully into a block, are NOT by default packed into
  198. fragments.  To illustrate this, a 100K file has an initial 64K block and a 36K
  199. remainder.  This 36K remainder is not packed into a fragment by default.  This
  200. is because to do so leads to a 10 - 20% drop in sequential I/O performance, as a
  201. disk head seek is needed to seek to the initial file data and another disk seek
  202. is need to seek to the fragment block.  Specify this option if you want file
  203. remainders to be packed into fragment blocks.  Doing so may increase the
  204. compression obtained BUT at the expense of I/O speed.
  205.  
  206. The -no-duplicates option tells mksquashfs to not check the files being
  207. added to the filesystem for duplicates.  This can result in quicker filesystem
  208. generation and appending although obviously compression will suffer badly if
  209. there is a lot of duplicate files.
  210.  
  211. The -b option allows the block size to be selected, this can be either
  212. 4096, 8192, 16384, 32768 or 65536 bytes.
  213.  
  214. 3.3 Specifying the UIDs/GIDs used in the filesystem
  215. ---------------------------------------------------
  216.  
  217. By default files in the generated filesystem inherit the UID and GID ownership
  218. of the original file.  However,  mksquashfs provides a number of options which
  219. can be used to override the ownership.
  220.  
  221. The options -all-root and -root-owned (both do exactly the same thing) force all
  222. file uids/gids in the generated Squashfs filesystem to be root.  This allows
  223. root owned filesystems to be built without root access on the host machine.
  224.  
  225. The "-force-uid uid"  option forces all files in the generated Squashfs
  226. filesystem to be owned by the specified uid.  The uid can be specified either by
  227. name (i.e. "root") or by number.
  228.  
  229. The "-force-gid gid" option forces all files in the generated Squashfs
  230. filesystem to be group owned by the specified gid.  The gid can be specified
  231. either by name (i.e. "root") or by number.
  232.  
  233. 3.4 Excluding files from the filesystem
  234. ---------------------------------------
  235.  
  236. The -e and -ef options allow files/directories to be specified which are
  237. excluded from the output filesystem.  The -e option takes the exclude
  238. files/directories from the command line, the -ef option takes the
  239. exlude files/directories from the specified exclude file, one file/directory
  240. per line. If an exclude file/directory is absolute (i.e. prefixed with /, ../,
  241. or ./) the entry is treated as absolute, however, if an exclude file/directory
  242. is relative, it is treated as being relative to each of the sources in turn,
  243. i.e.
  244.  
  245. %mksquashfs /tmp/source1 source2  output_fs -e ex1 /tmp/source1/ex2 out/ex3
  246.  
  247. Will generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,
  248. /tmp/source1/out/ex3 and source2/out/ex3.
  249.  
  250. The -e and -ef exclude options are usefully used in archiving the entire
  251. filesystem, where it is wished to avoid archiving /proc, and the filesystem
  252. being generated, i.e.
  253.  
  254. %mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh
  255.  
  256. Multiple -ef options can be specified on the command line, and the -ef
  257. option can be used in conjuction with the -e option.
  258.  
  259. 3.5 Appending to squashfs filesystems
  260. -------------------------------------
  261.  
  262. Running squashfs with the destination directory containing an existing
  263. filesystem will add the source items to the existing filesystem.  By default,
  264. the source items are added to the existing root directory.
  265.  
  266. To make this clear... An existing filesystem "image" contains root entries
  267. "old1", and "old2".  Source directory "/home/phillip/test" contains  "file1",
  268. "file2" and "dir1".
  269.  
  270. example 1:
  271.  
  272. %mksquashfs /home/phillip/test image
  273.  
  274. Will create a new "image" with root entries "old1", "old2", "file1", "file2" and
  275. "dir1"
  276.  
  277. example 2:
  278.  
  279. %mksquashfs /home/phillip/test image -keep-as-directory
  280.  
  281. Will create a new "image" with root entries "old1", "old2", and "test".
  282. As shown in the previous section, for single source directories
  283. '-keep-as-directory' adds the source directory rather than the
  284. contents of the directory.
  285.  
  286. example 3:
  287.  
  288. %mksquashfs /home/phillip/test image -keep-as-directory -root-becomes
  289. original-root
  290.  
  291. Will create a new "image" with root entries "original-root", and "test".  The
  292. '-root-becomes' option specifies that the original root becomes a subdirectory
  293. in the new root, with the specified name.
  294.  
  295. The append option with file duplicate detection, means squashfs can be
  296. used as a simple versioning archiving filesystem. A squashfs filesystem can
  297. be created with for example the linux-2.4.19 source.  Appending the linux-2.4.20
  298. source will create a filesystem with the two source trees, but only the
  299. changed files will take extra room, the unchanged files will be detected as
  300. duplicates.
  301.  
  302. 3.6 Miscellaneous options
  303. -------------------------
  304.  
  305. The -info option displays the files/directories as they are compressed and
  306. added to the filesystem.  The original uncompressed size of each file
  307. is printed, along with DUPLICATE if the file is a duplicate of a
  308. file in the filesystem.
  309.  
  310. The -le and -be options can be used to force mksquashfs to generate a little
  311. endian or big endian filesystem.  Normally mksquashfs will generate a
  312. filesystem in the host byte order.  Squashfs, for portability, will
  313. mount different ordered filesystems (i.e. it can mount big endian filesystems
  314. running on a little endian machine), but these options can be used for
  315. greater optimisation.
  316.  
  317. The -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.
  318. This is performed by default to enable the output filesystem file to be mounted
  319. by loopback, which requires files to be a 4K multiple.  If the filesystem is
  320. being written to a block device, or is to be stored in a bootimage, the extra
  321. pad bytes are not needed.
  322.  
  323. 4. FILESYSTEM LAYOUT
  324. --------------------
  325.  
  326. Brief filesystem design notes follow for the original 1.x filesystem
  327. layout.  A description of the 2.0 filesystem layout will be written sometime!
  328.  
  329. A squashfs filesystem consists of five parts, packed together on a byte
  330. alignment:
  331.  
  332.      ---------------
  333.     |  superblock     |
  334.     |---------------|
  335.     |     data    |
  336.     |    blocks    |
  337.     |---------------|
  338.     |    inodes    |
  339.     |---------------|
  340.     |   directories    |
  341.     |---------------|
  342.     |    uid/gid    |
  343.     |  lookup table    |
  344.      ---------------
  345.  
  346. Compressed data blocks are written to the filesystem as files are read from
  347. the source directory, and checked for duplicates.  Once all file data has been
  348. written the completed inode, directory and uid/gid lookup tables are written.
  349.  
  350. 4.1 Metadata
  351. ------------
  352.  
  353. Metadata (inodes and directories) are compressed in 8Kbyte blocks.  Each
  354. compressed block is prefixed by a two byte length, the top bit is set if the
  355. block is uncompressed.  A block will be uncompressed if the -noI option is set,
  356. or if the compressed block was larger than the uncompressed block.
  357.  
  358. Inodes are packed into the metadata blocks, and are not aligned to block
  359. boundaries, therefore inodes overlap compressed blocks.  An inode is
  360. identified by a two field tuple <start address of compressed block : offset
  361. into de-compressed block>.
  362.  
  363. Inode contents vary depending on the file type.  The base inode consists of:
  364.  
  365.     base inode:
  366.         Inode type
  367.         Mode
  368.         uid index
  369.         gid index
  370.  
  371. The inode type is 4 bits in size, and the mode is 12 bits.
  372.  
  373. The uid and gid indexes are 4 bits in length.  Ordinarily, this will allow 16
  374. unique indexes into the uid table.  To minimise overhead, the uid index is
  375. used in conjunction with the spare bit in the file type to form a 48 entry
  376. index as follows:
  377.  
  378.     inode type 1 - 5: uid index = uid
  379.     inode type 5 -10: uid index = 16 + uid
  380.     inode type 11 - 15: uid index = 32 + uid
  381.  
  382. In this way 48 unique uids are supported using 4 bits, minimising data inode
  383. overhead.  The 4 bit gid index is used to index into a 15 entry gid table.
  384. Gid index 15 is used to indicate that the gid is the same as the uid.
  385. This prevents the 15 entry gid table filling up with the common case where
  386. the uid/gid is the same.
  387.  
  388. The data contents of symbolic links are stored immediately after the symbolic
  389. link inode, inside the inode table.  This allows the normally small symbolic
  390. link to be compressed as part of the inode table, achieving much greater
  391. compression than if the symbolic link was compressed individually.
  392.  
  393. Similarly, the block index for regular files is stored immediately after the
  394. regular file inode.  The block index is a list of block lengths (two bytes
  395. each), rather than block addresses, saving two bytes per block.  The block
  396. address for a given block is computed by the summation of the previous
  397. block lengths.  This takes advantage of the fact that the blocks making up a
  398. file are stored contiguously in the filesystem.  The top bit of each block
  399. length is set if the block is uncompressed, either because the -noD option is
  400. set, or if the compressed block was larger than the uncompressed block.
  401.  
  402. 4.2 Directories
  403. ---------------
  404.  
  405. Like inodes, directories are packed into the metadata blocks, and are not
  406. aligned on block boundaries, therefore directories can overlap compressed
  407. blocks.  A directory is, again, identified by a two field tuple
  408. <start address of compressed block containing directory start : offset
  409. into de-compressed block>.
  410.  
  411. Directories are organised in a slightly complex way, and are not simply
  412. a list of file names and inode tuples.  The organisation takes advantage of the
  413. observation that in most cases, the inodes of the files in the directory
  414. will be in the same compressed metadata block, and therefore, the
  415. inode tuples will have the same start block.
  416.  
  417. Directories are therefore organised in a two level list, a directory
  418. header containing the shared start block value, and a sequence of
  419. directory entries, each of which share the shared start block.  A
  420. new directory header is written once/if the inode start block
  421. changes.  The directory header/directory entry list is repeated as many times
  422. as necessary.  The organisation is as follows:
  423.  
  424.     directory_header:
  425.         count (8 bits)
  426.         inode start block (24 bits)
  427.         
  428.         directory entry: * count
  429.             inode offset (13 bits)
  430.             inode type (3 bits)
  431.             filename size (8 bits)
  432.             filename
  433.             
  434. This organisation saves on average 3 bytes per filename.
  435.  
  436. 4.3 File data
  437. -------------
  438.  
  439. File data is compressed on a block by block basis and written to the
  440. filesystem.  The filesystem supports up to 32K blocks, which achieves
  441. greater compression ratios than the Linux 4K page size.
  442.  
  443. The disadvantage with using greater than 4K blocks (and the reason why
  444. most filesystems do not), is that the VFS reads data in 4K pages.
  445. The filesystem reads and decompresses a larger block containing that page
  446. (e.g. 32K).  However, only 4K can be returned to the VFS, resulting in a
  447. very inefficient filesystem, as 28K must be thrown away.   Squashfs,
  448. solves this problem by explicitly pushing the extra pages into the page
  449. cache.
  450.  
  451.  
  452. 5. AUTHOR INFO
  453. --------------
  454.  
  455. Squashfs was written by Phillip Lougher, email plougher@users.sourceforge.net,
  456. in Chepstow, Wales, UK.   If you like the program, or have any problems,
  457. then please email me, as it's nice to get feedback!
  458.