1

I have a sd card, wich works fine, and ubuntu 23.04, and dd does not fully mirror a disk image. example:

expected:

$ dd if=/dev/zero of=/dev/sdb
$ strings /dev/sdb
$

actual:

$ dd if=/dev/zero of=/dev/sdb
$ strings /dev/sdb
#random text, a lot

how can i make sure that my data ( not /dev/zero ) will be written correctly?

4
  • 3
    If you cannot overwrite the drive, it is likely broken. This happens relatively frequently on simple flash-based media. // Also, on the wording: "mirrorring" is a bad choice here. You are trying to wipe the drive.
    – Daniel B
    Commented Jun 29, 2023 at 16:59
  • 2
    "I have a usb flash drive, a sd card adapter, ..." -- Which is it, a "flash drive" or an "sd card adapter"? They are not equivalent. In normal usage those are two different types of USB devices. An SD card is typically a lower-quality NAND flash device than SSD or USB flash drive or eMMC.
    – sawdust
    Commented Jun 29, 2023 at 19:01
  • 2
    I’m voting to close this question because it isn't a question. IMO poster makes and observation and shares this. He/she now should compile an answerable question. Commented Jun 29, 2023 at 20:02
  • the drive works. also i am asking how i can make it so it does work
    – jp_
    Commented Jun 30, 2023 at 13:45

2 Answers 2

1

Try this:

dd if=source of=/dev/sdb bs=1M status=progress conv=fsync

What conv=fsync does:

Synchronize output data and metadata just before finishing, even if there were write errors.

(Source)

If copying block level devices, verify they are the same using cmp.

cmp /dev/sda /dev/sdb

cmp - compare two files byte by byte

1
  • 1
    note: replace bs=1m with bs=1M, it will throw error otherwise.
    – jp_
    Commented Jul 3, 2023 at 14:14
2

Apparently it does not work 'fine' or else you'd be able to write to all sectors. Since the destination drive appears to drop write commands without error, it can not be trusted and should be replaced.

Unfortunately this is a common issue with cheap SD Cards and USB flash drives. Not only the NAND used in these devices is very low quality, but so is the quality of the firmware as you'd expect the firmware to throw an error when it's unable to write to any specific LBA address.

In your case, since there was no error, the destination drive accepted the write, was unable to write and let it pass silently. It either simply did not detect the issue (which is bad), or detected and didn't notify (which is bad too).

5
  • i can mount it read-write and fill it up, without any data loss.
    – jp_
    Commented Jul 2, 2023 at 12:30
  • 1
    If you fill it up, you'd have the same issue since the drive appears to drop errors. your assumption it works fine is wrong which you have demonstrated yourself. Commented Jul 2, 2023 at 12:38
  • the other answer works, so it is indeed fine
    – jp_
    Commented Jul 3, 2023 at 14:16
  • Then I stand corrected. Commented Jul 3, 2023 at 15:00
  • 1
    @jp_ There is something fishy. If the drive was really fine, your dd if=/dev/zero of=/dev/sdb would work as expected in the first place. Commented Jul 13, 2023 at 4:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .