12

I'm using Ubuntu 12.04. I have an old 4GB SD card, and have just bought a new 16GB SD card. I would like to copy everything from my old 4GB SD card onto the new 16GB SD card. I was afraid that the usual copy-and-paste trick would miss out something, so I wanted to clone the old 4GB SD card onto the 16GB SD card. I used the dd command in a shell, following instructions in this link.

This worked with one small caveat. The new SD card now appeared to be 4GB. I later found out this is because the primary partition on the 16GB SD card has now shrunk to 4GB. I have solved this problem, and I think I understand it. However, my question now is, how do I clone my old 4GB SD card onto my new 16GB SD card without making the primary partition on the 16GB SD card shrink to 4GB?

Excellll
  • 12,717
Ray
  • 481

4 Answers4

6

You will allways shrink your primary primary partition to the size of the copied one unless you copy the contents of your partitions with dd.

I assume you did something like sudo dd if=/dev/sda/ of=/dev/sdb bs=4k or used an image file as temporary storage if you don't have two SD card slots. With this command you copied the partition as well as the partition table to the new SD card.

Try this (assuming your partitions are called /dev/sda1):

  • put in your 4 GB SD card
  • sudo dd if=/dev/sda1 of=~/sdcard.bin
  • put in your 16 GB SD card and make sure the primary partition spans over the whole 16 GB
  • sudo dd if=~/sdcard.bin of=/dev/sda1

This should copy only the contents of your partitions.


You could also simply resize the partition on your new SD card. If you'd like to have some information on that, you have to tell us which filesystem is used on your SD cards.

wullxz
  • 2,796
  • 2
    Thank you very much for you reply! But exactly the same thing happened with your method. If I understand it correctly, am I right to say that the difference in your method is that you use 'sda1' instead of 'sda'? So that in this way, you're targetting the partition instead of the whole drive? That made intuitive sense to me, and I thought it would work, but it didn't. My new 16GB SD card was recognised as one of 4GB again. – Ray Aug 12 '12 at 18:28
  • Maybe this is a problem with exfat but for me this also didn't work :/ – codewing Dec 25 '19 at 00:39
  • For exfat this does not work. – Rainer Glüge Jan 15 '20 at 22:39
  • Using this method the result partition will show as 16GB in size but it would still have the available free space as if it was 4GB device – oᴉɹǝɥɔ Apr 25 '22 at 17:56
2

Even if you set the partition size to be 16GB, the filesystem metada was created thinking for a 4GB partition and won't grow automatically.

The easier way to fix it is to fire up gparted and stretch the partition to use the entire disk - it will take care of fixing both the partition and the filesystem.

If you had no partition table on the old SD card, dump sda and create the sda1 partition with 16GB on the new card and use dd to write the image to that partition. You will still need a check with gparted like @Earendil described.

Renan
  • 601
1

Same thing happened here. Actually, I used the command with sda1, not sda. The easy way out is to use Gparted:

  • Right click on the partition.
  • Select check.
  • Run the check with Gparted (green check).
  • Gparted attempts to correct partition errors.

In my case it did. The SDHC card now read the 16GB correctly (before GParted showed the cloned partition as used space within the partition). Incredible how powerful Ubuntu and these Ubuntu tools are, when you master them. Hope this helps.

zero2cx
  • 641
0

Just wanted to add that I was able to make this work directly from one sd card to another, with both installed via USB at the same time, using this code:

sudo dd if=/dev/sdc of=/dev/sdb

I am running into the issue where the new SD card (originally 64gb) is now reading as the size of the cloned SD card (8gb) - and a Gparted check doesn't seem to fix this.

I'm sure I'll figure it out - just wanted to post my results and technique using one card directly to the other.

Nath
  • 1
  • 2
    Your problem was answered above by @wullxz. sudo dd if=/dev/sdc of=/dev/sdb copies the entire contents of one sd card to the other including information about the partition size the data is contained in. If the original SD card is 4GB then that DD command makes the new SD card also think it is 4GB. Instead you should do something like sudo dd if=/dev/sdc1 of=/dev/sdb1 where you copy the contents of the partition on the first SD card into a partition on the second SD card. Alternatively you could have used gparted to check the partition on the new SD card & then expand its size. – FlexMcMurphy Sep 04 '21 at 12:47