大网数据广告活动
服务器运维问答

Recovering data from a zpool with a missing device

· 52CE 我爱测

I have a zpool consisting of two mirrored drives, storing all my personal data. I wanted to add another mirror drive, since the other drives have been in use for several years now. Instead, I managed to cripple the pool and canno…

问题原文

原帖链接 · soulmerge · CC BY-SA 4.0

I have a zpool consisting of two mirrored drives, storing all my personal data. I wanted to add another mirror drive, since the other drives have been in use for several years now. Instead, I managed to cripple the pool and cannot import it any longer.

This was the original layout of the pool (called "vault") before I did anything:

vault
  mirror-0
    sdd
    sdh

I tried to add another drive by issuing zpool add vault /dev/sdc, and got a warning from zpool (something about expecting a vdev, but scd being a disk). I ignored the warning, and forced the operation with -f (yes, that was pretty stupid ... )

I ended up with the following pool configuration:

vault
  mirror-0
    sdd
    sdh
  sdc

Noticing that sdc was not part of the mirror, I tried to remove it from the pool again and realized that this is not possible. I ignored the extra drive and rebooted, and assumed that my data is already safe inside the mirror-0 and decided to use repurpose sdc and use another drive instead, overwriting the first 100MB of sdc with zeros: dd if=/dev/zero of=/dev/sdc bs=1MB count=100 (yes, I am particularly stupid today ... )

Now when I try to import my zpool, I get the following error:

root@atlas:~# zpool import                                                                                                                         
   pool: vault                                                                                                                                     
     id: 3553551207657826252                                                                                                                       
  state: UNAVAIL                                                                                                                                   
 status: One or more devices are missing from the system.                                                                                          
 action: The pool cannot be imported. Attach the missing                                                                                           
        devices and try again.                                                                                                                     
   see: http://zfsonlinux.org/msg/ZFS-8000-6X                                                                                                      
 config:                                                                                                                                           
                                                                                                                                                   
        vault        UNAVAIL  missing device                                                                                                       
          mirror-0   ONLINE                                                                                                                        
            sdd      ONLINE                                                                                                                        
            sdh      ONLINE                                                                                                                        
                                                                                                                                                   
        Additional devices are known to be part of this pool, though their                                                                         
        exact configuration cannot be determined.                                                                                                  

The data in the mirror on these drives is extremely important to me, and I really hope there is a way of restoring the data from the "partial" pool. Since I had rebooted a few minutes after the bogus add operation, I am assuming that the metadata for the file system was wiped, and that there is a way to access the raw data somehow. But I have no clue where to start.

Can anyone help me with this?

已采纳解答

原帖链接 · soulmerge · CC BY-SA 4.0

I have managed to recover parts of the data by upgrading debian to bullseye (in order to have access to a more recent version of zdb) and importing the zpool with missing vdevs:

echo 1 >> /sys/module/zfs/parameters/zfs_max_missing_tvds
zpool import -o readonly=on vault

Some of the filesystems on the zpool were corrupt, though. I have copied the intact data onto a new zpool, and probed earlier txg values to find one that did not throw any errors:

zdb -e vault -ul | grep ' txg' | sed 's/.*= //' | sort | head
zdb -deG -o zfs_max_missing_tvds=1 -T 5102203 vault  # <- errors
zdb -deG -o zfs_max_missing_tvds=1 -T 5102202 vault  # <- errors
zdb -deG -o zfs_max_missing_tvds=1 -T 5102201 vault  # <- worked!

I was then able to import the zpool at the intact transaction group id:

zpool import -o readonly=on -T 5102201 vault

This command took about 15 hours for my 2x4TB mirror, but I could access all my files again. The data has since been copied onto a new zpool that I won't ever touch in a sleep-deprived state again.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-11-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。