Duplicate Micro SD Cards with Your Windows 10 PC

Note: This article is about flashing SD or microSD cards several cards at a time in preparation for a class or workshop.  If what you want to do is flash an image onto one or two cards, balenaEtcher is the right tool for the job.  It's available for Windows, MacOS, and Linux, and will read compressed images directly.  If you need a bunch of copies, read on!

A $150 microSD Card Duplicator

Half a year ago I wrote an article about duplicating microSD cards with your Raspberry Pi.  It had a lot of command-line stuff in it, and one person complained that there was no verification step.  (I think modern flash storage is sufficiently robust that the verification step is redundant, but it does make some people feel better.)    I've spent some more time on the problem of duplicating microSD cards with the goal of doing most of the work on a Windows 10 PC and getting the benefit of USB-3. Using the equipment in the links below, I can make 10 duplicate microSD cards from an 8 GB master image in less than 17 minutes.  I can do enough for an entire class in an hour, including setup time.

So, to use your PC for microSD card duplication, here's what you need:

  • A powered USB-3 hub with enough ports for the number of cards Difference between parallel and in-line port arrangementyou want to duplicate at once. Your PC can power a couple of micro SD cards using its own power supply. To duplicate many at one time, you'll need a hub with a source of power.  $40.  (Most USB 3 hubs will do.  However, the microSD cards stick out from the side of the adapters recommended below, so you want a hub with the USB sockets parallel to each other, like the top image in the picture at the right, not "in a line," like the lower image.)
  • microSD card reader/writer USB adapters.  You need one of these for each port on your hub.  For a 10-port hub, you need ten.  About $80 for ten.  Not all "SD card readers" will write reliably, and not all will operate at USB-3 speeds.  The ones in the link are Transcend TS-RDF5 adapters, and they are the best I've found so far.
  • An 8 GB microSD card on which to build the image; you will want to flash 16 GB cards, as explained below.  About $4.

Even after you add a few bucks for shipping you can probably get the parts you need to turn your Windows PC into an SD card duplicator for about $150, and the software is all freeware. 

This process has been tested using a using a Lenovo ThinkPad with solid-state disk and Windows 10.  Please report problems or errors in these instructions to Bob.Brown@Kennesaw.edu.

Overview: Duplicating SD Cards

Here's what you're going to do:

  1. Make an SD card that's perfect for your class or other purpose.  This will become your master image.
  2. Set the perfect SD card to auto-resize on first boot.  You'll do this on your Raspberry Pi.
  3. Make an image of your perfect card on your PC.
  4. Flash your image onto other SD cards using ImageUSB, up to ten or more at a time!

Many procedures for duplicating microSD card images include shrinking the image.  You have to have an image that's no larger than your target cards, and "16 GB" cards from different manufacturers may be of slightly different sizes. If you make your image using a card that's a little bit bigger than average, then try to flash it onto one that's a little bit smaller, the operation will fail.  

Instead of shrinking the image, make that "perfect" SD card using an 8 GB card, then flash into 16 GB cards.  Problem solved, and the auto resize function will give you back the full capacity of the SD card upon the first boot.

The Gory Details

In the material that follows, code, i.e. things you will type as commands or put into files is shown in bold.  These directions assume a small amount of familiarity with working in the Raspbian terminal environment.

0. Get a Little PC Software

You'll need a copy of the freeware ImageUSB software.  ImageUSB does not need to be "installed," just plop it in a folder where you'll be able to find it and double-click to run.

Optional: If you also want to make a compressed image you can use with balenaEtcher, you will need 7Zip, the HDD Raw Copy Tool, and maybe a copy of balenaEtcher itself.  Use the portable version of the HDD Raw Copy Tool and plop it into the same folder as ImageUSB.  This is all free software.

1. Make the Perfect SD Card

This will be your "master" microSD card.  "Perfect" is a matter of application, and maybe even a matter of taste.  For example, if you're going to use Scratch 2 in your classes, you can decide whether to include Scratch (1) or leave it out.   Do this on an 8 GB card.  At the moment (summer, 2019) Raspbian "Buster" with desktop and recommended software will fit into 8 GB.  When it no longer fits, you'll have to make an image file under Raspbian and shrink it or be very careful to use 16 GB cards from the same manufacturer.

2. Set Up Auto-Resize on Your "Master" Card

Do this only after you have completely customized your "master" card.  You have to do this or you'll only be able to use 8 GB of your 16 GB cards.  You'll do this on your Raspberry Pi using the command line in a terminal window.  You can use copy-paste with the commands below.

  1. First edit /boot/cmdline.txt and append "init=/usr/lib/raspi-config/init_resize.sh" to the first (and only) line.  Here's a command to do that; you can use copy-paste to paste it right into the Terminal command line:
    sudo sed -i '1{s@$@ init=/usr/lib/raspi-config/init_resize.sh@}' /boot/cmdline.txt

  2. Create the "/etc/init.d/resize2fs_once" file.  There are three commands in bold below; the first one is a single, long line.  Copy-paste them into Terminal one at a time.
    sudo wget -O /etc/init.d/resize2fs_once https://raw.githubusercontent.com/RPi-Distro/pi-gen/master/stage2/01-sys-tweaks/files/resize2fs_once

    sudo chmod +x /etc/init.d/resize2fs_once

    sudo systemctl enable resize2fs_once

  3. Shut down your Pi and remove the microSD card.

Be careful not to boot the "master" card after you've set up auto-resize, or you'll have to do it again.

3. Make an Image of Your "Master" Card

Remove the "master" card from your Raspberry Pi, put it into a USB adapter, and plug it into your PC.  Start ImageUSB by double-clicking it.  In Step 1, select the USB drive that holds your master card.  In Step 2, about a third of the way down the screen, select "Create image from USB drive."  In Step 3, click "browse," select a folder, and type a file name  to hold your image file.  Use a .bin file extension to avoid confusion with the raw image you may make later.  Step 4, click "Write."  For an 8 GB microSD card this will take less than ten minutes.  Beware:  It will also create a 7.4 GB file on your PC, so be sure you have room.

4. Make as Many Copies as You need!

Put the SD cards to receive the copies into USB adapters and plug the adapters into your powered USB hub.  Plug the USB hub into your Windows 10 PC.  Be sure you don't have any USB devices you don't want to flash.

Start ImageUSB.  Click "Select all" in Step 1.  Select "Write image to USB Drive" in Step 2.  Select your image file in Step 3, and click "Write."

This takes about twelve minutes for one card.  It may take as much as 20 minutes for 10 cards.  Relax and watch the blinking lights.

When you're done, you don't need to keep that 7.4 GB image on your PC; you've got it on your "master" microSD card, and it only takes a few minutes to copy it back if you need it again.

Making an Image for balenaEtcher

This part is optional; do it only if you need an image that will work with balenaEtcher.

The image you made with ImageUSB has a 512-byte header that prevents using it with any program other than ImageUSB.  You'll need to make a "raw" image for use with balenaEtcher.  You will start with that same "master" microSD card, but you'll end up with a much smaller compressed image.  You might want to do this yourself in case you need extra copies later on, or even to make the image file available to students.

With the "master" microSD card in a USB adapter and attached to your computer, start the HDD Raw Copy tool.  If you got the portable version, just double-click it.  In the first screen, select, by clicking, the device that is your "master" card, then click "Continue." 

In the second screen, double-click to open a file on disk, select a folder and type a file name.  In "Save as type" choose "raw image (dd image)" and use a .img file extension.  (That's why we used a .bin extension for ImageUSB.)  Click "Save" in the file panel, then "Continue."

Check that everything looks right and click "Start."  That will take five or six minutes and produce another 7.4 GB file on your hard disk.  When the process is 100% complete, close the tool with the X in the upper right.

Then navigate to the folder holding your image and right-click the file.  Choose 7Zip from the context menu, then "Add to archive."  Choose "xz" for the archive type, then "OK."  This will take 45 minutes or more, so plan to take a break.  (It will be much faster if you have an SSD.)  It will leave you with an XZ file that will be less than 2 GB.

When the compression task finishes, you can delete the .img file.  You can use the .xz file directly with balenaEtcher.

 

More Raspberry Pi resources


Copyright © 2019 by Kennesaw State University
Creative Commons BY-NC-SA License

Last update: 2019-07-24 11:55
Originally published 2019-04-21

©