[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it safe to replace dd?

From: L A Walsh
Subject: Re: Is it safe to replace dd?
Date: Wed, 22 Jan 2020 21:56:36 -0800
User-agent: Thunderbird

On 2020/01/20 04:14, microsoft gaofei wrote:
Many people suggest using dd to create bootable USB, . But cp and mv also writes to USB, e.g., cp 
archlinux-2020.01.01-x86_64.iso /dev/sdb, cat archlinux-2020.01.01-x86_64.iso > 
/dev/sdb. Is it safe to use these commands instead of dd? If it's unsafe, I want 
to know the reason.
No it is not safe. (TLDR at end)
The behavior of 'cp' and 'cat' with regard to how they perform I/O to or from
a device is not documented to be done in ANY consistent way.

You can describe their behavior in the coreutils suite in a specific version
on a particular machine with specific hardware.  But it doesn't mean they
will behave the same if you change any of those inputs.  There are many
implementations on different types of hardware.
On some types of block devices, in the past, linux would generate a
fatal signal if a program didn't perform I/O aligned with the device's
I/O size.  The I/O sizes used in cat and cp are not specified or guaranteed.
The alignment used by 'dd' is specified and guaranteed.  It's actions can
be directed to do various actions in odd cases, that you couldn't specify in
cat or cp.
That said, I have used a program like 'cat' to do a disk copy (successfully)
more than once in the past (not recently).  It's not that using alternate
programs *won't* work, its that their behavior is undefined and unsupported, so if they work in a specific situation, great! But for general purpose block copying, their implementation is guaranteed to behave a specific way -- and many types
of hardware hide misalignments now at the expense of performance.  Typical
example, 4K-sector disks labeled "512e", meaning they will emulate 512 bytes.

On reads, not much differeence, but on writes, if you write <4K, it takes two spins of the disk, one to read the sector, then merge the new info and a second
pass to write the new sector.  So it DOES work, BUT, it drops the IO speed

So, use cat if you want for some things, __if__ you know the alternate utils work
in advance.  If not, using 'dd' is more reliable.  I don't think you'll be
able to find anyone to guarantee otherwise.

So the short answer is no, it isn't "safe", even though it may work in
some situations.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]