Corrupted Filesystems

(Reproduce & Troubleshoot Series)

1 Overview

When an inode becomes invalid, the filesystem is considered as corrupted.

Reproduce cases:

2 Lab

2.1 Initial Setup

vm$ apk add lsblk e2fsprogs-extra util-linux file

2.2 Create a Filesystem

container$ qemu-img create -f qcow2 disk.qcow2 2G
# Switch from VM console to QEMU monitor:   Ctrl + A C

# Plug disk to VM
(qemu) drive_add 0 file=disk.qcow2,media=disk,if=none,id=mydrive
(qemu) device_add virtio-blk-pci,drive=mydrive,id=mydevice

# Switch from QEMU monitor to VM console:   Ctrl + A C

# Check if disk added
vm$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda    253:0    0    2G  0 disk
vm$ fdisk /dev/vda
(fdisk) o   # create a new empty DOS partition table
(fdisk) w   # write changes

vm$ fdisk /dev/vda
(fdisk) n   # add a new partition
            # partition type: primary partition
            # partition number: (default)
            # first sector: (default)
            # last sector: +1G
(fdisk) w   # write changes

vm$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda    253:0    0    2G  0 disk
└─vda1 253:1    0    1G  0 part
vm$ mkfs -t ext4 /dev/vda1
vm$ fsck -fn /dev/vda1
vm$ mkdir /mnt/vda1
vm$ mount /dev/vda1 /mnt/vda1

3 Orphaned Files

3.1 Reproduce

The inode link count is the number of filenames or hard links that point to the inode. An inode with a zero link count is known as an orphaned file. The fsck considers an orphaned file as a incomplete deletion error.

vm$ echo 'Hello A' > /mnt/vda1/file_a
vm$ umount /mnt/vda1
vm$ debugfs -w /dev/vda1

(debugfs) ls -l
#   inode   filetype & mode     link_count      uid    gid      size    last modification   name
     13     100644              (1)             0      0        8       13-Sep-2026 10:04   file_a

(debugfs) show_inode_info file_a
Inode: 13   Type: regular    Mode:  0644   Flags: 0x80000
Links: 1
(debugfs) set_inode_field file_a links_count 0

(debugfs) show_inode_info file_a
Inode: 13   Type: regular    Mode:  0644   Flags: 0x80000
Links: 0
vm$ fsck -fn /dev/vda1
Pass 2: Checking directory structure
Entry 'file_a' in / (2) has deleted/unused inode 13.  Clear? no
/dev/vda1: WARNING: Filesystem still has errors
vm$ mount /dev/vda1 /mnt/vda1

vm$ ls /mnt/vda1/
ls: /mnt/vda1/file_a: Data consistency error
lost+found

4 Invalid-Mode Files

4.1 Reproduce

vm$ echo 'Hello B' > /mnt/vda1
vm$ umount /mnt/vda1
vm$ debugfs -w /dev/vda1

(debugfs) ls -l
#    inode     filetype & mode     link_count      uid    gid      size    last modification   name
     14        100644              (1)             0      0        8       18-Sep-2026 15:08   file_b

# filetype & mode: 100644 (octal)
#     10: file type, 0: special permission, 644: owner,group,other permissions
# new mode: 020644 (oct) = 8612 (dec)
#           02: character device, 0: special permission, 644: owner,group,other permissions
(debugfs) set_inode_field file_b mode 8612

(debugfs) ls -l
#    inode     filetype & mode     link_count      uid    gid      size    last modification   name
     14        020644              (1)             0      0        8       18-Sep-2026 15:08   file_b
vm$ fsck -fn /dev/vda1
Pass 2: Checking directory structure
Inode 14 (/file_b) is an illegal character device.
/dev/vda1: WARNING: Filesystem still has errors
vm$ mount /dev/vda1 /mnt/vda1/
vm$ ls -lh /mnt/vda1
total 20K    
crw-r--r--    1 root     root      243,  10 Sep 18 15:08 file_b

5 References