ddrescue,当使用较大的磁盘进行磁盘复制时进行第二次磁盘复制,以从故障硬盘进行第一次复制

ddrescue,当使用较大的磁盘进行磁盘复制时进行第二次磁盘复制,以从故障硬盘进行第一次复制

我的硬盘出现故障,第一次使用 Testdisk 时,速度非常慢,之后我使用 ddrescue 复制磁盘。原始磁盘是一个 2TB 的驱动器,有 4 个 NTFS 分区(我在实时 ubuntu 系统上错误地将其格式化为 ext4)。

现在,我在 Ubuntu 上使用 ddrescuesudo ddrescue -d -f -r3 /dev/sdb /dev/sdc sdc.log

我使用一个新的 4TB 硬盘进行复制,现在我想制作第二个副本。对于第二个副本,我有另一个新的 4TB 驱动器,它与第一个复制驱动器不同。我读到目标驱动器必须大小相同或至少更大。现在我的中间驱动器比第一个故障驱动器(2TB)大。如果我的第二个目标驱动器比中间驱动器小几 MB 怎么办?ddrescue 会无法在第二个驱动器上写入数据吗?或者它会在第一个复制驱动器上的原始 2TB 数据结束后停止写入吗?

无论是哪种情况我该怎么办?

提前致谢。

更新于 2023 年 2 月 21 日:下面是日志文件文本(我将 sdc.log 文件复制到 USB 上并单独打开它):

# Mapfile. Created by GNU ddrescue version 1.26
# Command line: ddrescue -d -f -r3 /dev/sdb /dev/sdc sdc.log
# Start time:   2023-02-18 05:03:10
# Current time: 2023-02-21 10:47:14
# Copying non-tried blocks... Pass 1 (forwards)
# current_pos  current_status  current_pass
0x610FA80000     ?               1
#      pos        size  status
0x00000000  0x47AC630000  +
0x47AC630000  0x00010000  *
0x47AC640000  0x01320000  ?
0x47AD960000  0x479140000  +
0x4C26AA0000  0x00010000  *
0x4C26AB0000  0x01320000  ?
0x4C27DD0000  0x2FA860000  +
0x4F22630000  0x00010000  *
0x4F22640000  0x01320000  ?
0x4F23960000  0x1F7230000  +
0x511AB90000  0x00010000  *
0x511ABA0000  0x01320000  ?
0x511BEC0000  0x32780000  +
0x514E640000  0x00010000  *
0x514E650000  0x01320000  ?
0x514F970000  0xC5D00000  +
0x5215670000  0x00010000  *
----------------------------------------------------

以下是在此处输入图片描述终点站:

其次,当我尝试使用 smartctl -a /dev/sdb >myreport 运行 smarttools 时


以下是来自 SMART 工具的报告:(使用“sudo smartctl -a /dev/sdb >myreport”运行)

smartctl 7.3 2022-02-28 r5338 [x86_64-linux-5.19.0-21-generic] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Barracuda 7200.14 (AF)
Device Model:     ST2000DM001-1ER164
Serial Number:    W4Z3P9PN
LU WWN Device Id: 5 000c50 09b8366dd
Firmware Version: CC26
User Capacity:    2,000,398,934,016 bytes [2.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        In smartctl database 7.3/5319
ATA Version is:   ACS-2, ACS-3 T13/2161-D revision 3b
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Tue Feb 21 11:10:57 2023 UTC
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
See vendor-specific Attribute list for marginal Attributes.

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                    was completed without error.
                    Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                    without error or no self-test has ever 
                    been run.
Total time to complete Offline 
data collection:        (   80) seconds.
Offline data collection
capabilities:            (0x7b) SMART execute Offline immediate.
                    Auto Offline data collection on/off support.
                    Suspend Offline collection upon new
                    command.
                    Offline surface scan supported.
                    Self-test supported.
                    Conveyance Self-test supported.
                    Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                    power-saving mode.
                    Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                    General Purpose Logging supported.
Short self-test routine 
recommended polling time:    (   1) minutes.
Extended self-test routine
recommended polling time:    ( 209) minutes.
Conveyance self-test routine
recommended polling time:    (   2) minutes.
SCT capabilities:          (0x1085) SCT Status supported.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   110   080   006    Pre-fail  Always       -       215372854
  3 Spin_Up_Time            0x0003   096   095   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   096   096   020    Old_age   Always       -       4686
  5 Reallocated_Sector_Ct   0x0033   079   079   010    Pre-fail  Always       -       26840
  7 Seek_Error_Rate         0x000f   082   060   030    Pre-fail  Always       -       168010836
  9 Power_On_Hours          0x0032   064   064   000    Old_age   Always       -       32234
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   096   096   020    Old_age   Always       -       4690
183 Runtime_Bad_Block       0x0032   091   091   000    Old_age   Always       -       9
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   001   001   000    Old_age   Always       -       3934
188 Command_Timeout         0x0032   100   052   000    Old_age   Always       -       112 301 483
189 High_Fly_Writes         0x003a   098   098   000    Old_age   Always       -       2
190 Airflow_Temperature_Cel 0x0022   062   034   045    Old_age   Always   In_the_past 38 (Min/Max 26/41 #1798)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       191
193 Load_Cycle_Count        0x0032   001   001   000    Old_age   Always       -       224369
194 Temperature_Celsius     0x0022   038   066   000    Old_age   Always       -       38 (0 8 0 0 0)
197 Current_Pending_Sector  0x0012   001   001   000    Old_age   Always       -       37904
198 Offline_Uncorrectable   0x0010   001   001   000    Old_age   Offline      -       37904
199 UDMA_CRC_Error_Count    0x003e   200   199   000    Old_age   Always       -       68
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       19597h+41m+10.668s
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       57999941039
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       1327164476473

SMART Error Log Version: 1
ATA Error Count: 3937 (device log contains only the most recent five errors)
    CR = Command Register [HEX]
    FR = Features Register [HEX]
    SC = Sector Count Register [HEX]
    SN = Sector Number Register [HEX]
    CL = Cylinder Low Register [HEX]
    CH = Cylinder High Register [HEX]
    DH = Device/Head Register [HEX]
    DC = Device Command Register [HEX]
    ER = Error register [HEX]
    ST = Status register [HEX]
Powered_Up_Time is measured from power on, and printed as
DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,
SS=sec, and sss=millisec. It "wraps" after 49.710 days.

Error 3937 occurred at disk power-on lifetime: 32223 hours (1342 days + 15 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 53 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 80 ff ff ff 4f 00   2d+19:53:57.102  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+19:53:57.101  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+19:53:57.101  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+19:53:57.101  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+19:53:57.100  READ FPDMA QUEUED

Error 3936 occurred at disk power-on lifetime: 32222 hours (1342 days + 14 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 53 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 80 ff ff ff 4f 00   2d+18:50:34.589  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:50:34.588  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:50:34.588  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:50:34.587  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:50:34.587  READ FPDMA QUEUED

Error 3935 occurred at disk power-on lifetime: 32221 hours (1342 days + 13 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 53 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 80 ff ff ff 4f 00   2d+18:04:18.861  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:04:18.861  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:04:18.861  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:04:18.860  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+18:04:18.860  READ FPDMA QUEUED

Error 3934 occurred at disk power-on lifetime: 32221 hours (1342 days + 13 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 53 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 80 ff ff ff 4f 00   2d+17:50:52.906  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+17:50:52.906  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+17:50:52.905  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+17:50:52.905  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+17:50:52.905  READ FPDMA QUEUED

Error 3933 occurred at disk power-on lifetime: 32219 hours (1342 days + 11 hours)
  When the command that caused the error occurred, the device was active or idle.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 53 00 ff ff ff 0f  Error: UNC at LBA = 0x0fffffff = 268435455

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  60 00 80 ff ff ff 4f 00   2d+15:56:40.578  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+15:56:40.016  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+15:56:39.728  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+15:56:36.988  READ FPDMA QUEUED
  60 00 80 ff ff ff 4f 00   2d+15:56:36.988  READ FPDMA QUEUED

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

-----------------------------------------------

答案1

如果我的第二个目标驱动器比中间驱动器小几 MB 怎么办?无法ddrescue将数据写入第二个驱动器?

确实会,但只有当它试图写入超出第二个驱动器的大小时才会发生。通常,第一次传递是正向进行的,因此如果没有读取错误,那么在发生写入错误时,整个第二个驱动器将被重写。

或者当第一个复制驱动器上的原始 2TB 数据结束后,它就会停止写入?

不会。就ddrescue第一个复制驱动器而言,不会显示复制结束的位置。您可以将每个驱动器视为一个线性字节序列;每个序列都有自己的长度,即相应设备的大小。将一个序列(的一部分)复制到另一个序列(的一部分)不会改变后者的长度。在这方面,驱动器与常规文件不同,您无法轻易截断它们。

无论是哪种情况我该怎么办?

首先是其他内容。仅复制您需要的部分。例如,从中间驱动器-s复制ddrescue到第二个驱动器时可以使用:

-s bytes
--size=bytes
救援域的最大大小(以字节为单位)。它限制要复制的输入数据量。[…] 如果 ddrescue 无法确定输入文件的大小,您可能需要使用此选项指定它。[…]

来源

您应该指定精确的原始驱动器的大小或更大的数字。如果有任何疑问,请使用更大的数字。如果使用更大的数字,ddrescue则会尝试复制 2TB 数据以外的一些垃圾。关键是您希望这些垃圾足够小。不使用此选项进行复制-s将获得中间驱动器中的几乎所有垃圾,完全是徒劳的。

即使您提供了准确的数字,那么在ddrescue完成后,第二个驱动器将包含超过 2TB 数据的垃圾,因为其中也没有指示复制在何处结束。

希望在此阶段不会出现读取错误。如果是这样,那么您应该将第一阶段(即您的sdc.log)的映射文件视为与两个副本相关。

如果原始驱动器使用 GPT,请参阅这个答案了解如何在副本上修复 GPT,以防您选择这样做。


供将来参考:在类似情况下,请考虑创建文件系统并使用ddrescue写入常规文件在文件系统内。如果您对中间驱动器和第二个驱动器执行此操作,则复制副本将意味着将常规文件从一个文件系统复制到另一个文件系统;您可以使用 执行此操作cp,而不必担心大小。

在第二个驱动器上创建文件系统并将内容从中间驱动器复制到那里的常规文件还不算太晚。-s但您仍需要使用,因为中间驱动器上没有指示复制结束的位置。

我个人更喜欢ddrescue在支持的文件系统中使用常规文件奶牛(例如 Btrfs)。然后我可以制作一个非 CoW 副本 ( cp --reflink=never) 以实现冗余(如果需要,可以制作到另一个文件系统)并在文件系统内制作任意数量的 CoW 副本 ( cp --reflink=always)。在这些 CoW 副本中,我将其中一个视为不可变的 ( chattr +i) 并与其他副本一起使用,可能使用修改数据的工具。这样,如果修改出现任何问题,我始终可以立即创建不可变副本的新 CoW 副本,而不会对磁盘​​造成压力。

(附注:Btrfs 支持压缩,有几次我成功地将磁盘映像作为常规文件存储在更小磁盘并使用它。

常规文件的缺点是,您需要一些知识和工具才能访问存储在其中的分区。我的意思是,如果您的副本处于打开状态,/dev/sdz则操作系统将在磁盘连接或打开时自动创建等sdz1(除非原始和副本之间的逻辑扇区大小不匹配,请参阅sdz2partprobe这个问题和我的回答看看问题是什么);但如果您的副本位于 中,regular_file那么您将不会获得regular_file1regular_file2分区。有用的工具:

  • mount -o offset=… …
  • losetup -o … --sizelimit … …
  • kpartx …

另一个缺点是您无法从常规文件启动。如果您打算尝试从副本启动,那么直接复制到块设备更为合理。

答案2

如果我的第二个目标驱动器比中间驱动器小几 MB 怎么办?

这对你的情形来说无关紧要,因为有缺陷的源是 2TB,而你的逐扇区副本完全适合第一个 4 TB 磁盘。如果第二个 4 TB 磁盘比第一个磁盘小一点(几 MB),你的有缺陷的源仍然会完全包含在第二个副本中。

顺便说一句,该软件名为 Testdisk,而不是“测试磁盘”。如果错误地输入了重要的关键字,则会降低此论坛的搜索能力。我已更正了您的帖子。

或者当第一个复制驱动器上的原始 2TB 数据结束后,它就会停止写入?

不。ddrescue 不知道您如何创建第一个副本。它不会尝试解释第一个副本上的数据。ddrescue 将复制所有 4 TB。

相关内容