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.

gatorback
  • 1,384
  • 23
  • 48

3 Answers3

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
muru
  • 72,889
  • 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 Jun 05 '19 at 04:08
  • The concern that when the very large image is displayed on the console the process would unnecessarily slow – gatorback Jun 05 '19 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

muru
  • 72,889
fossil
  • 307