So we are all familiar at some point with the advice to use the command

dd if=image.iso of=/dev/sdx

or similar. People almost religiously think of dd as the tool to do this. It certainly can do the job, but not only is it really bad at it (mostly because it doesn't let the kernel automatically select a good block size), but it is also infamous for having a very fragile command syntax that is easy to typo and destroy your data with. dd wasn't actually written as a disk copying tool and is meant to be used as a data conversion tool. People using it to copy images to disks without doing any sort of conversion are kind of just abusing the fact that it reads one file in and writes another out. A lot of people don't know this, but on Linux/UNIX systems you can interact with block devices like they are normal files. As a result it's generally faster and safer to do something like

cp image.iso /dev/sdx

instead. People frequently uselessly risk using dd in places where ordinary file commands like cat and cp work fine. Some of you nerds probably already knew this but I want to spread it because people recommending dd is way too common.

Also, regardless of what commands you are using, when you finish doing anything involving writing to block devices always remember to run the command sync to make sure the kernel has actually written the data to the disk and isn't waiting to later.

  • skeletorsass [she/her]
    hexagon
    ·
    edit-2
    4 years ago

    dd has a very unusual syntax that doesn't comply with other UNIX commands (because of the if= of=). If you screw this syntax up, dd will not care and will do exactly as you typed the command. This last part is also true of cp to some extent (though cp has a lot more safeguards), but cp only takes the input and output file paths in, uses a very ordinary syntax, works properly with shell tab completion. If you're careful it shouldn't matter, but cp is just simpler, more familiar, and better integrated with most shells.

    Regardless of that though, dd is very bad at this task for the other specified reasons, and there isn't any real reason to use it over them unless you need something specific to dd like conversion, or for whatever reason need a specific uniform block size (very uncommon on modern disk interfaces).