The SD card is a key part of the Raspberry Pi. As this cards have a limited erase/write cycles, it is very important to choose and use them carefully, in order to expand their life time. In this post we will see some methods to increase the lifespan of a Raspberry Pi SD Card by minimising the number of read/writes. In fact the performances of the Raspberry Pi will be strongly influenced by the quality of the SD card chosen. The SD cards we recommend. In general, the choice of a good SD card can totally change your experience of the Raspberry Pi. Indeed, the SD card is always called by the system. Therefore, if the card is slow the system is also slow.
I've written separate instructions for duplicating SD cards with a Windows computer.
A $150 microSD Card Duplicator
You can buy SD card duplicating machines at prices from several hundred dollars to several thousand. Or, you can duplicate ten or more cards at a time using $150 worth of parts and your Raspberry Pi running Raspbian. (It was $99 in the fall of 2018, but I now recommend USB 3 equipment, which is pricier.) Here's what you need:
Even after you add a few bucks for shipping you can probably get the parts you need to turn your Raspberry Pi into an SD card duplicator for less than $150.
This process has been tested using a Raspberry Pi Model 3 B+ and Raspbian Stretch 9.4. However, it will run much faster if you have a Raspberry Pi 4 and use a USB 3 port. Please report problems or errors with these instructions to [email protected].
Overview: Duplicating SD Cards
Thanks very much to Richard Hayler, who revealed the secret of multiple output devices with the dcfldd program.
Note: if you have a laptop or desktop computer running a Debian-like operating system, you can use that and it will possibly be faster than using a Raspberry Pi. You will have to substitute appropriate device names. In particular, /dev/sda is probably your system disk. I have been politic and you have been warned.
Here's what you're going to do:
It's time to say a word about shrinking the image. There are two reasons for doing that. The first is that it will make a smaller image, and so things will run faster. If you work with 16 GB cards, you can probably shrink the image from 16 GB down to around 6 or 7 GB, so operations will run more than twice as fast!
The more serious problem is that '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. By shrinking the image, you make sure your image will fit when you flash it onto cards that are nominally 16 GB. The auto resize function will give you back the full capacity of the SD card upon the first boot.
The image shrinking process given is for Raspbian only, not NOOBS.
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. Install a Little Software
You only have to do this once. Install Raspbian on your big microSD card and boot from it.
There are two bits of software you need that aren't a part of the standard Raspbian installation. Both software packages go on your large SD card. One is dcfldd, an extension of the dd command that performs the magic of writing multiple devices at ones. The other is PiShrink, which packages the fiddly operations of shrinking the image file and setting up the auto resize operation. Install dcfldd by typing:
sudo apt-get install dcfldd in a terminal window.
Also in a terminal window, install PiShrink by Drewsif by typing these commands:
wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh chmod +x pishrink.sh sudo mv pishrink.sh /usr/local/bin 1. Make the Perfect SD 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. Remember: Raspbian only, not NOOBS.
2. Make an Image of Your 'Master' Card
Boot from the big microSD card. Make sure you have at least as much free space on the big card as the full size of your 'master' SD card. (Erase old image files as needed.) In a terminal window, type the following:
sudo umount /dev/sd* sudo dd bs=4096 if=/dev/sda of=myimage.img sudo sync
Replace 'myimage.img' with whatever you want to name your image file. I like to use something with a date, e.g. workshop_20180906.img. For a 16 GB card, this will take about 18 minutes on a Model 3 B+.
3. Shrink the Image and Set Up Auto-Resize
Use PiShrink to shrink the image and set up auto resize typing in a terminal window:
sudo pishrink.sh myimage.img
Replace 'myimage.img' with whatever you called your image file. This will take only a couple of minutes. PiShrink has options for making a copy of the image file and suppressing the auto-resize function; you don't need them.
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 Raspberry Pi.
To make four copies, type:
sudo dcfldd bs=64k if=myimage.img of=/dev/sda of=/dev/sdb of=/dev/sdc of=/dev/sdd
Change if= to the name of the image you want to flash. To make more than four co pies, add more of=/dev/sdX operands, where X is the next sequential letter.
This takes about eight minutes for one card. It may take as much as 24 minutes for 10 cards and USB 2. Relax and watch the blinking lights.
Copyright © 2018 by Kennesaw State University
Last update: 2020-04-09 08:08
Originally published: 2018-09-25
Have you ever had your Raspberry Pi stopped booting up? The red and the yellow lights flash a few times and then quit? These are classic symptoms of a corrupted SD Card.
This posting will walk through how to fix a corrupted SD Card for your Raspberry Pi using a Mac and VirtualBox. This is a fairly complicated procedure, but most of it only has to be done once and then you can fix corrupted cards quickly and efficiently.
Why do SD Cards get Corrupted?
When the SD Card is being written, there are windows of vulnerability. There seem to be four main scenarios during which SD Cards become corrupted:
OK, what can I do with a Corrupted SD Card?
The first thing you can do is BEFORE you get corrupted, back up your SD Card on a regular basis. If you spend hours configuring an SD Card, then back it up. Changing your software? Back it up. It will save you a lot of time if you end up corrupting or destroying the SD Card. Here is how to do it on a Mac.
Sometimes, the SD Card is actually damaged. In that case, you aren’t going to be able to fix the card. However, you can get your files off the SD Card in many cases. Check out this posting.
Fixing a Corrupted SD Card
Overall, this is the procedure for fixing a corrupted SD Card using a Mac. The process is similar for a PC, but requires different instructions to install and get VirtualBox working.
Install VirtualBox on your Mac
VirtualBox is a “virtualizer” which means that it allows you to install an operating system in a “Box” inside another operating system. Connect smartphone to computer usb. It is open source and free to use. In this case we will be installing Linux (Ubuntu) on a Mac OS X platform.
Step 1: Download the VirtualBox .dmg file for the Mac OS X from this page:
![]()
Step 2: Click on the downloaded .dmg file.
Step 3: Double click on the VirtualBox.pkg icon
Step 4: Follow the instructions to install VirtualBox in the applications directory.
Step 5: Now download the installation file (.iso) for Ubuntu from this link: Note: Make sure you use this link – ubuntu-1510-desktop-i386.iso. If this link isn’t available, go to https://mirror.pnl.gov/releases/ and find the latest release. The default download link on Ubuntu server will download an amd64 image, which WILL NOT WORK on your Mac OS X.
Step 6: Start up VirtualBox from Applications
Step 7: Click on “New”
Step 8: Enter “Ubuntu” as the name. Linux and 64 bit will be automatically selected. Click Continue.
Sd Card Writer For Raspberry Pi Audio
Step 9: Click on continue until you are done, using all the defaults.
Step 10: Click on settings and then on Storage and then on Controller: SATA
Step 11: Enter 2 in port count! This is an important step not to miss! Click “OK” to close
Step 12: Ready to install Ubuntu now! Click the Start Button
Step 13: When you are promoted to select an image, select the ubuntu .iso image downloaded in Step 5.
Step 14: Select “Install Ubuntu” from the screen, then “Continue” from the next screen and then keeping the defaults, finally “Install Now”.
Step 15: Click “Continue” when asked to erase the virtual disk. Don’t worry, this is not your Mac OS X disk.
Step 16: Select your Timezone. Hit “Continue”
Step 17: Put in your name and choose a password. Make sure you can remember it! Now hit “Continue” and you are installing Ubuntu.
Step 18: Now click “Restart Now” when the installation is finished. If Ubuntu does not start (which happens often the first time), then hit the “x” in the corner and select “Power Off the Machine”.
Step 19: Now you have your Ubuntu Virtual Machine running. Click the “X’ on the window and select “Send the shutdown signal”. Then click “Shutdown”
Adding the SD Card to your Ubuntu Virtual Machine
In order to mount and fix your corrupted SD Card, you need to add it to the Ubuntu virtual machine. This is the complicated part of this procedure.
Step 1: Insert your SD Card into the reader on your Mac OS X machine. Below is on the Mac Mini. On a Mac Book, it will be on the side.
Step 2: Open up a terminal window and type:
Step 3: You will see a list similar to this. Look for your SD card and note the /dev path (/dev/disk4 in this case)
Step 4: In the terminal window type (replacing /dev/diskX with what you found in Step 3):
Step 5: change directory in the terminal window to the “VirtualBox VMs” on our development machine this command is:
Note the quotes around the directory name. Adding spaces in directory names and filenames causes all sorts of issues. The user on our machine is “development”. The user name on your machine will be different.
Step 6: Now we come to the magic. Type the following (replacing diskX with what you found in Step 3):
Step 7: Now we have an .vmdk file pointing to your raw SD Card device. We next have to set the permissions on this file so your Ubuntu VirtualBox machine can read the file.
Step 8: Next we have to add the SD Card (a SATA device) in the Ubuntu virtual machine storage configuration built in the previous section.
Step 9: Click on Settings in VirtualBox and select Storage. If port count is “1” change it to “2”
Step 10: Click on the icon on the right of the Controller: SATA disk and select “Choose existing disk”. Select the .vmdk file built in Step 6 above. If it reports that it is busy (Mac OS X likes to remount things for some reason), repeat Step 4 and quickly do Step 10 again.
Raspberry Pi Image Burner
Step 11: Click OK
Step 12: Start your Ubuntu Virtual machine with the start button.
Iso to sd card. Now finally, we can repair the SD Card.
Repairing the SD Card
Step 1: Select the top most icon on the Ubuntu Desktop. Type “Terminal” in the search line.
Step 2: Select the Terminal Icon on the top line. You will get a terminal window.
Sd Card Writer For Raspberry Pi Emulator
Step 3: type
into the terminal window (you may have to enter your password from Step 17 in the section above)
Step 4: Note the name “/dev/sdb”. That is your SD Card on the Ubuntu system. Note it may be different, but if you followed these directions, it should be the same.
Step 5: Now the magic. Finally. We will fix the sdb2 partition on sdb. That is the linux system. Type the following in the terminal window:
Sd Card Writer For Raspberry Pi Using
This may take a while, depending on the speed of your machine. Note that the following picture shows you what you get on a clean, good SD Card. If you have issues, it will show you what it is doing.
ConclusionSd Card Writer For Raspberry Pi Keyboard
Now you should have a repaired Raspberry Pi SD Card. If it doesn’t work, you may have bigger issues. Start by looking at more “fsck repair” pages on the web. If the card is bad, look at mounting the SD Card under your Ubuntu Virtual machine and going into the file system to try to recover your most important files.
Sd Card Writer For Raspberry Pi
The next time you need to repair an SD Card, you should only have to plug it into your Mac OS X and then start Ubuntu from VirtualBox. Note that the image you built for the SD Card repair probably won’t boot without an SD Card plugged in. If you want to use Ubuntu without the SD Card, build another image in VirtualBox. You don’t have to delete the SD Card Ubuntu image.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |