Upgrading SD on the Raspberry Pi

I’ve been running my Raspberry Pi (V2) for almost a year and a half on a 16gb SD card, but because I run owncloud on the pi, I’ve been slowly running out of space. I know I can just add a usb drive or have owncloud store the data on an attached NAS or something, but I chose to just store everything on the SD card. Just so everything is in the one place. Anyway, I finally got around to purchasing a 32GB card, to upgrade the pi. I didn’t want to start from scratch and re-install everything from a backup, so I did a bit of searching in the raspberry pi forums, and found you can easily upgrade the SD card. And it turns out it was very easy. All you need is another machine (I used GNU/Linux here) and a SD card reader (which you probably have if you have a pi)

So here are the few steps I took to upgrade the SD in the Pi, retaining the whole OS and everything I had installed on it.

  • Safely power off the pi
    • Wait about 60-90 seconds while things power off completely. You shouldn’t see the green activity led flicker anymore once its fully shut down
 sudo poweroff 
  • Get the SD card and plug into your other machine, making sure you un-mount it if it automounts
  • Find out where the sd card is
    • Look for your SD card in the list and note its location, for me this was /dev/sdd
sudo fdisk -l
  • Take an image of the SD card with dd. This will take quite a long time, it took around 30 minutes for me, for 16gb. You can speed this up, at the risk of corruption
    • the status=progress is just a nice way to see how things are going without using the pkill trick
sudo dd status=progress if=/dev/sdd of=/home/george/rpi-16gb.img
  • Once this is complete, sync and unmount the drive. Plug in the larger SD card now
  • Again, find out where its located sudo fdisk -l
  • Using dd, lets write the image to the new disk
    • Notice here I use a larger block size when writing to the image, this makes it alot quicker, and is fairly safe to do. If it doesn’t work for you, decrease this to 1M. This will take alot longer
sudo dd status=progress bs=4M if=/home/george/rpi-16gb.img of=/dev/sdd
  • Now we have the old image on a new SD card, time to plug it in and boot up the pi
  • Wait the usualy amount of time and ssh into your Pi. You should notice that nothing has changed. It even still thinks its on a 16gb sd card. Have a look at df -h. We will fix that next
  • Run the raspi-config tool, and choose the first option - Expand filesystem
    • wait some time and it will do its thing to expand the file system magically for you. Once its done, it will prompt you to reboot. Do this
  • ssh back in and check out df -h you should see now it can see the rest of the new SD card!

These are the steps that worked for me, and it worked first time. You may or may not find that this works straigh away. If it doesn’t, plug the HDMI in and see if there is anything strange happening at boot time, also try plugging your original SD card in and make sure that boots. If it doesn’t, you will find the image that you took of it will have the same issue (so the new one won’t boot). If it does though, try taking another dd copy of it, and checksum it against the one you took in step 4, the checksum should come back the same