czwartek, 22 listopada 2012

Raspberry Pi: system backup with dd

First I find the device with SDHC card mounted:


pi@raspberrypi ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 7969 MB, 7969177600 bytes
4 heads, 16 sectors/track, 243200 cylinders, total 15564800 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
Disk identifier: 0x000108cb

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 15564799 7720960 83 Linux

Now I mount a USB stick for storing a copy of the system:


pi@raspberrypi ~ $ mkdir /media/sda1
## Assume USB stick is /dev/sda1
pi@raspberrypi ~ $ mount /dev/sda1 /media/sda1

Raw copy with dd


pi@raspberrypi ~ $ sudo dd if=/dev/mmcblk0 | gzip -1 > /media/sda1/sd_backup.img.gz
## w/o compression:
pi@raspberrypi ~ $ sudo dd if=/dev/mmcblk0 of=/media/sda1/sd_backup.img
## over ssh in case there is no USB stick at hand:
user@othercomputer ~ $ sudo ssh root@raspberrystar dd if=/dev/mmcblk0 | gzip -1 | dd of=sd_backup.img.gz

Note: raspberrystar is the name of my system---change it to appropriate IP address or name.

Restoring system image:


pi@raspberrypi ~ $ zcat sd_backup.img.gz > /dev/sdX

Where /dev/sdX denotes the device with blank SDHC card mounted.

More details can be found here.

Copying over sshfs:


pi@raspberrypi ~ $ sudo apt-get install sshfs fuse-utils

pi@raspberrypi ~ $ mkdir -p ~/Dist/jupiter

## mounting (as user tomek) remote directory /public/raspberry at jupiter;
## mounting point is: ~/Dist/jupiter
pi@raspberrypi ~ $ sshfs tomek@jupiter:/public/raspberry/ ~/Dist/jupiter
failed to open /dev/fuse: Permission denied

On first try failure (as usual). Only fuse group members can read/write from/to /dev/fuse. User pi should be added to group "fuse":


pi@raspberrypi ~ $ sudo usermod -a -G fuse pi

To activate the modifications made in /etc/group one should log out/log in now.


pi@raspberrypi ~ $ sshfs tomek@jupiter:/public/raspberry/ ~/Dist/jupiter
pi@raspberrypi ~ $ ls -l /home/pi/Dist/jupiter
total 0

## Raw copy with dd (with compression):
sudo dd if=/dev/mmcblk0 | gzip -1 > /home/pi/Dist/jupiter/raspberrystar.iso

Added 3 Oct 2012:


15564800+0 przeczytanych recordów
15564800+0 zapisanych recordów
skopiowane 7969177600 bajtów (8,0 GB), 3504,04 s, 2,3 MB/s

Raw copying of 8Gb SDHC card with compression over sshfs took about 1 hr. The resulting image size is about 1,6 Gb.

Brak komentarzy:

Prześlij komentarz