Wednesday, August 14, 2013

Raspberry Pi Journal #6

Back Up Your SD Card part 2

On the last journal entry, I mentioned how everybody is satisfied with turning off their Raspi and pulling the card out, only to insert it to a Windows computer just to back up their SD card. Well, I'm not going to settle for that.

So, I keep digging, and finally found the program "part image". It's a partition backup program that takes a partition and save it to a file. Sounds familiar? Yes, that's exactly what "DD" Disk Dump do!

I ran into another problem. What's the name of the OS partition? Not documented anywhere, is it? After a few trial and error with fdisk, I came up with the name /dev/mmcblk0

There are 4 different partition, mmcblk0p1, mmcblk0p2, mmcblk0p3, mmcblk0p4. I'm sure one of those thing is the swap partition.

I'm backing up the first partition to my flash drive. mmcblk0p1 is fat32, 1.04 GB. Well, I think I just backed up NOOBS bootloader partition. Oh, well. It only takes about 20 minutes, anyway. Nice interface, too.

sudo -z1 -o -d save /dev/mmcblk0p1 /mnt/Lexar/raspi-p1.partimg.gz

So, that's it! Maneuver through the GUI and make some coffee!

Be careful about some of the options. There is a sync option at the end, that you want to keep, especially if you're doing live back-up. Mount devices are also iffy, and although you can override it, you definitely want to be extra careful on this one. I almost made the mistake of copying and writing to the same device, which would be bad.

I tried to do more back up:

The file system of [/dev/mmcblk02p2] is [-unknown-], and is not supported

As is partition 3 and 4.

So, the question is: Am I fully backed up or just the NOOBS?

I did

sudo dd if=/dev/mmcblk0p2 of=/media/Lexar/raspi-2.img

2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0992122 s, 10.3 kB/s

Well, obviously, my /home directory isn't in there. Let's do partition 3:

No such file or directory

Huh? It turns out they got shifted to 5 and 6. Oh, well. This is bad. I wonder if I'm destroying the file system! Better stop here for now.

In the end, I bit the bullet, and dump those anyway. Partition 5 is about 60 MB, so I'm guessing that's the swap partition. Partition 6 took such a long time, that I simply didn't wait.

sudo dd if=/dev/mmcblk0p6 | gzip -c >/media/Lexar/raspi-6.img.gz

It does about 2 MB per minute, and so I decided not to wait. Next time, I'll do it without compression, and if desired, do the compression separately. Also, I'll probably do it in the background so I can check the copying status

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

Straight from the man page!

So, I finally did it, and what happens? Ran out of space! How can that be? And before you ask, nope, it doesn't work. Does not even boot.









No comments:

Post a Comment