After a hard drive I/O failue and an attempt at fsck recovery on an ext4 partition, I've got a disk where the numbers of used inode is vastly different according to 'df -i' and according to 'find . | wc -l':
[yan@machine ~]$ ls -di /run/media/yan/data 2 /run/media/yan/data [yan@machine ~]$ lsblk -o NAME,FSTYPE,LABEL,TYPE,SIZE,MOUNTPOINT NAME FSTYPE LABEL TYPE SIZE MOUNTPOINT ... sdc disk 1.8T ├─sdc1 vfat clonezilla part 512M ├─sdc2 ext4 live_system part 14.7G ├─sdc3 ext4 system_images part 244.1G ├─sdc4 ext4 data part 781.3G /run/media/yan/data └─sdc5 ext4 rec part 822.5G [yan@machine data]$ df -i /run/media/yan/data/ Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sdc4 51200000 74199 51125801 1% /run/media/yan/data [yan@machine data]$ sudo find /run/media/yan/data | wc -l 23690
So it seems I have a lot of unconnected inodes, despite fsck telling me partition is clean (even with -f). I'd like to know where the (74199-23690) missing inodes are. I know there are still on the disk because I've managed to get back 50k files using photorec.
So I've try to use debugfs, but I can't find anywhere in the manual a way to dump the list of allocated inodes. (And most post online use find/ls -i to list inodes, which won't work in my case).
Does any one know a way to get the list of inodes used according to df/fsck ?
For now, I'm considering to inefficiently bruteforce with something along the lines of :
for i in `seq 1 $NMAX`; do debugfs -R 'ncheck $i' | grep $i; done > inodelist
with NMAX big enough, but there is surely more efficient way, no ?
I think I have found a possible way.
dumpe2fs list all blocks and free inodes for each block. From it, it should be possible to deduce used inodes.
I still have to compute the list of "non-free inodes" and see if it seems (at least count-wise) to be what I want. From the list, I found some weird inodes apparently connected between themselves, but not to the root :
debugfs: pwd [pwd] INODE: 45220182 PATH: .../dir1/dir2/dir3/dir4 [root] INODE: 2 PATH: / debugfs: cd .. debugfs: pwd [pwd] INODE: 44957702 PATH: .../dir4/dir1/dir2/dir3 [root] INODE: 2 PATH: /