Home / Alt manpages / fsck.cramfs(8)

  • fsck.cramfs(8)
  • Admin command
  • linux

Check a cramfs Image Safely with fsck.cramfs

You will validate a compressed ROM file system image, test that its contents can be decompressed, and optionally extract those contents into a new directory. The commands below do not repair an image and do not mount it.

Allow about ten minutes. You need a readable cramfs image and the fsck.cramfs command from util-linux. The local manpage describes util-linux 2.39.3. The command found first on this machine is the Homebrew build of util-linux 2.41.3, so the examples are checked against that executable as well as the installed manual. Check your own version before relying on exact diagnostic wording.

Safety boundary

The normal check is read-only. Extraction writes new files, so choose a destination that does not already exist and do not point it at a directory containing anything you need to keep.

1. Confirm the executable and version

First establish which copy of the command your shell will run:

$ command -v fsck.cramfs
/home/linuxbrew/.linuxbrew/sbin/fsck.cramfs
$ fsck.cramfs --version
fsck.cramfs from util-linux 2.41.3

Your path and version may differ. The important detail is to avoid checking an image with one release and then diagnosing a different executable later. The command accepts one image path after its options:

$ fsck.cramfs /path/to/image.cramfs

No root privileges are normally needed to read an image in a directory you can access. Do not add sudo automatically. Use elevated privileges only when the file's permissions genuinely require it, and keep the output and destination paths explicit.

2. Run the ordinary check

Run the check against the image:

$ fsck.cramfs /path/to/image.cramfs
$ printf 'status=%s\n' "$?"
status=0

A successful ordinary check may print nothing. Exit status 0 is the useful result: the image passed the check. If you want an explanation on standard output, add --verbose:

$ fsck.cramfs --verbose /path/to/image.cramfs
cramfs endianness is little
/path/to/image.cramfs: OK

The verbose endianness line is information about the image, not a request to convert it. Keep the command's status separate from its text if a script will consume the result.

Checkpoint

You have a read-only validation result. If the status is not 0, keep the original image unchanged and continue to the failure section rather than trying options at random.

3. Test full decompression without extracting

Use --extract without a directory when you want the program to test uncompression but do not need a copy of the files:

$ fsck.cramfs --extract /path/to/image.cramfs
$ printf 'status=%s\n' "$?"
status=0

This is a stronger check than reading only the image header. It asks the program to process the complete compressed file system. It still does not mount the image and does not alter the input. A successful status means the command completed its decompression test; it does not prove that every application-level file is the content you intended.

4. Extract into a new directory when you need the files

Pass a directory with an equals sign or as the optional argument to --extract. The destination must not already exist. For a disposable inspection, use a clearly named path under /tmp:

$ work=/tmp/cramfs-inspection-12345
$ fsck.cramfs --extract="$work" /path/to/image.cramfs
$ printf 'status=%s\n' "$?"
status=0
$ find "$work" -type f -printf '%P\n' | sort
etc/example.conf
usr/share/example/readme.txt

Replace the placeholder directory with a fresh path. The installed command returns an operation error when it cannot create the requested destination, including when that path already exists. Treat that as a safe failure: choose another empty path and rerun. Do not overwrite a useful directory just to satisfy the command.

Inspect extracted text or compare known files before removing the directory. If you created it only for a temporary check, remove that exact temporary directory after inspection with your normal cleanup process. There is no undo for deleting the only extracted copy, so retain the source image and any files you may need.

5. Interpret the exit statuses

Capture the status immediately after the command. The documented values are:

StatusMeaningNext action
0SuccessRecord the check as passed.
4The file system was left uncorrectedPreserve the image and investigate the diagnostic; this command does not repair it.
8Operation error, such as failure to allocate memoryCheck the path, permissions, destination and available resources.
16Usage information was printedCorrect the command syntax or option values.

A missing input commonly produces status 8 with an error saying that the file cannot be opened. That is an input or access problem, not evidence that the image contents are corrupt. Check the exact path with ls -l and rerun the command without changing the image.

6. Use blocksize only for extraction

The --blocksize option changes the block size used by the extraction test. Its default is the system page size, and the value must match the block size used when the image was created. The option is only used with --extract:

$ fsck.cramfs --extract=/tmp/cramfs-inspection-67890 --blocksize 4096 /path/to/image.cramfs
$ printf 'status=%s\n' "$?"
status=0

Do not guess this value. An incorrect value can make a valid image fail extraction, while a passing check with the default does not tell you what creation-time setting was used. If you do not have reliable creation metadata, omit --blocksize.

7. Avoid the repair-shaped options

The names -a and -y are accepted for compatibility but silently ignored. They do not approve repairs, answer prompts or change the image. The local manpage lists no repair operation for fsck.cramfs. If an image fails, keep it as evidence, make a separate copy for experiments, and obtain a known-good image or use a documented image-recovery workflow rather than expecting this command to fix it.

For a script, distinguish a clean result from an operational failure:

if fsck.cramfs --extract /path/to/image.cramfs; then
    printf '%s\n' 'cramfs decompression check passed'
else
    status=$?
    printf 'cramfs check failed with status %s\n' "$status" >&2
    exit "$status"
fi

Keep the original exit status. Parsing the word OK from verbose output is less reliable than testing the documented status value.

Done means

  • fsck.cramfs --version identified the executable you intended to use.
  • The ordinary check returned status 0, or you recorded and investigated its documented failure status.
  • The optional full decompression test passed when content integrity mattered.
  • Any extraction used a new, disposable destination and left the source image untouched.
  • You did not treat -a or -y as repair controls, and you did not guess a block size.