Ubuntu – SD card cloning using the dd command – more questions

command lineddmountsd card

This is a bit of a follow on from another users question found here:
SD card cloning using the dd command

I have used the dd command to clone or make backup copies of SD cards with limited success. These are for single board computer projects of mine, where it is prudent to fully backup the SD card now and then. I say limited success because at times, I have been able to do a full restore of a system (card) using the advice found online.

Note however that at other times this has not been the case, and I am wondering whether it has something to do with the mounting (or ideally unmounting of the card as there is some confusion here (for me anyway).

Question 1: When I run umount (as suggested in the above mentioned forum page) it reports that the device is not mounted. Is that because it just unmounted the device, or because the device I have specified to unmount doesn't exist to be unmounted in the first place?

To unmount, I use the following command: sudo umount /dev/sdc

Question 2: In the Ubuntu 16.04 (Files) GUI utility, the USB memory stick or SD card inserted in USB has a little upwards facing arrow to the right of it. If you click on this, it effectively disconnects the device and makes it safe to remove. Is this the same as unmounting in the CLI? It does not appear to be the case, as when I have done so, the dd command kicks up an error that it can't find my device to create an image of. If I unplug the SD card (USB) and then plug it back in, The SD card is shown once again with the little arrow, and I can use DD without issue to create the image (though whether the image is any good is another question, as I still don't know whether or not it was actually unmounted prior to image generation!)

Upward facing arrow disconnects HDD, SD etc. Unmount?

Question 3: When I run sudo fdisk -l, I see my card listed as sdb, however if I use the disks utility, I see the SD card actually consists of at least 3 partitions (SDB repeated for 2 of the partitions, and SDB1 for the bulk or main partition). Which partition am I to select as part of the dd operation? Won't dd limit itself to only making an image of that partition, ignoring the rest of the SD card? If so it's not really relevant to call it a disk imaging tool as such…

Finally, this is the dd command that I run to create a compressed image of the SD card (When I get this right, it works perfectly, and Etcher has no issues reading the zipped image too)

sudo dd if=/dev/sdc | pv | gzip > FileNameHere.img.gz

Your assistance is appreciated for somebody who is still learning the ropes with Linux, even after several years of use and experience so far.

Best Answer

When using dd to copy block devices we need to be aware of the fact that it is a low level tool for bit per bit copying data.

This very powerful tool will copy each and every bit from the source to any destination.

  • The any destination part is decisive as it means that if you accidentally type in the wrong place it may mercilessly overwrite data there.

  • The each and every bit part also means that it will copy each single bit on any location. It will also copy NULL bits and trash content. This is very useful to create an image for recovery but it may not be what you need for a simple backup.

Because dd also does not allow incremental backups and takes considerable time I would suggest you have a look at those many different backup solutions we have to possibly find one that suits your needs better than dd.

To still answer your questions:

  1. Yes, you can unmount partitions (i.e. not drives!) both, from Nautilus, and from the command line.
  2. Yes, partitions (e.g. /sdb1) need to be unmounted to be able to copy them with dd.
  3. Yes, you can copy the whole block device (in your case /sdb) including all partitions, partition tables, deleted file, boot records, deleted partitions, and what else it may hold with dd but you can not skip "unused" areas.
Related Question