|
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. 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, possibly the HDD Raw Copy Tool, and 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.
- Software for the Raspberry Pi
Download the Raspberry Pi OS 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:
sudp apt update sudo apt install -y wget wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh chmod +x pishrink.sh sudo mv pishrink.sh /usr/local/bin
If you want to use an exFAT-formatted flash drive to transfer the shrunken image to
a PC, you will need more software:
sudo apt-update sudo apt install exfat-fuse sudo apt install exfatprogs sudo apt update sudo apt install -y parted gzip pigz xz-utils udev e2fsprogs
You only need to install once once unless you re-flash your working card. However, beware that PiShrink must be running on the same version of the Raspberry Pi OS as you are generating. So, you will likely need to reflash you working card every time!
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.
[Optional] Zero-fill the Free Space
This is worth doing only if you plan to make a compressed image for balenaEtcher or Raspberry Pi Imager 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 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. You could also copy the image onto an exFAT-formatted flash drive. To do that, you will need to have installed the exFAT programs described above. You can format a flash drive as exFAT on Windows my selecting the drive in This PC, right clicking, choosing Format, and selecting exFAT as the format type.
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 or 11 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
|