How to use the command unsquashfs (with examples)
- Linux
- December 25, 2023
Unsquashfs is a command-line tool used to uncompress, extract, and list files in squashfs filesystems. Squashfs is a compressed read-only filesystem that is commonly used in embedded systems, Live CDs, and other situations where a lightweight and efficient filesystem is needed.
Use case 1: Extract a squashfs filesystem to squashfs-root
in the current working directory
Code:
unsquashfs filesystem.squashfs
Motivation: This use case is useful when you need to extract the contents of a squashfs filesystem into a designated directory within the current working directory. The extracted files can then be used or analyzed further.
Explanation:
unsquashfs
is the command itself.filesystem.squashfs
is the path to the squashfs file that you want to extract.- When no destination directory is specified, unsquashfs will extract the contents to a directory named
squashfs-root
in the current working directory.
Example output:
Unsquashfs: Filesystem image is read-only. Filesystem attributes will be ignored.
Parallel unsquashfs: Using 4 processors
5 inodes (18 blocks) to write
[========================================================================|] 18/18 100%
created 5 files
created 3 directories
created 3 symlinks
created 0 devices
created 0 fifos
Use case 2: Extract a squashfs filesystem to the specified directory
Code:
unsquashfs -dest path/to/directory filesystem.squashfs
Motivation: This use case is useful when you want to extract the contents of a squashfs filesystem to a specific directory other than the default squashfs-root
.
Explanation:
-dest path/to/directory
is an option to specify the destination directory where the files should be extracted.path/to/directory
is the path to the directory where you want to extract the files.filesystem.squashfs
is the path to the squashfs file that you want to extract.
Example output:
Unsquashfs: Filesystem image is read-only. Filesystem attributes will be ignored.
Parallel unsquashfs: Using 4 processors
5 inodes (18 blocks) to write
[========================================================================|] 18/18 100%
created 5 files
created 3 directories
created 3 symlinks
created 0 devices
created 0 fifos
Use case 3: Display the names of files as they are extracted
Code:
unsquashfs -info filesystem.squashfs
Motivation: This use case is useful when you want to see the names of the files that are being extracted from the squashfs filesystem. It provides a progress update and allows you to monitor the extraction process.
Explanation:
-info
is an option to display the names of files as they are being extracted.filesystem.squashfs
is the path to the squashfs file that you want to extract.
Example output:
File: filesystem.squashfs
Block: 504 - offset: 0x3f45a0 - (root)/
Block: 1592 - offset: 0xc3919 - (root)/file1.txt
Block: 1401 - offset: 0xb2f0b - (root)/file2.txt
Block: 3434 - offset: 0xd5eae - (root)/file3.txt
Block: 1080 - offset: 0x89150 - (root)/directory1/
...
Use case 4: Display the names of files and their attributes as they are extracted
Code:
unsquashfs -linfo filesystem.squashfs
Motivation: This use case is similar to the previous one, but in addition to displaying the names of files, it also shows their attributes. This can be helpful when you need to analyze the files’ properties during the extraction process.
Explanation:
-linfo
is an option to display the names of files and their attributes as they are being extracted.filesystem.squashfs
is the path to the squashfs file that you want to extract.
Example output:
File: filesystem.squashfs
Block: 504 - offset: 0x3f45a0 - (root)/
Size: 0
Compression: 0
Mode: 0
Hard links: 1
...
Use case 5: List files inside the squashfs filesystem (without extracting)
Code:
unsquashfs -ls filesystem.squashfs
Motivation: This use case is useful when you want to get a quick overview of the files present in the squashfs filesystem without actually extracting them. It provides a list of filenames and their paths.
Explanation:
-ls
is an option to list the files inside the squashfs filesystem without extracting them.filesystem.squashfs
is the path to the squashfs file that you want to list the files from.
Example output:
-rw-r--r-- 0 0 0 Aug 12 14:42 2021 (root)/
-rw-r--r-- 2482 0 0 Aug 12 14:42 2021 (root)/file1.txt
-rw-r--r-- 4131 0 0 Aug 12 14:42 2021 (root)/file2.txt
-rw-r--r-- 6475 0 0 Aug 12 14:42 2021 (root)/file3.txt
drwxr-xr-x 0 0 0 Aug 12 14:42 2021 (root)/directory1/
...
Use case 6: List files and their attributes inside the squashfs filesystem (without extracting)
Code:
unsquashfs -lls filesystem.squashfs
Motivation: This use case is similar to the previous one, but in addition to listing the files, it also displays their attributes. This can be useful when you need more detailed information about the files in the squashfs filesystem without actually extracting them.
Explanation:
-lls
is an option to list the files and their attributes inside the squashfs filesystem without extracting them.filesystem.squashfs
is the path to the squashfs file that you want to list the files from.
Example output:
-rw-r--r-- 0 0 0 Aug 12 14:42 2021 (root)/
-rw-r--r-- 2482 0 0 Aug 12 14:42 2021 (root)/file1.txt
-rw-r--r-- 4131 0 0 Aug 12 14:42 2021 (root)/file2.txt
-rw-r--r-- 6475 0 0 Aug 12 14:42 2021 (root)/file3.txt
drwxr-xr-x 0 0 0 Aug 12 14:42 2021 (root)/directory1/
...
Conclusion:
The unsquashfs
command is a versatile tool for working with squashfs filesystems. It allows you to extract the contents of a squashfs filesystem, display file names and attributes during extraction, and list files without extracting them. These use cases provide flexibility and convenience when dealing with squashfs files, making the extraction and analysis process easier.