To answer your last question about using rsync
instead of dd
to create an image file to be used by Etcher, the answer is yes and no. Let me start at the beginning. I have not used Etcher, I have used the Pi to create its own bootable clone/backup sd card from the running system. From this sd card or stick the dd
, tar
, zip
, gzip
, type of commands can be safely used by Etcher to create an image file. The setup takes some effort, but it is easy after the setup. I apologize for the mistakes in my previous answer, I will try to correct them.
SETUP - From your addition information I see that you are running Raspbian and Recalbox and I think NOOBS was installed. I have downloaded and installed NOOBS on a used reformatted sd card, unzipped it in place, shutdown/power off, inserted in system sd slot, inserted a new sd card in a USB adaptor, powered up, selected Raspbian and Recalbox, and configured with raspi-config. I copied from my old system card, /etc/hostname, /etc/hosts, /etc/ssh/, and /home/pi/.ssh/ and rebooted.
PARTITIONS - The sd (serial disk, sda) card/stick/key/HD has sectors which hold data. Partitions (primary, extended and logical; sda1, sda2, sda5) divides the sectors into groups to hold filesystems. The logical subdivides the extended. Some useful commands are df -h
, lsblk
, sudo fdisk -l /dev/sda
, sudo blkid
, ... for partition information.
pi@RPi5:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 15G 3.7G 9.8G 28% /
devtmpfs 459M 0 459M 0% /dev
tmpfs 463M 0 463M 0% /dev/shm
tmpfs 463M 6.4M 457M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 463M 0 463M 0% /sys/fs/cgroup
/dev/mmcblk0p6 65M 21M 45M 32% /boot
tmpfs 93M 0 93M 0% /run/user/1000
/dev/sda1 30G 32K 30G 1% /media/pi/9016-4EF8
/dev/mmcblk0p9 1.9G 710M 1.1G 39% /media/pi/root0
/dev/mmcblk0p8 60M 6.8M 53M 12% /media/pi/boot0
/dev/mmcblk0p5 30M 5.4M 23M 20% /media/pi/SETTINGS
/dev/mmcblk0p10 11G 27M 9.8G 1% /media/pi/share
pi@RPi5:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 29.8G 0 disk
└─sda1 8:1 1 29.8G 0 part /media/pi/9016-4EF8
mmcblk0 179:0 0 29.8G 0 disk
├─mmcblk0p1 179:1 0 2.8G 0 part
├─mmcblk0p2 179:2 0 1K 0 part
├─mmcblk0p5 179:5 0 32M 0 part /media/pi/SETTINGS
├─mmcblk0p6 179:6 0 66M 0 part /boot
├─mmcblk0p7 179:7 0 14.4G 0 part /
├─mmcblk0p8 179:8 0 60M 0 part /media/pi/boot0
├─mmcblk0p9 179:9 0 2G 0 part /media/pi/root0
└─mmcblk0p10 179:10 0 10.6G 0 part /media/pi/share
CREATE PARTITIONS - Create partitions on /dev/sda to match thoses on /dev/mmcblk0 with values from the sudo fdisk -l /dev/mmcblk0
command. Your system will have different values that mine as I see that I made a mistake for download NOOBS to the sd card which is included in mmcblk0p1. I also see that I have mmcblk0p10 which is not in your mounts, don't include it if you don't have it (take the default end sector for mmcblk0p9). Some information lines are cut from the fdisk
command to
shorten the output.
pi@RPi5:~ $ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 29.8 GiB, 32026656768 bytes, 62552064 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000daefb
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 5773437 5771390 2.8G e W95 FAT16 (LBA)
/dev/mmcblk0p2 5773438 62552063 56778626 27.1G 5 Extended
/dev/mmcblk0p5 5775360 5840893 65534 32M 83 Linux
/dev/mmcblk0p6 5840896 5976063 135168 66M c W95 FAT32 (LBA)
/dev/mmcblk0p7 5980160 36184061 30203902 14.4G 83 Linux
/dev/mmcblk0p8 36184064 36306941 122878 60M c W95 FAT32 (LBA)
/dev/mmcblk0p9 36306944 40402941 4095998 2G 83 Linux
/dev/mmcblk0p10 40402944 62552063 22149120 10.6G 83 Linux
pi@RPi5:~ $ sudo umount /dev/sda?*
pi@RPi5:~ $ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): o
Created a new DOS disklabel with disk identifier 0x3dbbc516.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-62552063, default 2048): [Enter]
Last sector, +sectors or +size{K,M,G,T,P} ... default 62552063): +2.8G
Command (m for help):t
Selected partition 1
Hex code (type L to list all codes): e
Changed type of partition 'Linux' to 'W95 FAT16 (LBA)'.
Command (m for help): n
Partition type
Select (default p): e
Partition number (2-4, default 2): 2
First sector (5834752-62552063, default 5834752): [Enter]
Last sector, ... default 62552063): [Enter]
Command (m for help): n
Partition type
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (5836800-62552063, default 5836800): [Enter]
Last sector, default 62552063): +32M
Command (m for help): n
Select (default p): l
Adding logical partition 6
First sector (5904384-62552063, default 5904384): [Enter]
Last sector, ... default 62552063): +66M
Command (m for help): t
Partition number (1,2,5,6, default 6): [Enter]
Hex code (type L to list all codes): c
Command (m for help): n
Select (default p): l
Adding logical partition 7
First sector (6041600-62552063, default 6041600): [Enter]
Last sector, ... default 62552063): +14.4G
Command (m for help): n
Select (default p): l
Adding logical partition 8
First sector (36222976-62552063, default 36222976): [Enter]
Last sector, default 62552063): +60M
Command (m for help): t
Partition number (1,2,5-8, default 8): [Enter]
Hex code (type L to list all codes): c
Command (m for help): n
Select (default p): l
Adding logical partition 9
First sector (36347904-62552063, default 36347904): [Enter]
Last sector, ... default 62552063): +2G # take default here if no 10
Command (m for help): n
Select (default p): l
Adding logical partition 10
First sector (40544256-62552063, default 40544256): [Enter]
Last sector, ... default 62552063): [Enter]
Command (m for help): p
Disk /dev/sda: 29.8 GiB, 32026656768 bytes, 62552064 sectors
...
Disklabel type: dos
Disk identifier: 0x3dbbc516
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 5834751 5832704 2.8G e W95 FAT16 (LBA)
/dev/sda2 5834752 62552063 56717312 27G 5 Extended
/dev/sda5 5836800 5902335 65536 32M 83 Linux
/dev/sda6 5904384 6039551 135168 66M c W95 FAT32 (LBA)
/dev/sda7 6041600 36220927 30179328 14.4G 83 Linux
/dev/sda8 36222976 36345855 122880 60M c W95 FAT32 (LBA)
/dev/sda9 36347904 40542207 4194304 2G 83 Linux
/dev/sda10 40544256 62552063 22007808 10.5G 83 Linux
Command (m for help): w
The partition table has been altered.
pi@RPi5:~ $ sudo fdisk -l /dev/sda
Disk /dev/sda: 29.8 GiB, 32026656768 bytes, 62552064 sectors
...
Disklabel type: dos
Disk identifier: 0x3dbbc516
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 5834751 5832704 2.8G e W95 FAT16 (LBA)
/dev/sda2 5834752 62552063 56717312 27G 5 Extended
/dev/sda5 5836800 5902335 65536 32M 83 Linux
/dev/sda6 5904384 6039551 135168 66M c W95 FAT32 (LBA)
/dev/sda7 6041600 36220927 30179328 14.4G 83 Linux
/dev/sda8 36222976 36345855 122880 60M c W95 FAT32 (LBA)
/dev/sda9 36347904 40542207 4194304 2G 83 Linux
/dev/sda10 40544256 62552063 22007808 10.5G 83 Linux
CREATE FILESYSTEMS -
pi@RPi5:~ $ sudo mkfs.vfat -n RECOVERY /dev/sda1
pi@RPi5:~ $ sudo mkfs.ext4 -L SETTINGS /dev/sda5
pi@RPi5:~ $ sudo mkfs.vfat -n boot /dev/sda6
pi@RPi5:~ $ sudo mkfs.ext4 -L root /dev/sda7
pi@RPi5:~ $ sudo mkfs.vfat -n boot /dev/sda8
pi@RPi5:~ $ sudo mkfs.ext4 -L root /dev/sda9
pi@RPi5:~ $ sudo mkfs.ext4 -L share /dev/sda10
CLONE/COPY DATA INTO FILESYSTEMS - Raspbian will mount extra filesystems on /media/pi/...
with owner pi
and will create errors with the rsync
command. By making new mount points and mounting the filesystems there, errors will not be created. The rsync -axvHAXW
command will not cross filesystems, so /dev
, /proc
, /run
, etc (system generated filesystems) and mounted filesystems (/mnt/d1
, etc) will not be cloned/copied. It is best to not have other jobs running on the system during this section.
pi@RPi5:~ $ sudo umount /media/pi/*
pi@RPi5:~ $ sudo mkdir /mnt/d1 /mnt/d2
pi@RPi5:~ $ sudo mount /dev/mmcblk0p1 /mnt/d1
pi@RPi5:~ $ sudo mount /dev/sda1 /mnt/d2
pi@RPi5:~ $ sudo rsync -axvHAXW /mnt/d1/ /mnt/d2/ # always use trailing /
pi@RPi5:~ $ sudo umount /mnt/d? # on directors
pi@RPi5:~ $ sudo mount /dev/mmcblk0p5 /mnt/d1
pi@RPi5:~ $ sudo mount /dev/sda5 /mnt/d2
pi@RPi5:~ $ sudo rsync -axvHAXW /mnt/d1/ /mnt/d2/
pi@RPi5:~ $ sudo umount /mnt/d?
pi@RPi5:~ $ sudo mount /dev/sda6 /mnt/d2 # /boot is already mounted
pi@RPi5:~ $ sudo rsync -axvHAXW /boot/ /mnt/d2/
pi@RPi5:~ $ sudo umount /mnt/d2
pi@RPi5:~ $ sudo mount /dev/sda7 /mnt/d2 # / (root) is already mounted
pi@RPi5:~ $ sudo rsync -axvHAXW / /mnt/d2/
pi@RPi5:~ $ sudo umount /mnt/d2
pi@RPi5:~ $ sudo mount /dev/mmcblk0p8 /mnt/d1
pi@RPi5:~ $ sudo mount /dev/sda8 /mnt/d2
pi@RPi5:~ $ sudo rsync -axvHAXW /mnt/d1/ /mnt/d2/
pi@RPi5:~ $ sudo umount /mnt/d?
pi@RPi5:~ $ sudo mount /dev/mmcblk0p9 /mnt/d1
pi@RPi5:~ $ sudo mount /dev/sda9 /mnt/d2
pi@RPi5:~ $ sudo rsync -axvHAXW /mnt/d1/ /mnt/d2/
pi@RPi5:~ $ sudo umount /mnt/d?
pi@RPi5:~ $ sudo mount /dev/mmcblk0p10 /mnt/d1 # skip section if no 10
pi@RPi5:~ $ sudo mount /dev/sda10 /mnt/d2
pi@RPi5:~ $ sudo rsync -axvHAXW /mnt/d1/ /mnt/d2/
pi@RPi5:~ $ sudo umount /mnt/d?
REBOOT AND SYSTEM MOUNTS FILESYSTEMS -
pi@RPi5:~ $ sudo reboot
pi@RPi5:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 29.8G 0 disk
├─sda1 8:1 1 2.8G 0 part
├─sda2 8:2 1 1K 0 part
├─sda5 8:5 1 32M 0 part /media/pi/SETTINGS
├─sda6 8:6 1 66M 0 part /media/pi/boot1
├─sda7 8:7 1 14.4G 0 part /media/pi/root1
├─sda8 8:8 1 60M 0 part /media/pi/boot
├─sda9 8:9 1 2G 0 part /media/pi/root
└─sda10 8:10 1 10.5G 0 part /media/pi/share
mmcblk0 179:0 0 29.8G 0 disk
├─mmcblk0p1 179:1 0 2.8G 0 part
├─mmcblk0p2 179:2 0 1K 0 part
├─mmcblk0p5 179:5 0 32M 0 part /media/pi/SETTINGS1
├─mmcblk0p6 179:6 0 66M 0 part /boot
├─mmcblk0p7 179:7 0 14.4G 0 part /
├─mmcblk0p8 179:8 0 60M 0 part /media/pi/boot0
├─mmcblk0p9 179:9 0 2G 0 part /media/pi/root0
└─mmcblk0p10 179:10 0 10.6G 0 part /media/pi/share1
# If root or boot are not configured as /dev/mmcblk0... in the
# cmdline.txt and/or /etc/fstab files, then adjustments will have
# to be configured to the proper device. Check with the following
# two commands:
pi@RPI5:~ $ for x in /boot /media/pi/boot*; do ls $x/cmdline.txt; cat $x/cmdline.txt; done | awk '{ if (NF == 1) fn = $1; else for (i=1; i<NF; i++) if (substr($i,1,5) == "root=") print fn " " $i }'
... root=/dev/mmcblk0p7 ... # Good
... root=PARTUUID=000daefb-07 ... # Reconfigure sda to sda PARTUUID
pi@RPi5:~ $ for x in / /media/pi/root*; do ls $x/etc/fstab; cat $x/etc/fstab; done | grep -E 'fstab|/boot|/ ' | grep -v '#'
... /dev/mmcblk0p6 ...
DONE - The backup/clone card (sda) is basically the same as the system card (mmcblk0). If everything went right, the system can be shutdown sudo shutdown -h now
, powered off (unplug power cord), and swap the backup card with the system card. Power up and the system should boot up just like before.
pi@RPi5:~ $ sudo blkid /dev/mmcblk0 /dev/sda
/dev/mmcblk0: PTUUID="3dbbc516" PTTYPE="dos"
/dev/sda: PTUUID="000daefb" PTTYPE="dos"
Notice the PTUUID="3dbbc516"
on /dev/mmcblk0
is the same as Disk identifier: 0x3dbbc516
when I partitioned /dev/sda
earlier. Anyway, BEFORE YOU REMOVE THE BACKUP SD CARD run sudo umount /dev/sda?*
to sync the data, check unmounted status with df -h
or lsblk
command.
Also note if this sd card is placed into another system, the hostname, network config, and ssh keys/config may need to be changed.
To keep the backup current, refer to the CLONE/COPY DATA INTO FILESYSTEMS section as a guide. Don't remount root, boot, or others being used, they are already mounted.
You should be able to restore filesystem from the sda card/stick to the mmcblk0 sd card, but not the ones being used, (root, boot, or others).
The question about the bad sd card. Put it in a USB slot, run command lsblk
, if it shows up as sda
or sdb
, you should be able to format it, if it does not show up, the sd card translate tables are shot and the card is trash.
/dev/sda
contains, but trying to backup an image to itself is bound to fail! – Milliways May 02 '17 at 00:07tar -zcvf name-of-archive.tar.gz /path/to/directory-or-file
If you do not understand how a tar archive is made, you'd have to raise a different question. Also, source here: link – CoderX May 02 '17 at 18:10df
it lists a bunch of stuff but no/dev/mmcblk0p1
but only have/dev/mmcblk0p6 for /boot
/dev/mmcblk0p9 for /media/pi/root1
/dev/mmcblk0p8 for /media/pi/boot0/dev/mmcblk0p5 for /media/pi/SETTINGS`. – MFJC May 08 '17 at 09:57
/dev/mmcblk0p6 for /boot
? or/dev/root/
(this one being "mounted on /"). – MFJC May 08 '17 at 09:58sudo dd bs=4M if=/dev/mmcblk0p1 of=/yourflashdrive/raspbian.iso
withof=/etc/sda1
for my flash drive andif=/dev/mmcblk0p1
for my sd card, it doesn't work and saysdd: failed to open '/dev/sda1/backup.iso': Not a directory
. I get the same error if I try withof=/media/pi/USBDrive/backup.iso
. – MFJC May 08 '17 at 10:18if=/dev/mmcblk0p6
as my source (is this the whole sd card anyway?), it does create an img file in my home that's barely 69 Mb, so eitherif=/dev/mmcblk0p6
isn't the whole sd card (since it's several Gb large) or Gzip has the compression power of a black hole !!! – MFJC May 08 '17 at 10:46/dev/mmcblk0
, I'm gonna post thedf
result right now as you requested. – MFJC May 08 '17 at 10:48'/dev/**mmcblk0**
will backup my SD card with my 2 OSes (Raspbian and Recalbox) with their partitions etc into one ".img" file ? – MFJC May 08 '17 at 10:49