Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I want to backup my running Raspberry Pi to an SD card which is connected via an USB card reader.

As far as I understand, the device name of the onboard SD card in /dev is

brw-rw---T 1 root 179,   0 Jan  1  1970 mmcblk0

But how can I find the correct device name of the SD card which is conncted through the USB card reader? The LED of the card reader is on. I guess that this is good starting point.

Once I know the exact device names I know how to create a bakup usind dd. But since dd is also nicknamed destroy disk, I want to make sure I'm using the right device names before I start.

share|improve this question
add comment

2 Answers

  • 1) Make sure their is a card in your card reader and then plug it into the Raspberry Pi. If using a powered HUB then the Raspberry Pi will not reboot
  • 2) Then run "dmesg | tail" and look for /dev/sdX where X is a, b, or c (for example, the below uses 'a').
  • 3) Now as long as the plugged-in card is the same size (or larger) than what is in the Raspberry Pi SD card slot, you can run "dd if=/dev/mmcblk0 of=/dev/sda bs=1b"
  • NOTE: /dev/mmcblk0 refers to the whole SD card and not any one partition
  • NOTE: /dev/sda refers to the whole SD card in the external reader and not any one partition
  • 4) This will take anywhere from 10 min to an hour depending on the size of the SD card you have. When it's done you should as a minimum run "fsck /dev/sda2" since you copied a running "live" filesystem.

Not only is this a backup of your whole SD card (W95 "/boot", and Linux ext4 "/"), it can also be used to boot the system.

PS: I've also used this to copy my bootable 4 GB SD card to a 16 GB card and after using fdisk to make an ext4 on the remaining 12 GB and mount as /opt1.

share|improve this answer
add comment

I don't have a card reader to try with, but I would first do:

  pi@raspberrypi ~ $ ls -al /dev | grep mmc
  brw-rw---T  1 root floppy  179,   0 Dec 31  1969 mmcblk0
  brw-rw---T  1 root floppy  179,   1 Dec 31  1969 mmcblk0p1
  brw-rw---T  1 root floppy  179,   2 Nov 29 22:13 mmcblk0p2
  lrwxrwxrwx  1 root root           9 Nov 29 22:13 root -> mmcblk0p2
   pi@raspberrypi ~ $ pi

The SD card is on /dev/mmcblk0 . This is also verified by looking at /etc/fstab which mounts the file systems at boot.

  pi@raspberrypi ~ $ cat /etc/fstab
  proc            /proc           proc    defaults          0       0
  /dev/mmcblk0p1  /boot           vfat    defaults          0       2
  /dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
  pi@raspberrypi ~ $ 

Remove the card reader and look at the device file system and see what disappears. Put the card reader back in and see which device reappears.

Update

pi@raspberrypi ~ $ cd
pi@raspberrypi ~ $ ls /dev > before.txt
pi@raspberrypi ~ $ #plug in the usb reader with the SD card
pi@raspberrypi ~ $ ls /dev > after.txt
pi@raspberrypi ~ $ diff -C 2 before.txt after.txt 
*** before.txt  2012-12-01 13:29:58.234244009 -0500
--- after.txt   2012-12-01 13:31:04.313366798 -0500
***************
*** 56,59 ****
--- 56,62 ----
  raw
  root
+ sda
+ sda1
+ sda2
  shm
  snd
***************
*** 134,137 ****
--- 137,141 ----
  usbdev1.2
  usbdev1.3
+ usbdev1.4
  vchiq
  vc-mem
pi@raspberrypi ~ $ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 058f:6366 Alcor Micro Corp. Multi Flash Reader
pi@raspberrypi ~ $

This is showing that usbdev1.4 was added - the card reader. Also /dev/sda /dev/sda1 /dev/sda2 .

This is a second RPI card (not the running one) in the reader so it has two partitions mounted from /dev/sda1 and /dev/sda2 .

pi@raspberrypi ~ $ df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           1804128 1685924     26556  99% /
/dev/root        1804128 1685924     26556  99% /
devtmpfs          224436       0    224436   0% /dev
tmpfs              44900     228     44672   1% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              89780       0     89780   0% /run/shm
/dev/mmcblk0p1     57288   16896     40392  30% /boot
/dev/sda1          57288   16920     40368  30% /media/8B12-9112
/dev/sda2        1804128 1256004    456476  74% /media/29b6c2f5-5469-49f2-abd5-daa9149021cc
pi@raspberrypi ~ $

The mount points for the partitions show up on the right.

pi@raspberrypi ~ $ cd /media/8B12-9112/
pi@raspberrypi /media/8B12-9112 $ ls
bootcode.bin  fixup_cd.dat  kernel_cutdown.img    start_cd.elf
cmdline.txt   fixup.dat     kernel_emergency.img  start.elf
config.txt    issue.txt     kernel.img
pi@raspberrypi /media/8B12-9112 $
share|improve this answer
    
Thanks for explaining how to find the device of the onboard card. Unfortunately I have no clue what look at the device file system means. –  BetaRide Dec 1 '12 at 14:26
    
linux makes many hardware devices look like files in the file system. These devices show up in the /dev directory. –  Dan M Dec 1 '12 at 16:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.