Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 exactly same formatted, same size and same brand SD-cards. I would like to dd image to /dev/disk2 and to /dev/disk3 at the same time.
Pseudocode

sudo dd bs=1m if=/Users/masi/2016-05-10-raspbian-jessie.img of={/dev/disk2,/dev/disk3}

How can you dd from one input to many output SDs?

share|improve this question
    
What's the goal here? Performance? If yes remember the data you read will be cached. So the 2nd dd will you data from your bcache instead of reading (of course you need some free RAM). – KWubbufetowicz yesterday
2  
My simplistic test with GNU coreutils dd ... of=one of=two did not produce two outputs. May need two dd commands. I don't see wording in posix for dd to allow for multiple of's. – Jeff Schaller yesterday
    
@KWubbufetowicz I have 8GB RAM. Possible to get 32GB. Speed is my goal because I have 5 SDs. – Masi yesterday
up vote 14 down vote accepted

1) Borrowing from don_crissti's answer using tee, without dd or bashisms:

sudo tee /dev/disk2 /dev/disk3 > /dev/disk4 < masi.img

2) Using pee from Debian's moreutils package:

sudo dd if=masi.img | \
  pee "dd of=/dev/disk2" "dd of=/dev/disk3"  "dd of=/dev/disk4"

With either method the number of output disks can be extended indefinitely.

share|improve this answer
1  
Using dd for this isn't necessary. A lot of people believe it's necessary because its usage, specific to copying to or from disk images, is "fossilized" in tutorials written back in the 90s and copied by people who didn't know why. It was used back then to work around a glitch in cp. – Random832 yesterday
    
@Random832 It is necessary because it is more stable than cp. Try many formats and different allocation sizes. I have not found enough stable cp for the work. Please, correct me as an answer here if you can argumentate how cp is enough stable. – Masi yesterday
    
@Masi It is rarely necessary to explicitly select a format (what do you even mean by "format") and allocation size (you mean the block size?) for the common purpose of writing a disk image to a disk or reading a disk into a disk image. The reason dd became commonly used for this purpose was because of a bug in cp (GNU cp on Linux specifically) in the early 90s that caused it to skip copying blocks that were all-zero-bytes. – Random832 yesterday
5  
Bug in cp in the 90s? dd is 20 years older than that. The main reason for using dd was that many devices, especially tape drives, needed to be read/written in fixed block sizes, which is why dd has bs, ibs and obs parameters, and it was the only program that could ensure correct block sizes. – Guntram Blohm yesterday
    
@GuntramBlohm I support your argument. I think dd is still the only program that can ensure correct block size and provide arguments which you pointed out. All my cp attempts have failed eventually. dd is solid. – Masi yesterday

You could try dcfldd
It's an enhanced version of gnu dd and it can output to multiple files or disks at the same time:

dcfldd if=masi.img of=/dev/disk2 of=/dev/disk3 of=/dev/disk4
share|improve this answer
    
Can you explain your first command. Why pipe only before the last dd? How does the location of the pipe change with four dd? – Masi yesterday
    
dcfldd is the fastest, maybe that should be the first choice. – agc yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.