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