SD card cloning using the dd command - more questions

7,012

Solution 1

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.

Solution 2

1. Unmount

The command

sudo umount /dev/sdc

would unmount a file system that is created directly 'in the whole drive' like in old floppy disks. Today we usually create partitions /dev/sdxn and create file systems in the partitions, where x is the drive letter and n is the partition number, so a more relevant command would be

sudo umount /dev/sdc1

or for all partitions in sdc

sudo umount /dev/sdc?

2. The eject symbol

The 'arrow' you are referring to is the eject symbol, and it will not only unmount a USB pendrive or memory card but also turn off the power for it. You need to unplug and replug the pendrive or card in order to get the power back, so that you can mount it again (maybe it automounts).

This is different to what you do with the umount command. I think the udisks software is called from that eject symbol. See

man udisksctl

which describes a command line utility for it.

3. Which partition as seen by Disks ...

Clone a whole drive to clone the whole operating system. You should use the source device /dev/sdx, otherwise you are only cloning a partition and it will not contain the whole system. There should be a drive letter but no partition number. You can also use Clonezilla or mkusb to clone in a safer way (dd is dangerous).

If you want to use dd anyway, you should start by unmounting all partitions on the drive,

sudo umount /dev/sdc?

and after that the command line that you show in the edited question should do the job,

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

and if I understand correctly, it works for you (to create a compressed image file, that can be used to restore the system).

  • It should work directly with an inverse command line to create a working system if there is an MSDOS partition table (MBR).

  • If there is a GUID partition table (GPT), you must repair the backup partition table at the end of the drive (if the target drive size is not exactly the same as that of the source drive). This is done automatically with mkusb, and can be done manually with gdisk or with the script gpt-fix.

Share:
7,012

Related videos on Youtube

witenitenz
Author by

witenitenz

Updated on September 18, 2022

Comments

  • witenitenz
    witenitenz over 1 year

    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.

    • sudodus
      sudodus over 6 years
      1. Please edit your original question to show the whole command line you used to unmount; 2. I can't see any upwards facing arrow, but there is a triangle 'on mounted partitions', and when I click on it and below there is button with a square, that you can click on to unmount. Then the symbol on the button turns into a triangle, and if you click again, it mounts the partition; 3. To clone a drive, you should use /dev/sdx to clone the whole drive. There should be a drive letter but no partition number. You can also use Clonezilla or mkusb to clone in a safer way (dd is dangerous).
    • witenitenz
      witenitenz over 6 years
      edited as requested. The picture with the little arrow next to the HDD is what I'm talking about. SD card does the exact same thing. To clarify, this is seen in Files (equivalent of windows explorer) in Ubuntu 16.04 GUI. Thank you.
  • witenitenz
    witenitenz over 6 years
    Thank you. The unmounting points you made with regard to partitions certainly cleared that up for me. With regard to the eject symbol, that is what I thought, that it does more than just unmounts a drive, it physically powers down too. This makes it an unsuitable option when you only wish to unmount and then use a tool such as dd to image the disk for example.
  • sudodus
    sudodus over 6 years
    @witenitenz, You are right. When you wish to unmount and then use a tool such as dd to image the disk, you should use the command line tool umount.