Raspberry Pi logo, micro SD card illustration

How To Upgrade Storage Capacity On A Raspberry Pi

  • Adam Douglas
  • linux

A Raspberry Pi system are a very useful low powered single-board computer (SBC) that can do just about anything. Presently I’m using a Raspberry Pi 2 Model B with Pi-Hole software as a network wide advertisement blocking service. Those interested in setting up your own may follow my knowledge base article, Arch Linux ARM Install Pi-Hole On A Raspberry Pi. Anyway I wanted to take my setup to next level by adding Unbound, a recursive DNS resolver. So I began the process but quickly noticed that I have almost no free storage space left on the system. After quite some time I was able to clear up some log files but nothing substantial enough. The system has a max storage capacity of 8 GB, and it seems this is not enough for my needs. I decided that I’ll replace the Kingston 8 GB microSDHC UHS-I card with a SanDisk 32 GB microSDHC UHS-I card. However, this leaves me with a dilemma, I didn’t want to have to reinstall and configure Arch Linux ARM and Pi-Hole all over again. So I thought why not just image the old microSD card and write it to the new one. After that I should just be able to resize the partition size to utilize the entirety of the 32 GB microSD card. This may seem like a lot of work, but it really isn’t.

Here are the steps I took to get the job done successfully.

Danger

The instructions outlined below are done at your own risk. Data loss may occur if not done carefully.

Environment

  • Linux terminal
  • Linux graphical desktop with GParted

Assumptions

  • Steps prefixed with a “$” (dollar sign) represents the CLI (command-line interface) prompt
  • The text after the “$” is to be entered at the CLI
  • Steps prefixed with a “#” (dollar sign) represents the CLI (command-line interface) prompt
  • The text after the “#” is to be entered at the CLI
  • The partition that will be resized is the last partition on the microSD card

Instructions

  1. Powered off the Raspberry Pi.
     $ systemctl poweroff
    
  2. Removed the microSD card from the Raspberry Pi.
  3. Insert the microSD card from the Raspberry Pi into computer running Linux.
  4. Find microSD card device name.
     $ lsblk
    
     NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
     sdf      8:80   1   7.4G  0 disk
     ├─sdf1   8:81   1   100M  0 part /run/media/adam/0E9A-D8D0
     └─sdf2   8:82   1   7.3G  0 part /run/media/adam/f2577c9a-c3da-4f5f-aa38-c6a5dbcfbae1
    
  5. Umount microSD card.
     $ umount /run/media/adam/0E9A-D8D0
     $ umount /run/media/adam/f2577c9a-c3da-4f5f-aa38-c6a5dbcfbae1
    
  6. Create image of microSD card.
     # dd if=/dev/sdf of=pi-hole-alarm-8gb-sd.img
    
     # sync
    
  7. Remove the microSD card from the computer and set aside for safe keeping.
  8. Insert the 32 GB SD card into computer.
  9. Find microSD card device name.
     $ lsblk
    
     NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
     sdf      8:80   1  29.7G  0 disk
     └─sdf1   8:81   1  29.7G  0 part /run/media/adam/3938-3834
    
  10. Umount the 32 GB microSD card.
     $ umount /run/media/adam/3938-3834
    
  11. Write the 8 GB image to the 32 GB microSD card.
     # sudo dd if=pi-hole-alarm-8gb-sd.img of=/dev/sdf bs=4MB
    
     # sync
    
  12. Remove the microSD card from the computer and then insert it again.
  13. Using GParted application, select device “/dev/sdf” in the top right.

    Select device in GParted

  14. Select the partition “/dev/sdf2”.

    Select partition in GParted

  15. Click on “Resize/move the selected partition”.

    Click on resize partition in GParted

  16. Drag the right arrow all the way to the right and click on the “Resize/Move” button.

    Resize partition (before) in GParted Resize partition (after) in GParted

  17. Apply changes by clicking on the green check mark icon.

    Apply changes in GParted

    You will receive a warning message similar to the effect of “Editing partitions has the potential to cause LOSS of DATA. You are advised to backup your data before proceeding”. Click on the “Apply” button.

  18. Close summary report.
  19. Remove microSD card and begin using on the Raspberry Pi.

I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting 100DaysToOffload.com.

- modified
    • correct grammar "for" to "with"
    • correct title heading levels from 3 to 2