22

So I got my new pi and the only free SD I had was 2GB. I couldn't hold off playing with it so it had to do for the time being. I loaded raspbmc and then spent time loading repositories, add-ons and customizing to my liking.

I now I have a 16GB class 10 in the mail and am wondering how to go about copying my current setup to that SD. My first thought is use Win32 Disk Imager to read from the 2GB and then write to the 16GB. However this would then leave only 2GB available to the pi on the 16GB correct? Essentially I am wondering how one would go about re-sizing the partition to use all of the available space on the 16GB SD.

Looking here I see that the ext4 partition at /dev/mmcblk0p3 is the one that would need re-sizing. Is this possible without deleting the contents of that partition?

The problem is, I only have windows PC's available to me. I suppose I could load raspbian on the 2GB after I copy the image to the 16GB to get a more functional linux box but hopefully that's more work then necessary... Im open to any suggestions, just would rather not have to start from scratch with a fresh raspbmc install.

2

5 Answers 5

14

I think you should look into doing this so you can take and restore backups of your card from time to time. Once you get a second card and as long as you don't destroy the original one, it should be easy to experiment. And yes, it should work.

Some instructions on how to set up a card image can be found on the RPI wiki "easy SD card setup". There's also a page on resizing partitions on rpi. Raspi-config can apparently also do this automatically.

Essentially you should be able to use parted, fdisk, cfdisk or other tool to resize the root partition and use resize2fs to make the filesystem use the extra space.

This should all work from the running Linux system on the PI, so as long as you can get the image on the card correctly in windows, it shouldn't be a problem anymore.

Note that depending on your distribution of choice and version, the card may be set up in different ways and the instructions might not be correct to the letter. But the idea is the same. Find the root, stretch it, resize the filesystem and enjoy your new space (and a 16GB image you need to back up).

Related:

5

The following worked for me, with an SD card that was originally prepared with NOOBS. I was going from a 32GB SD-Card to a 128 GB Card.

  • Insert the new card into an external card reader and attach it to the Pi.
  • Close all windows that pop up
  • Open gparted using sudo gparted
  • The drop-down at the upper right will have two entries, one named /dev/mmcblk0 (that's the SD card the Pi now booted from) and one named /dev/sdb or similar, which is your new card.
  • Unmount any volumes and delete all partitions from /dev/sdb (right click on the partitions to get a menu)
  • Accept those changes, then close gparted
  • Use sudo dd if=/dev/mmcblk0 of=/dev/sdb bs=4M status=progress to clone the existing disk to the new SD card. This will take a while.
  • When it's done, open gparted again, and check that you'll now have the same partitions on the source and the target disk.
  • On the new disk, select the partition which has "extended" in the file system. This is a container for three other partitions: settings, boot and root (we want to extend the root partition, as this is the one that contains all user data and applications, but we cannot directly do that, because it's limited within that container partition)
  • Extend the size of the extended partition to fill the whole disk
  • Apply the changes
  • Note: Now the root partition still has the old size, but we could extend that now. For safety, we make sure the existing state boots first, though.
  • Now shut down the pi, and insert the new SD card into the SD card slot of the Pi.
  • Reboot, now using the new card
  • Once the Pi has booted open gparted again, and now extend the root partition to fill the whole remainder of the disk
  • Apply changes
  • Reboot
  • If everything worked well, your Pi has now much more disk space to play around with. If it failed, you still have the old card as a backup.

Note: I tried to do the partition changes on a Windows PC, using different partition tools, but they all failed with strange "Disk IO error" messages, although the SD card is clearly ok. Despite the large advertisement banners for these partition tools on google, they all failed.

3
  • Just in case anyone tries to do this over an ssh connection via xterm (-X) option, sudo -E gparted is what I needed for it to actually open up the window. :) Commented Sep 10, 2020 at 3:15
  • 1
    Thank you, very well written! I'd just like to comment that you should extend the root partition before booting from the new MicroSD, because gparted reports that extending is not possible while the partition is in use.
    – jgosar
    Commented Dec 5, 2020 at 19:10
  • @jgosar IIRC that worked for me, but yes, you can of course do that all in one go.
    – PMF
    Commented Dec 6, 2020 at 13:01
1
dd if=/dev/sdc of=/dev/sdd bs=1m

I don't see how you can do this on the pi as it has only one SD card slot.

2
  • 3
    I do not think this would help the OP much. As you point out the RPi only has one SD card slot - though it might be possible to add another one to the SPI pins on the GPIO port, or via a Card Reader/Writer plugged into a powered Hub attached to the USB bus. Using dd to read/write from/to the storage medium is best done on inactive media which requires mounting the SD Card in say a Linux PC - but as the OP is talking about using Win32 Disk Imager it is reasonable to believe that they have (only) a Windows PC!
    – SlySven
    Commented Jan 19, 2016 at 4:07
  • 1
    Think outside of the box, guys (literally): take old small SD card of of the Pi, insert into laptop, run dd if=/dev/sdc of=/tmp/image.bin bs=1m, take out old small SD card out of laptop and put in new big SD card, run dd if=/tmp/image.bin of=/dev/hdc bs=1m, take new big SD card from laptop and put it into the Pi. Commented Dec 9, 2016 at 14:25
1

There is an app called sdcard copier (piclone) available now. Use that app to make a complete backup of your OS and you can use that later.

0

In your case, where your original card is smaller, and the target is bigger you can go straight with:

dd if=/dev/sdc of=/dev/sdd bs=1m

This will make a byte level clone from sdc to sdd, but beware those might be different in your specific case.

After that, you just boot & run raspi-config on the new card and let it resize the partition, voila!.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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