-Kipling
If you boot your Beaglebone Black off an SD card (rather than using the EMMC memory) you will probably wish to make a bootable backup copy. This page describes how to create a copy of a Beaglebone Black SD card.
The primary method used is the dd command on a Linux PC. A discussion of the cloning method using a Windows PC is also provided with caveats because the tools for this method proved to be somewhat unreliable.
This page is one of a series of (hopefully) helpful Beaglebone Black notes - more of which can be found on the BeagleNotes page.
Inserting the source SD card in the slot on the Ubuntu PC will automatically mount it and cause it to appear as a device in /dev directory. The exact device name depends on the configuration, so our first action is to find out the device name of the SD card.
Copying the Source SD Card
First we query a single column list of the files in the /dev directory and save it in a text file
ls -1 > dev1.txt
Next we insert the card. Then we create the list again to another file.
ls -1 > dev2.txt
Now we use the diff command to see what new devices have appeared
diff dev1.txt dev2.txt 78a79,81 > sdb > sdb1 > sdb2 80a84 > sg2
In this example, the SD card appears as /dev/sdb. There are also two partitions on the SD card and they are listed as /dev/sdb1 and /dev/sdb2.
Unmount the two partitions so that they don't get in the way of the cloning process. This probably isn't all that necessary but it doesn't hurt either.
umount /dev/sdb1 umount /dev/sdb2
Create a byte-for-byte copy of the SD card contents using the dd command. The sudo command is necessary since we need root permissions for this.
sudo dd if=/dev/sdb | gzip > bbb_sd_image.gz
On my system, the above command took about 10 minutes (for an 8Gb card) to complete and produced a 950Mb compressed output file.
ls -l bbb_sd_image.gz -rw-r--r-- 1 root root 955495227 Jan 21 13:40 bbb_sd_image.gzWe now have a compressed copy of the entire SD card contents which we can use to create a bootable copy.
Creating the Target Copy SD Card
Remove the source SD card from the slot on the Ubuntu PC. Place a new SD card of the same size (unformatted or unformatted) in the drive. Once again we have to make sure which device the new SD card appears under in the /dev directory. Take care to get this right – because if you do not you will be copying the source data to some other device and this could (probably will) have potentially disasterous consequences.
Insert the new target SD card (it MUST be the same size or larger) and output a list of the devices – this time to the dev3.txt file.
ls -1 /dev > dev3.txt
Since we still have a copy of the original dev1.txt file from when we created the copy of the source SD card we can just use that to see the changes.
diff dev1.txt dev3.txt 78a79 > sdb 80a82 < sg2This new card is listed as /dev/sdb as well. Note there are no /dev/sdb1 or /dev/sdb2 devices listed since the card in this example is a new blank card and there are no partitions on this drive yet.
Now we can copy the source SD image onto the new drive. We use the dd command for this as well. Also, in particular, note the dual use of the sudo command to make it all happen as root. The first part uncompresses the image and then pipes it to the second part for output
sudo gzip -dc bbb_sd_image.gz | sudo dd of=/dev/sdbThe write to the SD card takes quite a bit longer than the read from the SD card and write to the disk. On my system it took about 30 minutes
Copying the Source SD Card
Insert the SD card you wish to use as a source. The act of inserting the SD card will probably open up a Windows Explorer window or otherwise prompt you to take some action. Note down the drive letter of the new SD card. On my system it was drive F.
Start the Win32DiskImager software and choose the drive letter of your SD card from the drop down box on the right. Type the name of the file into which you wish to store the image in the area on the left hand side.
Note if you start the Win32DiskImager software and then insert the SD card, the Win32DiskImager software is not clever enough to notice that the disk has been newly inserted and you will not see the drive letter present. You have to insert the SD card before starting the imaging software so that the SD card is already present when the Win32DiskImager software scans the system for drives.
Its is not especially clear what you need to do in order to save the contents of the SD card to the PC disk. The hints at the bottom provide some insight - press the Read button to copy the contents of the SD card to your image file.
In the above screenshot the Read button has been pressed and the contents of the SD card in Drive F are being copied to the D:/Dump/bbb_SDCardImage1.img file. The read of the data took about 10 minutes on my system for an 8Gb card.
Creating the Target Copy SD Card
Remove the source SD card from the slot on the Windows PC. Place a new SD card of the same size (unformatted or unformatted) in the drive. Set up the Win32DiskImager as before (it's probably best to close and re-start it) and press the Write button.
Once the write process has completed, the SD card can be removed and the newly cloned card should be identical to the one used as a source.
NOTE: There were a couple of occasions where an error "Not enough space on disk" was immediately returned by the Win32DiskImager software when attempting to write the disk image. There appears to be considerable discussion of this error message on the Internet and the problem seems to be due to minor differences in the capacity of SD cards by different manufacturers. It does not appear that there is any mechanism (as of Win32DiskImager v0.9.5) to force it to continue as best it can or to trim the image file size created in the original read. The only recourse is to use SD cards from the same manufacturer. Alternately, you can write to a larger SD card (for example, write an 8Gb image to a 16Gb card) and this always seems to work successfully. This issue may well be fixed in subsequent Win32DiskImager versions.
The contents of this web page are provided "as is" without any warranty of any kind and without any claim to accuracy. Please be aware that the information provided may be out-of-date, incomplete, erroneous or simply unsuitable for your purposes. Any use you make of the information is entirely at your discretion and any consequences of that use are entirely your responsibility. All source code is provided under the terms of the MIT License.
Various internet resources were used to help understand the SD card cloning procedure. Especially useful were the LifeHacker Raspberry Pi SD card clone page for the Win32DiskImager advice and Shawn Hymel's How to Backup a SD Card Image page for the workings of the dd command on Linux.