Skip to main content

Check the Filesystem

TST, Hong Kong

Find the Partition

First we need to find the partition of the mounted SD card:

sudo fdisk -l

This returns information about all mounted disks - we can identify our SD card by it's capacity:

Disk /dev/sdb: 29.54 GiB, 31719424000 bytes, 61952000 sectors
Disk model: STORAGE DEVICE
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdb1 8192 61951999 61943808 29.5G c W95 FAT32 (LBA)

Check the Filesystem

fsck cannot be used on a mounted partition. If you do so, there is a high chance that it will damage the filesystem. To check our SD card /dev/sdb1, find the location it was mounted in:

Check the Filesystem

And use the following commands:

umount /run/media/myuser/0012-D687/
fsck /dev/sdb1

fsck from util-linux 2.38.1
fsck.fat 4.2 (2021-01-31)
There are differences between boot sector and its backup.
This is mostly harmless. Differences: (offset:original/backup)
65:01/00
1) Copy original to backup
2) Copy backup to original
3) No action
[123?q]? 1
Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
[12?q]? 1

*** Filesystem was changed ***
The changes have not yet been written, you can still choose to leave the
filesystem unmodified:
1) Write changes
2) Leave filesystem unchanged
[12?q]? 1
/dev/sdb1: 0 files, 1/967616 clusters

There are differences between boot sector and its backup. This is mostly harmless. Differences: (offset:original/backup) 65:01/00: The byte at offset 65 (0x41) is the dirty bit that is set when a drive is not unmounted properly.

Repair the Filesystem

  • -A: Used for checking all filesystems. The list is taken from /etc/fstab.
  • -C: Show progress bar.
  • -l: Locks the device to guarantee no other program will try to use the partition during the check.
  • -M: Do not check mounted filesystems.
  • -N: Only show what would be done – no actual changes are made.
  • -P: If you want to check filesystems in parallel, including root.
  • -R: Do not check root filesystem. This is useful only with ‘-A‘.
  • -r: Provide statistics for each device that is being checked.
  • -T: Does not show the title.
  • -t: Exclusively specify the filesystem types to be checked. Types can be comma separated list.
  • -V: Provide description what is being done.

During the filesystem check, if errors are detected, you can get “fsck” to auto repair the filesystem with the -a flag:

sudo fsck -ar /dev/sdb1

fsck from util-linux 2.38.1
fsck.fat 4.2 (2021-01-31)
/dev/sdb1: 0 files, 1/967616 clusters
/dev/sdb1: status 0, rss 17280, real 0.410190, user 0.028351, sys 0.033435

Benchmarking

Using the gnome-disk-utility:

Check the Filesystem

Check the Filesystem

I am using an SD Card reader that - I know - is very slow. So I cannot estimate the max read/write speeds. But I can check if the speeds are constant:

Check the Filesystem

The first card looks OK with reasonable and consistent speeds. But the second card seems to have some issues:

Check the Filesystem

It becomes a little better after re-formatting (over-writing everything with zeros):

Check the Filesystem