How to use the command `sqfstar` (with examples)
- Linux
- December 25, 2023
The command sqfstar
is used to create a squashfs filesystem from a tar archive. Squashfs is a compressed read-only file system that is commonly used for creating live CDs, embedded systems, and other disk image applications. The sqfstar
command allows users to convert tar archives into squashfs filesystems, giving them the ability to compress and exclude specific files as needed.
Use case 1: Creating a squashfs filesystem from an uncompressed tar archive
Code:
sqfstar filesystem.squashfs < archive.tar
Motivation: This use case is useful when you have an uncompressed tar archive and want to convert it into a squashfs filesystem. The resulting filesystem will be compressed using gzip
by default.
Explanation:
sqfstar
is the name of the command.filesystem.squashfs
is the name of the output squashfs filesystem file.< archive.tar
is the input tar archive file.
Example output: The command will create a compressed squashfs filesystem named filesystem.squashfs
from the uncompressed tar archive archive.tar
.
Use case 2: Creating a squashfs filesystem from a gzip-compressed tar archive and compressing the filesystem using a specific algorithm
Code:
zcat archive.tar.gz | sqfstar -comp gzip|lzo|lz4|xz|zstd|lzma filesystem.squashfs
Motivation: This use case is helpful when you have a tar archive compressed with gzip
but want to use a different compression algorithm for the resulting squashfs filesystem.
Explanation:
zcat archive.tar.gz
extracts the contents of thearchive.tar.gz
file.sqfstar -comp <algorithm>
is used to specify the compression algorithm to be used for the squashfs filesystem. Choose one from the optionsgzip
,lzo
,lz4
,xz
,zstd
, orlzma
.filesystem.squashfs
is the name of the output squashfs filesystem file.
Example output: The command will extract the contents of the archive.tar.gz
file and create a squashfs filesystem named filesystem.squashfs
using the specified compression algorithm.
Use case 3: Creating a squashfs filesystem from an xz-compressed tar archive and excluding certain files
Code:
xzcat archive.tar.xz | sqfstar filesystem.squashfs file1 file2 ...
Motivation: This use case is useful when you have a tar archive compressed with xz
and want to exclude specific files from the resulting squashfs filesystem.
Explanation:
xzcat archive.tar.xz
extracts the contents of thearchive.tar.xz
file.sqfstar
is the name of the command.filesystem.squashfs
is the name of the output squashfs filesystem file.file1 file2 ...
are the names of the files to be excluded from the squashfs filesystem.
Example output: The command will extract the contents of the archive.tar.xz
file, excluding the specified files, and create a squashfs filesystem named filesystem.squashfs
.
Use case 4: Creating a squashfs filesystem from a zstd-compressed tar archive and excluding files ending with .gz
Code:
zstdcat archive.tar.zst | sqfstar filesystem.squashfs "*.gz"
Motivation: This use case is helpful when you have a tar archive compressed with zstd
and want to exclude files that end with the .gz
extension from the resulting squashfs filesystem.
Explanation:
zstdcat archive.tar.zst
extracts the contents of thearchive.tar.zst
file.sqfstar
is the name of the command.filesystem.squashfs
is the name of the output squashfs filesystem file."*.gz"
is a wildcard pattern specifying files ending with the.gz
extension to be excluded from the squashfs filesystem.
Example output: The command will extract the contents of the archive.tar.zst
file, excluding any files that end with .gz
, and create a squashfs filesystem named filesystem.squashfs
.
Use case 5: Creating a squashfs filesystem from a tar archive compressed with lz4 and excluding files matching a regular expression
Code:
lz4cat archive.tar.lz4 | sqfstar filesystem.squashfs -regex "regular_expression"
Motivation: This use case is useful when you have a tar archive compressed with lz4
and want to exclude files that match a specific regular expression from the resulting squashfs filesystem.
Explanation:
lz4cat archive.tar.lz4
extracts the contents of thearchive.tar.lz4
file.sqfstar
is the name of the command.filesystem.squashfs
is the name of the output squashfs filesystem file.-regex "regular_expression"
is an option that allows you to specify a regular expression pattern to exclude matching files from the squashfs filesystem.
Example output: The command will extract the contents of the archive.tar.lz4
file, excluding any files that match the specified regular expression, and create a squashfs filesystem named filesystem.squashfs
.
Conclusion:
The command sqfstar
provides users with the ability to create squashfs filesystems from tar archives, allowing for compression and exclusion of specific files. The provided use cases demonstrate different scenarios where the command can be applied, covering various compression algorithms and file exclusion patterns. By leveraging these use cases, users can effectively utilize the sqfstar
command and leverage the capabilities of squashfs filesystems for their specific needs.