【原】群晖btrfs系统修复

【背景】

前几日因为电源插头松动等原因导致频繁掉电;

同时,由于又使用了傲腾做缓存。

在某一日重启之后,虚拟机就没法启动了。

应该是硬盘出了问题。但是因为电源问题, 没法整。

这两天新买的电源回来了,插上硬盘开始尝试修复

 

【环境】

win10 ltsc

vmware

dsm6.2

1T+1T 储存池 raid0  NTFS==》 虚拟1T vmdk 

4T basic NTFS ==》虚拟4T vmdk

 

【过程】

因为只是1T的挂掉了,所以只用修复1t的

1.因为是raid0,可以取出一个硬盘,以防万一

2.新建一个ubuntu的虚拟机,安装相关软件

sudo -i # 所以步骤都需要管理员权限
apt update && apt install -y mdadm lvm2 btrfs-prog

3.备份一个副本

参考1

参考2

dd if=/dev/sdd of=1t.img bs=8M # 使用dd备份镜像,尽量不动原始数据
losetup --partscan --find --show 1t.img # 扫描 loop 设备
lsblk # 扫描一下,如果没有出现loop再尝试下面的,我好像没有用到下面的
#mkdir $DISK_PATH0 # 挂载 loop,可能不大需要
#mount /dev/loop0pX $DISK_PATH0 

3.群晖默认启用软raid,所以要挂载软raid

参考3

mdadm -Av /dev/md3 /dev/loop18p3 #挂载loop
# mdadm -Asf && vgchange -ay 这个命令可以自动挂载全部
lsblk # 检查一下,出现下面这种就是正常的

——————————————

loop18       7:18   0  1000G  0 loop  
├─loop18p1 259:3    0   2.4G  0 loop  
├─loop18p2 259:4    0     2G  0 loop  
└─loop18p3 259:5    0 995.4G  0 loop  
  └─md3      9:3    0 995.4G  0 raid1


4.磁盘修复

参考4

按照官当的文档,下一步直接挂载md3就可以读出数据了。

不过可能是我的损坏的比较厉害,挂载报错,只能再想办法了。

一定要确定文件系统,我之前以为是ext4,结果证明是btrfs,还好是在镜像上操作的。

如果不确定可以试试fsck.ext4会有提示

btrfs-find-root /dev/md3 &> /tmp/root.txt
head /tmp/root.txt
______
# Couldn't setup extent tree
# Superblock thinks the generation is 12684
# Superblock thinks the level is 1
# Found tree root at 394632675328 gen 12684 level 1
# Well block 394631839744(gen: 12683 level: 1) seems good, but generation/level doesn't # # match, want gen: 12684 level: 1
# Well block 394631561216(gen: 12682 level: 1) seems good, but generation/level doesn't # # match, want gen: 12684 level: 1
# Well block 394631364608(gen: 12681 level: 1) seems good, but generation/level doesn't # # match, want gen: 12684 level: 1
# Well block 394630971392(gen: 12680 level: 1) seems good, but generation/level doesn't # # match, want gen: 12684 level: 1
# Well block 394630627328(gen: 12679 level: 1) seems good, but generation/level doesn't # # match, want gen: 12684 level: 1
# Well block 394630348800(gen: 12678 level: 1) seems good, but generation/level doesn't # # match, want gen: 12684 level: 1
______
btrfs check --tree-root  --super  
#  从上往下尝试 ,如394631839744, = 0/1/2

# 跟参考4中的不一样,我这里报错了,多了个Error
————————
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# checking free space cache
# cache and super generation don't match, space cache will be invalidated
# checking fs roots
# checking csums
# checking root refs
# ERROR: transid errors in file system
# found 296381579264 bytes used, error(s) found
# total csum bytes: 290972
# total tree bytes: 298598400
# total fs tree bytes: 280166400
# total extent tree bytes: 17727488
# btree space waste bytes: 54920864
# file data blocks allocated: 359966142464
#  referenced 359930527744
————————
btrfs check --repair --tree-root  --super  


#我使用了跟上面一样的参数,这次就没什么问题
#但是如果再次使用上面的命令,还是一样的报错
————————
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# Invalid key type(BLOCK_GROUP_ITEM) found in root(202)
# ignoring invalid key
# No device size related problem found
# checking free space cache
# cache and super generation don't match, space cache will be invalidated
# checking fs roots
# checking csums
# checking root refs
# found 296381579264 bytes used, no error found
# total csum bytes: 290972
# total tree bytes: 298598400
# total fs tree bytes: 280166400
# total extent tree bytes: 17727488
# btree space waste bytes: 54920864
# file data blocks allocated: 359966142464
#  referenced 359930527744
————————
btrfs rescue super-recover /dev/md3 
# All supers are valid, no need to recover
# 既然这一步啥也没干,那就尝试挂载吧

mkdir btrfs
root@m-server:/media/ubuntu# mount /dev/md3 ./btrfs/
root@m-server:/media/ubuntu# ls btrfs/
# bo_nas     @download     oct_nas           svn                 @synophoto-bin-r.core  @synophoto-geoco.core  @synorcd.core
@database  @eaDir        @pulseaudio.core  @synoaudiod.core    @synophoto-bin-t.core  @synophoto-perso.core  TimeMachine
DDSM1      homes         R1                @synoelasticd.core  @synophoto-conce.core  @synophoto-task-.core  @tmp
ddsm2      @ipcalc.core  @sharesnap        @synologydrive      @synophoto-face-.core  @synophoto-thumb.core

# 挂载成功,愉快的拷贝出来就可以了

 

你可能感兴趣的:(私有云)