Copying a working SD card to a new one.

Feb 28, 2019 19 Replies

I want to copy an existing working SD card to a newer, larger one.



Background: Following the recent discussions on SD card reliability, and having had a couple of card failures on other Raspberry Pi systems, I have now purchased a 32 GB card for my Raspberry Shake:



formatting link



Currently the 'Shake has an 8 GB card so how would I go about transferring the existing 8 GB card to the new 32 GB one?



I don't have access to a Linux systems with multiple SD card slots.



On Windows I would use Paragon's Hard Disk manager to transfer from one HD to another and it would keep all the partitions intact but rescaled to fit the new HD capacity. I had considered using a Windows disk imager program to copy the 8 GB card to a .IMG file and then writing that image to the 32 GB card, but I don't know whether Linux would even recognise the card, or be able to use its greater capacity.



If I could add a couple of SD card readers to a (different) Raspberry Pi, is there a Linux command or program which do the equivalent of Paragon's "copy disk and expand partitions"? I'm not familiar enough with Linux to know how to do this.


Thanks, David Web: http://www.satsignal.eu

As I understand it, if uyou - say - install a Raspian image on the new card, then extend the secoind partion , then copy the cintenst of yoir existing second partition to that, it should work.

Why not use a live CD to get a linux PC env?

"In our post-modern world, climate science is not powerful because it is true: it is true because it is powerful." Lucas Bergkamp

Seems likely this could work (assuming the Windows thingy doesn't panic if it sees a Linux file system) but you'll just have the file systems you had on the 8 GB card. Gparted would help with resizing the partition(s).

How about a Linux system with one card slot, and some HDD space? You just use dd to create an image file on the HDD then write that back to the larger card, then stretch the partition with gparted to fill the card (although I think you could probably use raspi-config to stretch the partition automatically I've only ever done that with a fresh install - worth a try though).

See above, only you write the image straight to the larger card rather than a file on the HDD.

Looking at my Pi the card has two partitions. One is ext4 and is mounted on /

The other is on /boot, type vfat

Now, as I understand it, the PI has no boot sector, so all you need to do is partition a raw card with anbout 44M as VFAT, and the rest as ext 4.

Then copy your existing files from one to the other.

You will need to patch the /etc/fstab on the new card to reflect the blockids of the new partitions

Or make the new partition UUIDS the same as the old SD card

Linux command blkid is your friend here.

"And if the blind lead the blind, both shall fall into the ditch". Gospel of St. Mathew 15:14

I use Rpi Clone to copy the card in the SD slot ofthe pi to a card in a USB card reader in the pi. Run RPI-CLONE and it copies the working card onto the USB card reader.

On Thu, 28 Feb 2019 16:34:26 +0200, Anssi Saari declaimed the following:

This is pretty much the practice for the BeagleBone Black... Write an image (containing Linux partitions, not a FAT to be seen) to the SD card, boot said SD card, then run some utilities to expand the file system to use the full card size.

Script, probably Beaglebone specific:

formatting link

Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

stick the card in a USB card reader then dd if=/dev/yourusb of=/home/yourname/somefile.img bs=4096 swap cards and dd if=/home/yourname/somefile.img of=/dev/yourusb bs=4096 no messing around with partitions required

Copy the old little image to the new bigger SD, boot with your RasPi, start raspi-config and use the command Advancde Options - Expand Filesystem, reboot and all is done.

except you will end up with a partition the same size you started with.

"In our post-modern world, climate science is not powerful because it is true: it is true because it is powerful." Lucas Bergkamp

If such a utility exists, yes, that is simplest.

-- If you tell a lie big enough and keep repeating it, people will eventually come to believe it. The lie can be maintained only for such time as the State can shield the people from the political, economic and/or military consequences of the lie. It thus becomes vitally important for the State to use all of its powers to repress dissent, for the truth is the mortal enemy of the lie, and thus by extension, the truth is the greatest enemy of the State.

Joseph Goebbels

Then you use; resize2fs /dev/yourusb

---druck

Thanks for the suggestions!

In the end it proved as simple as I had hoped:

8 GB card => .IMG (using Win32DiskImager) .IMG => 32 GB high-endurance card sudo raspi-config => Expand file system Reboot

I also discovered rpi-clone which may be of interest:

formatting link

Cheers, David Web: http://www.satsignal.eu

raspi-config calls resize2fs, which is available on all Linux distros.

---druck

I use rpi-clone often to easily backup my work.

Then its simples.

dd old car to new card, bott new and resize.

Only disadvnatage is the part-UUID are the same on both cards which might be 'intersting' if both are plugged into one machine.

Truth welcomes investigation because truth knows investigation will lead to converts. It is deception that uses all the other techniques.

Easiest way I've found is - get a USB/microSD card adapter.

All done directly on the Pi. Put new card in adapter and plug in to USB. Note the /dev/sd? Unmount newly mounted partition(s)! Using fdisk, make new partitions - 1 = type c ~ 100M; 2 = type 83 = rest. Make filesystems: mkfs.vfat /dev/sd?1; mkfs.ext4 /dev/sd?2 Mount the new partitions - unplug and replug USB adapter. Use: rsync -avx /boot/ /media/{newpartition1} rsync -avx / /media/{newpartition2} sync; sync and check there is nothing in {newpartition2}/boot Check the file cmdline.txt in the {newpartition1}. If there is a ROOT=PARTUUID= or ROOT=UUID= make sure to change the {longhexnumber} to the UUID or PARTUUID of {newpartition2}. (blkid is your friend). Or change to ROOT=/dev/mmcblk0p2. If ROOT=/dev/mmcblk0p2, leave it alone. Make sure there is no mount line for / in {newpartition2}/etc/fstab.

Then unmount {newpartition1} and {newpartition2} Power down, swap the SD cards and boot.

Always worked for me (but YMMV). HIH.

Chris Elvidge, England

There's a command for that too:-

tune2fs -U $(uuidgen) /dev/sdX

Where sdX is the the device you want to change.

---druck

Who is going to post the tunefs(8) joke?

[Making a copy of an SD card using rsync]

More specifically, if the mount line for / contains the UUID= either update it to the new one, or change both copies to /dev/mmcblk0p2 to make it independent of the UUID.

---druck

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required