Expand SD root filesystem.

Run df -h

Insert SD card and run df -h again.

/dev/sdc2 is partition 2 which contains the root filesystem. We’re going to expand this filesystem to match its partition size.

And then enter these commands: d, 2, n, p, 2, hit enter, hit enter, w.

Now we need to resize the filesystem in partition 2. First we need to un-mount this partition. Refer to the df -h listing to see the mount point for /dev/sdc2.

Then do these commands:

When completed, run sync and then remove the SD card. Re-insert the SD card and run df -h again to confirm if the partition is expanded.

Save and restore SD card.

Run df -h without SD card.

Insert SD card then run df -h. Notice the SD card is at /dev/sdc which has two partitions /dev/sdc1 and /dev/sdc2.

To back up the whole disk:

To back up only the used portion of disk use dd’s block size (bs) and count parameters.
For example, as we can see in above listing, both /dev/sdc1 and /dev/sdc2 partitions use less than 3GB. We can use 3000 counts of 1MB block size for 3GB. Adjust block size (bs) and count to match yours.

To restore. Use the df -h methods to confirm the SD device path. The dd command will clone the new SD to the same size as the one you save in above steps. If the new SD card is of larger size, you can expand the root partition later. See this post for instruction on how to expand partition.

The dd comand doesn’t display any progress status. It could take more than 5 minutes to finish. To see dd progress you can run pkill -USR1 -n -x dd in another terminal.