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.
Get a Little Software
- Software for Windows 10 or 11
You'll need a copy of the freeware ImageUSB software. 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 , you will need , possibly the , and a copy of 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.
- Software for the Raspberry Pi
Download the image (either "wth desktop" or "with desktop and recommended software") and flash it onto your 64 GB working card. Then install ZeroFree and PiShrink. Pro tip: On your 64 GB working card, open the Chromium browser and navigate to this page. Then you can use copy/paste to copy the commands from here and paste them into the terminal window.
To install ZeroFree, type the following commands (in bold) into a terminal window: sudo apt-get update then sudo apt-get install zerofree
To install PiShrink, type the following into a terminal window: wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh chmod +x pishrink.sh sudo mv pishrink.sh /usr/local/bin
You only need to install ZeroFree and PiShrink once unless you re-flash your working
card.
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 16 GB card. You probably want to start with the "Raspberry Pi OS with desktop and recommended software," then add and remove software until you have the perfect card.
Set Up Auto-Resize on Your "Master" Card
Do this only after you have completely customized your "master" card. You have to do this to get back full use of your 16 GB cards. You'll do this on your Raspberry Pi, running the "master" card using the command line in a terminal window. You can use copy-paste with the commands below.
- 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
-
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
- 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.
[Optional] Zero-fill the Free Space
This is worth doing only if you plan to make a compressed image for balenaEtcher as described below. This step overwrites the free space on the master card with zeros to improve compression. You will do this on the Raspberry Pi, booted from a your 64 GB working card.
Boot your Pi from the working SD card. If the program zerofree is not already installed on the working SD card, install it with as described above. Insert the master SD card in a USB adapter and plug it in to a USB port; if you have a Pi 4, use a USB 3 adapter and a USB 3 port on the Pi. Be sure there is no other USB storage attached. Issue the commands: sudo umount /dev/sda* sudo zerofree /dev/sda2
When the zerofree program completes, your card image will be maximally compressible.
Make and Shrink an Image of Your "Master" Card using your Raspberry Pi
You now need to make and shrink an image of the "master" SD card on your Raspberry Pi. If you used ZeroFree, your Pi is already booted from your 64 GB working card and the "master" SD card is in a USB adapter. If not, set things up that way.
With the master card in an adapter and plugged into a USB port, make and shrink an
image of it like this:
sudo umount /dev/sd* sudo dd bs=4096 if=/dev/sda of=your_master.img sudo sync sudo pishrink.sh -s your_master.img sudo sync
Replace "your_master" with whatever name you want for your image files. Pro tip: include the date in the file name, e.g. 20210515 to help you keep track of things.
The dd operation will take many minutes, the PiShrink part much less. When the process is done, you will have an image file perhaps 8-9 GB or more on your working SD card.
You now need to get it onto a PC. Because of file system incompatibilities, the most
straightforward way to do that is to use VNC's file transfer, which is somewhat slow.
If you are handy with the command line, you might use dd to copy the image onto a different 16 GB card in USB adapter, then use HDDRawCopy
to read it onto the PC.
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" to select all the USB adapters in Step 1. Select "Write image to USB Drive" in Step 2. Select your image file ifrom 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.
Making an Image for balenaEtcher
This part is optional; do it only if you need an image that will work with balenaEtcher.
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 or others.
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. The compressed file can be used directly as input to balenaEtcher.
When the compression task finishes, you can delete the .img file; you can recreate
the image file from your master microSD card.
More Raspberry Pi Resources
|