Introduction: Raspberry Pi Resize Partitons (Use All Free Space)
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.
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:
This will elevate you to root status, negating the need of sudoing a lot.
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.