Sunday, August 18, 2013

Raspberry Pi: Copy contents of one SD Card to another of larger size.

I use many OSes on my RPi but my favourite has to be Raspbian with a Fluxbox window manager.
It's lightweight and lends itself very well to keyboard shortcuts which allow for optimum performance speed despite the significantly underpowered CPU.

Of course, I've overclocked as much as I can without overvolting.

Well, now I've got a new 50" plasma TV with internet, hdmi ports, usb ports and everything a modern TV should have.
So, I want to use it as a screen for another of my RPi's (I've got three now).

Rather than start from scratch, I wanted to just copy everything from my 4GB Transcend Class4 SD Card to a new 8GB Sandisk Extreme Pro card.

I fired up Ubuntu 13.04 on my Dell Desktop, plugged in my SD Card reader with the Transcend card therein (which came up as /dev/sdb) and ran the following command:

/home/paul# dd if=/dev/sdb conv=sync,noerror bs=64K of=/home/paul/raspbian.img
After a little less than 4 minutes, I got the following output to indicate the required image had been written to the home directory of my Dell Desktop

60504+0 records in60504+0 records out3965190144 bytes (4.0 GB) copied, 230.983 s, 17.2 MB/s
Next, I used the following command to write the image from the Desktop to my Sandisk Class10 card

/home/paul# dd bs=1M if=raspbian.img of=/dev/sdb
After a further 4 minutes, I got the following output
3781+1 records in3781+1 records out3965190144 bytes (4.0 GB) copied, 242.555 s, 16.3 MB/s
and my Sandisk card was ready for action.
Of course, I had to make some very small changes to my /boot/config.txt file to get the display to show up on the plasma screen.
I intend to write another post about this shortly.

Additionally, given that I had transferred a 4GB image to an 8GB card, I also needed to create a Swap partition and expand the /root partition to completely fill all of the available 8GB.
This is very easy to do using Gparted (I used it from Ubuntu on the Desktop).

Once I had this done and made the required config.txt changes, the Sandisk card worked perfectly on the TV.

The only potential problem here is the space required to store the image of the card to be copied.
So, for example, if you wished to image the contents of a 16GB card, even though only one or two GB are actually being used on the card, the image size will still be a whopping 16GB which may not be available on your Desktop.

This post explains how to image the card and zip it before it's written so that the space required to store the zipped image is considerably less.

Using the same Transcend 4GB card, I made the gzipped image using the following command:

/home/paul# dd if=/dev/sdb conv=sync,noerror bs=64K | gzip -c > raspbian.img.gz
which provided this output

60504+0 records in60504+0 records out3965190144 bytes (4.0 GB) copied, 319.907 s, 12.4 MB/s
The gzipped image had a size of 2.0GB which is exactly half of the unzipped image size.
So that's good.

Next, I unzipped and wrote this image to the same Sandisk 8GB Extreme Pro card with this command:

/home/paul# gunzip -c raspbian.img.gz | dd of=/dev/sdb conv=sync,noerror bs=64K
which produced the following output

39998+41012 records in81010+0 records out5309071360 bytes (5.3 GB) copied, 329.885 s, 16.1 MB/s
 That's strange, why were 5.3GB copied when the image was only 4GB in size?

In any event, I again used Gparted to expand the /root directory and create a Swap partition.
However, according to Gparted, the file systems in each of the two existing partitions were unrecognizable.
As a result, Gparted could do nothing with these partitions.

Additionally, the Sandisk card was unbootable.

I tried this technique two or three times and always got the same negative result.

Unfortunately, I have no explanation for this.
But, as I have ample room on my Desktop for any further SD Card images I may want to produce, I'm not particularly concerned.


No comments:

Post a Comment