fsck

LPIC-1LINUX

Warning: Repairing tools for your file system must be used with caution! While it is safe to only check your file system for inconsistencies, actually attempting a repair may worse the situation. When using these tools, the system must be always unmounted. When you need to check the "/" (root partition), you need to do this from live media.

tl;dr

For repairing tools to work they need your FS to be always unmounted.

e2fsck, fsck.ext2/3/4 with -n it only checks

xfs_repair with -n it only checks

xfs_db “debugger”, it only checks (it inspects the metadata)

btrfs check it only checks

Changing the label:

tune2fs -L "New label" /dev/sdXX (ext2/3/4)

xfs_admin -L "New label" /dev/sdXX

btrfs filesystem label <mount_point or device> "New label"

--------------------------------------------------------------

1 Repairing the system

Use these commands when a file system is corrupted or won't mount.

File System Command Notes

ext2/3/4 e2fsck Usually called via the fsck wrapper. Must be unmounted. -n flag to check only.

xfs xfs_repair Must be unmounted. -n flag to check only.

xfs_db db stands for "Debugger". To view or debug internal metadata. Must be unmounted.

Btrfs btrfs check Must be unmounted.

All the following commands are soft links to e2fsck command:

ls /sbin/fsck.ext?
/sbin/fsck.ext2 /sbin/fsck.ext3 /sbin/fsck.ext4

2 Changing the label of a FS

Warning on changing the label: If you are changing the label for the Root (/) and Boot (/boot) partitions, if your /etc/fstab file is configured to mount your drive using the old label (e.g., LABEL=CentOS7), your machine will fail to boot next time because that label no longer exists! Check your /etc/fstab before making any changes.

a) ext2/3/4

# tune2fs -L "New label" /dev/sdXX

Verify the change:

# tune2fs -l /dev/sdXX | grep <label_name>

b) XFS (the system needs to be unmounted to apply the changes, use a Live ISO for the root and boot FS)

# xfs_admin -L "New label" /dev/sdXX or /dev/mapper/[Volume_name]

Verify the change:

# xfs_admin -l /dev/sdXX

c) btrfs

# btrfs filesystem label <mountpoint_or_device> "New label"

Verify the change:

# btrfs filesystem label <mount_point or device>

4 Review

Question: You are trying to mount an XFS partition, but the kernel reports "structure needs cleaning." You want to check for errors without making any changes. Which command do you use?

  • Answer: xfs_repair -n /dev/sdXX (The -n is the key for "no changes").

Question: Which command allows you to manually inspect the inodes of an XFS file system?

  • Answer: xfs_db

Contact

Email

hello@unixtips.eu

© 2025. All rights reserved.