xfsをmount出来なくなった時の対処

## 参考

* [Did I just lose all of my data? - [H]ard|Forum](http://hardforum.com/showthread.php?t=1476237)

## 現象

* USB-SATA変換でHDDを接続していたが、デバイスが外れた。(これはUSB接続ではよくあること。)
  * USB抜き差しやOS再起動してもmountできなくなった。

```bash:mount出来ない
# mount -vvv /dev/sdb1 /media/
mount: fstab path: "/etc/fstab"
mount: mtab path:  "/etc/mtab"
mount: lock path:  "/etc/mtab~"
mount: temp path:  "/etc/mtab.tmp"
mount: UID:        0
mount: eUID:       0
mount: spec:  "/dev/sdf1"
mount: node:  "/media/"
mount: types: "xfs"
mount: opts:  "(null)"
mount: mount(2) syscall: source: "/dev/sdf1", target: "/media/", filesystemtype: "xfs", mountflags: -1058209792, data: (null)
mount: wrong fs type, bad option, bad superblock on /dev/sdf1,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
```

```bash:dmesg
# dmesg | tail
[15109.290419] sd 6:0:0:0: [sdb] 1953525168 512-byte logical blocks: (1.00 TB/931 GiB)
[15109.291359] sd 6:0:0:0: [sdb] Write Protect is off
[15109.291366] sd 6:0:0:0: [sdb] Mode Sense: 00 38 00 00
[15109.294147] sd 6:0:0:0: [sdb] Asking for cache data failed
[15109.294154] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[15109.309960]  sdb: sdb1
[15109.313013] sd 6:0:0:0: [sdb] Attached SCSI disk
[15131.325293] SGI XFS with ACLs, security attributes, realtime, no debug enabled
[15131.330694] XFS (sdb1): bad version
[15131.330720] XFS (sdb1): SB validate failed with error -22.
```


## 対処

```bash:
# apt-get install xfsprogs
```

```bash:
# xfs_repair -n /dev/sdb1
...(略)
found candidate secondary superblock...
verified secondary superblock...
would write modified primary superblock
Primary superblock would have been modified.
Cannot proceed further in no_modify mode.
```

## 最終手段

```bash:
# xfs_repair -L /dev/sdf1
...(略)
disconnected dir inode 3227714795, moving to lost+found
disconnected dir inode 3227714796, moving to lost+found
disconnected dir inode 3227714797, moving to lost+found
disconnected dir inode 3227714798, moving to lost+found
disconnected dir inode 3264730920, moving to lost+found
disconnected dir inode 3264730930, moving to lost+found
disconnected dir inode 3264730934, moving to lost+found
disconnected dir inode 3264730938, moving to lost+found
disconnected dir inode 3265169937, moving to lost+found
disconnected dir inode 3483325977, moving to lost+found
disconnected dir inode 3843207708, moving to lost+found
disconnected dir inode 3843207710, moving to lost+found
Phase 7 - verify and correct link counts...
resetting inode 128 nlinks from 2 to 3
resetting inode 137 nlinks from 2 to 72
resetting inode 42168321 nlinks from 4 to 2
resetting inode 42168322 nlinks from 4 to 2
resetting inode 456134464 nlinks from 4 to 3
resetting inode 456134465 nlinks from 3 to 2
resetting inode 1073741953 nlinks from 3 to 2
resetting inode 1073741954 nlinks from 3 to 2
resetting inode 1513853499 nlinks from 4 to 2
resetting inode 1513853500 nlinks from 4 to 2
resetting inode 1513853501 nlinks from 4 to 2
resetting inode 1513853502 nlinks from 4 to 2
resetting inode 1513853503 nlinks from 4 to 2
resetting inode 1513853516 nlinks from 8 to 6
resetting inode 2149391550 nlinks from 10 to 9
resetting inode 2149391559 nlinks from 4 to 2
resetting inode 2149391560 nlinks from 4 to 2
resetting inode 2149391561 nlinks from 4 to 2
resetting inode 2149391562 nlinks from 4 to 2
resetting inode 3221225600 nlinks from 7 to 6
resetting inode 3227714785 nlinks from 3 to 2
resetting inode 3227714786 nlinks from 3 to 2
resetting inode 3483325977 nlinks from 6 to 5
resetting inode 3843207699 nlinks from 8 to 7
resetting inode 3843207715 nlinks from 3 to 2
Note - stripe unit (0) and width (0) fields have been reset.
Please set with mount -o sunit=<value>,swidth=<value>
done
```

全部`lost+found`に行ってしまったがmount出きるようになった。