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

Cloning data from a damaged SSD

· 52CE 我爱测

The SSD went into read-only mode, so you need to move the partition to a working SSD, but I encountered the fact that the LVM size is different: #lvm pvscan PV /dev/sdc3 VG pve lvm2 [<111.29 GiB / 13.87 GiB free] PV /dev/sdb3 VG …

问题原文

原帖链接 · Джон Смит · CC BY-SA 4.0

The SSD went into read-only mode, so you need to move the partition to a working SSD, but I encountered the fact that the LVM size is different:

#lvm pvscan

PV /dev/sdc3 VG pve lvm2 [<111.29 GiB / 13.87 GiB free]

PV /dev/sdb3 VG pve lvm2 [<118.74 GiB / 14.75 GiB free]

It will not be possible to transfer through DD due to the difference in volume.

sudo dd if=/dev/sdb3 of=/dev/sdc3 status=progress

What other ways are there? Maybe there is software to clone partitions from under the BIOS?

UPD: Both SSDs are connected via an NVME-usb adapter. I am working through live linux on iODD-2531. And I, in turn, connect to the system via ssh.

Copying from a 128gb drive to a 120gb drive. If the first drive wasn't write-protected, I could try to reduce the size of the partition, and then copy using DD.

UPD:

I connected a 500GB drive for the test and started copying using DD. As a result I get an error:

ubuntu@ubuntu:~$ sudo dd if=/dev/sdd of=/dev/sdc status=progress
456839680 bytes (457 MB, 436 MiB) copied, 53 s, 8.6 MB/s
459821568 bytes (460 MB, 439 MiB) copied, 57 s, 8.1 MB/s
461292032 bytes (461 MB, 440 MiB) copied, 59 s, 7.8 MB/s
569393664 bytes (569 MB, 543 MiB) copied, 72 s, 7.9 MB/s
709820928 bytes (710 MB, 677 MiB) copied, 85 s, 8.4 MB/s
dd: error reading '/dev/sdd': Input/output error
1388520+0 records in
1388520+0 records out
710922240 bytes (711 MB, 678 MiB) copied, 93.8062 s, 7.6 MB/s

This is a copy error. SSD patriot p300, it continued to degrade and more than 50% of bad sectors. The topic can be closed. The drive is dead. Thx.

已采纳解答

原帖链接 · Nikita Kipriyanov · CC BY-SA 4.0

You have to shrink the PV before cloning it with dd, but read only status of the SSD prohibits this.

But, using an overlay difference image you can still do it. In general it is the same as I described in detail in the other answer. I'll describe only differences here.

  1. Create a difference overlay scratch image file with physical backing device — old SSD, in qemu-img arguments have -b /dev/sdb3.
  2. Load the nbd driver and attach the image file as NBD disk with qemu-nbd. That device will be read-write, it will initially contain whatever the backing device (old SSD) had, but changes will be written into the qcow2 file (so the read-only status of the old SSD will not interfere with writes to the NBD).
  3. Now, it is possible to shrink the PV on the NBD device. Since it shouldn't involve much data movement, the scratch qcow2 file will not grow much. Reduce it so it matches (or slightly less) than the partition on the second SSD. You have to use something like pvresize --setphysicalvolumesize 111G /dev/nbd0 (if you attached it as nbd0 on previous step).
  4. After it is reduced, you can use dd from the NBD device. Better disuse the target partition and remove any leftover labels from it (use wipefs) prior to cloning to it.

The same setup (read-only backing device and read-write overlay) could be achieved with device-mapper built-in overlay capability and sparse overlay image instead of using Qemu's image tools and NBD, as explained on the RAID wiki, but I never did it that way.


Edit: Since this appeared in the comments I think I need to add it here too. If you have a spare backup space (external HDD or something), big enough to store an image of the original device, do it, take a dump. ddrescue tool is very useful for this task, as it:

  • works around unreadable blocks, filling them with zeros
  • maintains a state ("log") file where it remembers which blocks were successfully copied, which were found unreadable and which weren't tried yet
  • you can safely restart it using the same source, destination and state file. Also it is possible to reset unreadable blocks to non-tried state, so it will retry them during the run.

This makes it possible to fully copy devices which overheat or otherwise fall offline after doing some work and overall unstable. Just be patient, after several runs it will pull all the data possible to recover.

After that, use this image instead of the original dying device. You can use it the way I explained above, e.g. setup another overlay image which will store the differences. You'll have infinite attempts, by not changing the original image and recreating overlay images again and again as needed.

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

资料来源与适用范围

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

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

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