2

My question is whether I can use the following command to create a SD card clone on the Raspberry Pi itself.

sudo dd bs=4M if=/dev/mmcblk0 of=raspbian-5.15.16.img

This can then be copied to my home PC was what I was thinking.

Philippe Gachoud
  • 267
  • 2
  • 12
sixter
  • 53
  • 1
  • 4
  • **No.** Do not do that. [See here](http://raspberrypi.stackexchange.com/a/5492/5538) and start reading at the second paragraph: "You actually do not want a complete copy of a running system as a back-up, since some of the stuff ostensibly in the filesystem exists only at runtime. Including that in a backup and then using it to recreate an image later may create problems for you." – goldilocks May 15 '16 at 11:38

3 Answers3

3

Yes you can, ... but it will almost certainly be inconsistent and not work as intended.

Any subsequent change to a sector already written will be lost which will leave the underlying file system in an unknown state. Perhaps a file has been moved or deleted and the sector is now in use by another file.

For a safer solution (if you are using Raspbian) see https://www.raspberrypi.org/blog/another-update-raspbian/ and search for "SD card copier".

One query which comes up a lot on the forums is about the best way to back up your Pi. People also want to know how to migrate their Raspbian install to a new SD card which is larger or smaller than the one they are using at the moment. This has been difficult with the command-line tools that we’ve recommended in the past, so there is now a new application to help with this, and you’ll find it in the menu under ‘Accessories’.

joan
  • 67,803
  • 5
  • 67
  • 102
2

Yes and No. You can image on the Pi itself (although this may not be the best option), BUT you need to image to some external medium.

This can be a SD Card (in a USB adaptor) a HDD or network drive.

The command above would attempt to image the Pi to a file on the SD which will fail.

The latest Raspbian has a SD Copy utility (which I have not used).

Milliways
  • 54,718
  • 26
  • 92
  • 182
2

Use the package piclone. It will copy the current running system to SD which can then be backed up to your PC using win32diskimager.

Hint: remove as much stuff that you don't use in the running image as possible to get the backup file size small. Use as small an SD that you can to keep your back up files small, also reducing image read and write in the future.

Hint 2: expand the partition on any backup SD cards as this isn't automatic.

Andy Anderson
  • 608
  • 4
  • 11
  • The comment which was most helpful to me in this answer, was to install package piclone. That installs the "SD card copier" Accessory which was missing in my desktop. – glenschler Feb 02 '21 at 20:00