1

I would like to write an image at two SD cards at the same time. I envision at least two concurrent writing scenarios:

  1. Is it possible to write the image with a tee or similar bifurcating mechanism?
  2. Is it possible to execute the cat or pv command from two different BASH shells?

    sudo sh -c 'pv sdcard.image >/dev/sdb'
    sudo sh -c 'pv sdcard.image >/dev/mmcblk0'
    
    sudo sh -c 'cat sdcard.image >/dev/sdb'
    sudo sh -c 'cat sdcard.image >/dev/mmcblk0'
    

I can foresee a problem in that if the two targets can be written at different rates, then it may be necessary to throttle write speed down so as to not overload the slower writer. The image is large: the ability to burn multiple targets is a significant advantage.

3
  • What do you mean with at the same time? Do you just want ONE command to write both devices with the image? Commented Jun 5, 2019 at 7:38
  • @matsib.dev Good question: Yes, the goal is to burn two SD cards concurrently instead of one. It would be preferable that a the image file is read once and burns two cards with a one-liner from the command line.
    – gatorback
    Commented Jun 5, 2019 at 12:59
  • @gatorback Ok, take a look at my updated answer. Commented Jun 5, 2019 at 23:48

3 Answers 3

4

Is it possible to write the image with a tee or similar bifurcating mechanism?

sudo tee /dev/sdb /dev/mmcblk0 < sdcard.image > /dev/null
2
  • 2
    Please add a small narrative to walk the reader through the thought process. It would be nice if the image file was not returned to the console and progress \ status was displayed. Thank you
    – gatorback
    Commented Jun 5, 2019 at 4:08
  • The concern that when the very large image is displayed on the console the process would unnecessarily slow
    – gatorback
    Commented Jun 5, 2019 at 13:01
2

Is it possible to execute the cat command from two different BASH shells?

Which cat command?


If you just want to achieve the same result as here:

sudo sh -c 'pv sdcard.image >/dev/sdb'

sudo sh -c 'pv sdcard.image >/dev/mmcblk0'

but with one Enter hit, why not simply combine the commands like this?:

sudo sh -c 'pv sdcard.image /dev/sdb && pv sdcard.image /dev/mmcblk0'

Is it because you don't want to read the file twice?

(with &&, the second commands it's executed, only if the first command succeed; if you want to execute the second command anyways, you can change the && for a ;)


To read the file from the filesystem only once, you can do this:

cat sdcard.image | tee /dev/sdb > /dev/mmcblk0

Here, your are taking advantage of tee default behavior: what tee sends to a file, you send it to one of your device targets, giving that device as a file argument of the tee command, and what tee sends to stdout, you redirect it to your other device target.


Or, reading the image twice, but doing both writes at the same time, in parallel, with parallel:

parallel 'cat sdcard.image >' ::: /dev/{sdb,mmcblk0}

Note: bare in mind that this parallel, is the GNU parallel, and not the moreutils parallel

-2

This is bare minimum shell script for concurrent copying. If any errors this will throw them to STDERR.

#!/bin/sh
echo "Image file ${1}"
echo "1st SD Card Path ${2}"
echo "2nd SD Card Path ${3}"

dd if=${1} of=${2}&
dd if=${1} of=${3}

Usage sh script.sh image_file first_card_path second_card_path

2
  • This would read the image file twice. (Also, please quote your variables!)
    – Sparhawk
    Commented Jun 5, 2019 at 6:01
  • Please give dd a decent buffer size. Writing 512 byte blocks to a 4K-block SD card is wrong. (You may find cat is faster anyway.) Commented Jun 5, 2019 at 6:38

You must log in to answer this question.

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