Skip to content

Instantly share code, notes, and snippets.

@gbaman
Last active May 8, 2022 01:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbaman/7a8b42a14b7fe4d25cdd to your computer and use it in GitHub Desktop.
Save gbaman/7a8b42a14b7fe4d25cdd to your computer and use it in GitHub Desktop.
How to clone an SD card for use in a classroom

##Creating SD card clones for classrooms

The basic idea for creating SD cards in a classroom is you create a master SD card, make all the required changes (install software, edit configuration files etc), then read it back onto the computer and flash it onto the rest of your SD cards like a normal Raspbian SD card image.

##Shameless plug If you have a networked classroom or are able to set one up, my free and open-source Raspi-LTSP project will save you a lot of time and hastle!

###A few key tips

  1. Be careful what size of SD card you use! As you will be cloning the entire SD card (even blank areas) it is important you create the master image with your smallest SD card. For example, if you are using 8gb cards that are all exactly the same make and model, it shouldn't be much of a problem. The issue is different manufacturers when they create an 8gb sd card, it may be a few kilobytes bigger than that other brands 8gb SD card. So if you use the bigger one to create your master image on then try to flash this image onto the smaller card, it won't fit... If you want to use 8gb cards, see if you can for example find a 4gb card and use that for your master image. If not, it may require a little trial and error.
  2. Don't use NOOBS. The reason for this is simple, it takes longer, wastes space etc when if you are cloning cards, you won't actually use NOOBS. One of the key features of NOOBS is you can wipe everything and reload Raspbian back on. You won't use this feature if you are cloning SD cards as the Raspbian image on NOOBS will be the standard one, not your new edited one. So just load standard Raspbian onto the SD card, is much quicker.

##Flashing an SD card with Raspbian First grab yourself a copy of Raspbian from the Raspberry Pi foundations downloads section. Make sure to hit the Download Zip button beside Raspbian (Not the torrent). Once it downloads, unzip it.

###Windows

  1. Grab Win32 disk imager from here.
  2. Run it (as administrator).
  3. Select your Raspbian image file you downloaded earlier.
  4. Plug in your SD card. If possible make sure you have no other removable drives (pendrives, other SD cards, external hard drives) attached and select the drive letter on the right. If there is more than 1, open My Computer and find which drive letter your SD card is. WARNING It is essential you are certain that you are using the correct drive letter or you could completely wipe a pendrive etc.
  5. If you are certain, hit write and go make a cup of tea, this will take 5-10 mins.

###Mac

  1. On mac, there are a number fo ways you can do it. I quite like a graphical tool called RPi SD card builder. Grab it from here.
  2. There is no need me reinventing the wheel as the developer of the tool has created an easy to follow guide here.

##On the Raspberry Pi Once you have your SD card flashed, it is now time to set up your Raspberry Pi.
Remember in Raspi-Config to resize the partition and do stuff like enable the camera etc. You may also want to enable boot to desktop.
Then install all your other packages you want to use with your class.

##Reading back the SD card image onto the computer. Now we need to read the new updated image back onto the computer. The image size will be as large as the SD card (so an 8gb card will create an 8gb SD card image on the computer). ###Windows

  1. Using Win32 disk imager again, select a location to save your image (using the same part of the application as you use to select an image file to load onto an SD card, enter the name you want to save it as at the bottom of the file selection window. Do not save it with the name of another SD card image or you will overwrite it!
  2. When you are sure everything looks good, hit read to start copying the SD card to an image file on your computer.

###Mac

  1. Open a terminal (can be found in applications/utilities/terminal).
  2. With SD card not plugged in, enter diskutil list and hit enter. You will get a list of all filesystems connected to your Mac.
  3. Insert the SD card and again enter diskutil list. You can now compare the 2 to see what has changed. You are looking the /dev/diskX, for example /dev/disk3. Take note of the final number (in the example, that was 3).
  4. Finally, we use DD to read the image from the SD card to a file sudo dd if=/dev/rdiskX of=~/Desktop/pi.img bs=1m. Note the use of rdiskX instead of diskX. Make sure to replace the X with the number from above (e.g. 2). This will save it to an image file on the desktop called pi.img.

##Flashing the cloned image onto other SD cards Now you have created your master disk image, it is as simple as following the Flashing an SD card with Raspbian section above to flash the newly created disk image instead of Raspbian.

If you have any issues, feel free to drop me a tweet Gbaman1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment