Raspberry Pi – Expanding DEBIAN to fill your SD Card

Here is how to utilise the full capacity of your Raspberry Pi’s SD card after installing the Debian image which gives a 2GB root partition:
Step 1: Run fdisk as sudo
sudo fdisk -cu /dev/mmcblk0
Step 2: enter p to view the current partition table:
Commands (m for help): p
Device        Boot  Start   End     Blocks Id System
/dev/mmcblk0p1      2048    155647  76800   c  W95 FAT32 (LBA)
/dev/mmcblk0p2      157696  3414015 1628160 83 Linux
/dev/mmcblk0p3      3416064 3807231 195584  82 Linux swap / Solaris
Step 3: Delete partitions 2 and 3 (root and swap)
Command (m for help): d 
Partition number (1-4): 2
Command (m for help):d 
Command (m for help): 3
Step 4: Create a new primary partition (2) starting where the previous partition 2 started (usually 157696)
Command (m for help): n
Command action
e extended
p primary partition (1-4)

p
Partition number (1-4): 2
First sector (155648-8058879, default 155648: 157696
Last sector, +sectors or +size{K,M,G} (157696-8058879, default 8058879): (press enter)
Your partition table will now look something like this: (The numbers will change depending on the size of your card, I am using a 4Gb card)
p
Device        Boot Start  End     Blocks  Id System
/dev/mmcblk0p1     2048   155647  76800   c  W95 FAT32 (LBA)
/dev/mmcblk0p2     157696 8058879 3950592 83 Linux

Command (m for help): w
this writes the new partition table to the SD card
The Partition table has been altered!
Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Step 5: Reboot to reload the partition table

 sudo shutdown -r now
Step 6: Once it has rebooted, log back in and resize partition 2 (Takes a while, be patient!)
sudo resize2fs /dev/mmcblk0p2

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.