Raspberry Pi Resize Partitons (Use All Free Space)

About: Hi there, I'm an engineering apprentice with a passion for computing.

Hi there,
If you have a Raspberry Pi with an SD Card larger than 2GB, then you may want access to all of the space available.
By default only 2GB is accessible.
The following will show you how to get all of your space.

NOTE: This will only work on the Debian image.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Backup

Please, if you have any data on your SD card - back it up before we start.
You can use something like Win32DiskImager (for windows).

Using Win32DiskImager, do the following to back up:
1. Run Win32DiskImager
2. Create a file
3. Click the "Read" button

Now just wait for it to finish, then boot your Raspberry Pi.

Note: This process should not affect your data - but it is good form to back up anyway.

Step 2: Locate Partitons

Firstly Login to your Raspbery Pi, then issue the following commands:
sudo -i
This will elevate you to root status, negating the need of sudoing a lot.
df -h
Make a note of the last line (shown in the image).
(It will most likely be "/dev/mmcblk0p1").

Step 3: Delete Partitons

Still logged in as root (from using sudo-i) issue the following commands:
fdisk -uc /dev/mmcblk0 <-- where mmcblk0 is what you had previously.

The prompt should change to "Command (m for help):"

Type the letter p and hit Return / Enter (this will list your partitions)

Make a note of the "Start" value for /dev/mmcblk0p2 (mine is 157696)shown in the second image.

Now type the letter d and hit Return / Enter.

The prompt will ask you for "Partition number (1-4):", type in 2 and hit Return / Enter.

Then type d again, hit Return / Enter, then enter 3 and hit Return / Enter.

Step 4: Create New Partitions

Still in the same prompt, type n and hit Return / Enter.

Now type p and hit Return / Enter to create a primary partition.

When you are asked for a "Partition number (1-4) :", type 2 and hit Return / Enter.

You will then be asked for a "First sector" value, enter the value you recorded previously (157696 for me - shown in the images below) and hit Return / Enter.

Now you'll be asked for a "Last sector", leave this blank, and hit Return / Enter.

Finally, hit w and hit Return / Enter to write the changes.

Now you need to reboot with the command reboot.

Step 5: Resize Partitons

Please note that this process will take a while, don't worry. The larger the SD card, the longer the re-size operation will take.

Login again, then type sudo -i and hit Return / Enter to raise your privileges to root.

Now type resize2fs /dev/mmcblk0p2 and hit Return / Enter.

Wait a while - have a coffee :D

Finally, after the operation completes, type df -h to see your changes.

Step 6: (Optional) Create a SWAP File

Swap isn't usually necessary - but is recommended.

Type the following as root (login, then type sudo -i):

cd /var and hit Return / Enter.

dd if=/dev/zero of=swapfile bs=1M count=256 and hit Return / Enter. <-- Set 256 to be any value you wish (in Megabytes)

This will take a while - so relax.

mkswap /var/swapfile and hit Return / Enter.

swapon /var/swapfile and hit Return / Enter.

Finally, reboot with reboot and hit Return / Enter.

You now have a fully working SWAP file for your Raspberry Pi.

Step 7: Overview

You have now re-sized the partition to use the entirety of your SD Card, and possibly created a SWAP file.

Comments and Criticisms are welcome as always.
Hope this helps, Daniel.

Be the First to Share


    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    14 Discussions


    Great guide! But just to clarify -am I supposed to be able to access the new larger partition when I plug it into my pc? Right now I have two primary patrions, but only the small one can be directly accessed.

    1 reply

    If you're looking at it under DOS/WIN, that is all you'll see.. When I started tinkering with the Pi, I accidentally blew-up the first installation.. (it refused to boot past the device start-up, just kept hanging. ) so .... I went to re-format the card... Under Windows-7.. Guess what it couldn't see? There is a program out there called "sdformatter" ( https://www.sdcard.org/downloads/formatter_3/ ), which will completely blank the card under Win/DOS.. otherwise, you'll need a 2nd machine running Linux, and following the steps mentioned.. (thankfully, I have Ultimate Edition 3.5 running on my laptop. Disk Utility came in real handy wiping the old one before I found out about SDFormatter.)


    6 years ago on Introduction

    Hi, I tried using this tutorial and got stuck one step..
    fdisk > p was not displaying any partitions for me, although I believe I followed the directions correctly.

    I did learn there is a much easier way to accomplish this task, however. If you type the command "raspi-config" the second menu option will automatically resize the partition to fill the SD card. So unless you don't want the partition to fill the card, that's probably the easier approach.

    1 reply

    7 years ago on Introduction

    Well I tried this and had a little difference:

    Device Boot Start End Blocks Id System
    /dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
    /dev/mmcblk0p2 122880 3788799 1832960 83 Linux

    Instead of the three listed in the screenshots.
    Also this command: fdisk -uc /dev/mmcblk0, did not work for me, fdisk -c /dev/mmcblk0 did though, so I'm thinking that shouldn't make much of a difference.

    But now the problem, I got till the end of step 4 and rebooted the device, but then it didn't start anymore... I'm not even getting a video signal when I plug the power in and have it connected to my screen.

    Hope you can give me some enlightment of what I did wrong, so next time I'll do it right. I did keep a backup so I'm hoping to set that back and try it again.

    Thanks in advance, must say your tutorials are very helpfull, I'm just a noob at this :)

    6 replies

    Reply 7 years ago on Introduction

    I had the same issue. I found it to be the step where he has you hit d again. Don't do this if you only have two partitions. Or else it will delete your raspberry pi partition and you will have to start over by re-installing the image on the SD card and then start from step 1 of this tutorial..

    Notice how he has a p1, p2, and p3 partition when typing p. He has three partitions...

    "Now type p and hit Return / Enter to create a primary partition."

    "The prompt will ask you for "Partition number (1-4):", type in 2 and hit Return / Enter.

    Then type d again, hit Return / Enter, then enter 3 and hit Return / Enter."


    Reply 7 years ago on Introduction

    Hi there,
    Glad they're useful :D

    Have you re-imaged the SD card yet? If so, does the Raspberry Pi work now?

    Just to confirm, you are using the Debian image?

    Hope to hear from you soon, Daniel.


    Reply 7 years ago on Introduction

    I did not re-image it, by that you mean setting the back-up back right? I'm planning to do that this weekend, don't have much time till then.

    I'm using the Debian image yes, though I used the official one from the raspberrypi.org website:


    It's also a Debian image, so that shouldn't be a problem right?

    Could you maybe point to what I could have done wrong? I'll let you know how my 2nd try goes :)


    Reply 7 years ago on Introduction

    Hi there,
    The Debian image should be exactly the same (unless they've been updated).
    All I can think of is that either the image has changed, or that you perhaps spelled something wrong (or I put it in the tutorial incorrectly).

    I'll have a look and try the new image in a day or two, then get back to you on that.


    Reply 7 years ago on Introduction

    I did a reinstall and after the first reinstall, with the password given in not working, I tried another and got it to work, even got the resizing done right.

    Thank you very much for your tutorials, they've been a welcome help!