Skip to content

Instantly share code, notes, and snippets.

@hdevalence
Last active December 17, 2022 06:28
Show Gist options
  • Save hdevalence/8088497 to your computer and use it in GitHub Desktop.
Save hdevalence/8088497 to your computer and use it in GitHub Desktop.
Btrfs corrupt file locator
#!/usr/bin/bash
echo "Looking for failed csum inodes...."
inodes=`dmesg | grep csum | sed 's/^.*ino \([0-9]*\) .*$/\1/g' | uniq`
echo "Finding system files from inodes..."
sysfiles=`for i in $inodes; do find /etc /opt /root /srv /usr /var -inum $i 2>/dev/null; done`
echo "Finding user files from inodes..."
homefiles=`for i in $inodes; do find /home -inum $i 2>/dev/null; done`
echo "Attempting to reinstall corrupted packages..."
# Get list of packages with corrupt files
packages=$(for f in $sysfiles; do pacman -Qqo $f 2>/dev/null; done)
# Reinstall corrupted packages
pacman -S $(echo $packages | uniq)
# Find other system files
othersys=$(for f in $sysfiles; do pacman -Qqo $f 2>&1 | grep error | sed 's/error: No package owns \(.*\)$/\1/'; done)
echo "Unowned system files:"
for f in $othersys; do echo -e " $f"; done
echo "User files:"
for f in $homefiles; do echo -e " $f"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment