image

If you do any work with the Raspberry Pi or other Linux based system that uses SD Cards as the primary storage device, you’ll run across a issue that can be time consuming and troublesome. When you purchase SD Cards, they are advertised as X number of GB’s. However, two cards that have the exact same number of GB’s (for instance 8 GB) advertised might not have the exact number of available space. For instance, I have a SanDisk SD Card that is advertised as 8 GB, but it has 7.95 GB of actual space. I also have a Kingston SD Card that is advertised as 8 GB, but it has 7.97 GB of available space. Normally, this isn’t an issue, but in some circumstances it can be problematic.

When it is a problem

If you install an operating system on an SD Card and want to make a copy of it, the simplest way is to get another SD card and do a byte-by-byte copy of the card. However, if the new card is slightly smaller, the operation will fail since the last partition on the original SD card cannot be completely copied. This can lead to corruption and problems with the new SD Card. Copying an SD card from a smaller card to a larger card doesn’t have this issue, but it you lose the additional space (not a big deal if it is only 0.02 GB, but is a bigger deal if you are going from a 8 GB card to a 16 GB card).

The Solution

The solution is to shrink the last partition so that it is only as large as the actual space being used. The card can then be copied and the last partition on the new SD Card can be expanded to take up all the remaining space.

SD Clone makes this operation easy, and has 2 different ways to accomplish it. The first involves shrinking the filesystem on the original card, making an image of it, then restoring that image to a new card. The second way is to make a copy of the original SD Card to a disk image so that you are not making any changes to the source SD Card. You then do the shrink operation on the disk image, make a clone of the disk image, and then restore that image to the new SD Card. Both ways work equally well, but the second way is slower but safer (since it doesn’t change the source SD Card).

Technique 1: Shrink Original SD Card

To shrink the original SD Card, launch SD Clone 3 and insert the original SD Card. Select the SD Card in Sources, and click the Shrink button in the toolbar. This will shrink the last Linux (EXT) partition on the SD Card, and then resize the partition to the size of the filesystem. When it is done, create a clone of the SD Card by selecting the SD Card in Sources, select Save Image in Destinations, and click Save Image…

Once the image has been created, you can expand the filesystem on the original SD Card by selecting the SD Card and click Expand in the toolbar. You can then eject the original SD Card, insert a new SD Card, and restore the image to the new SD Card. The size shown next to the image in sources is the minimum size SD Card you will need to restore the image.

Technique 2: Create Image, Restore to Disk Image, Shrink, Clone and Restore

The second way to do this involves a few more steps, but is safer since you do not change the source. As with the first technique, insert the original SD Card. Select it in Sources, and create an image of it by selecting Save Image and clicking the Save Image button. Give the image a name and click Save, and a image of the entire SD Card will be saved. Once this is completed, you can eject the original SD Card and put it away for safe keeping.

Back in SD Clone, select the image you just created, and restore to a disk image by selecting Restore to Disk Image in Destinations. Click Restore to Volume…, give it a name, and click Save. This will restore the image to an MacOS disk image.

Once the disk image have been saved, it will show in the sources, and you can shrink, clone, and restore it just like an SD card using technique 1.

I create a video of how to do this as well showing both technique 1 and technique 2: