Recently for a project, I used a Raspberry Pi. Although mostly it’s preferred to use raspbian as an operating system, I chose to use Ubuntu because it gives access to the Ubuntu repositories as well. There is a complete guide for the installation here. However after sometime, I found that the Raspberry is utilizing only 2GB from its SD card which had the capacity of 8GB. This was quite a surprise because I formatted the SD card before installing Ubuntu on it.
I searched for a good resource to resolve this and I came across this wiki on elinux.org (http://elinux.org/RPi_Resize_Flash_Partitions). However based on their instructions using raspi-config was not an option because I was running Ubuntu 14.04.
The other option which actually worked for me was to manually resize the SD card on linux.
Before you proceed with anything, I highly suggest that you take a copy of your SD card using HDD Raw Copy Tool.
First to show partition information I used the following command.
$ df -h
Look for a partition which approximately has 2GB size of the distribution image.
$ umount /dev/mmcblk0p1
Then use parted to examine the card
$ sudo parted /dev/sdd(parted) unit chs(parted) printDisk /dev/sdd: 121535,3,31Sector size (logical/physical): 512B/512BBIOS cylinder,head,sector geometry: 121536,4,32. Each cylinder is 65.5kB.Partition Table: msdos
Number Start End Type File system Flags
1 16,0,0 1215,3,31 primary fat32 lba 2 1232,0,0 26671,3,31 primary ext4 3 26688,0,0 29743,3,31 primary linux-swap(v1)
Notice that nothing uses the card from the end of the cylinder 29743 to 121535 (which is the maximum). However in my case there wasn’t a third partition called the swap. There were only two partitions; namely the boot partition and the root partition. I left the boot partition alone. I wanted to fill the SD card with the root partition. Nevertheless if there was a swap, then it would have to be moved to the end of the card. (You’ll have to adjust the numbers so that the end of the partition 3 is at the end cylinder/head/sector of the card)
Here’s the calculation.
Maximum - (Partition 3 End - Partition 3 Start) ) - 1 = Partition 3 New Start
So, in this example:
(121535 - ( 29743 - 26688)) -1 = 118479
Then move the partition. ( Note that this wouldn’t work on parted versions later than 2.4 )
(parted) move 3 118479,0,0
However if there was no swap like in my case, life becomes much simpler.
(parted) rm 2(parted) mkpart primary 1232,0,0 121534,0,0(parted) quit
Note that in my case, the head and sector numbers did not exactly coincide. (eg:- 3,31 at the end). Therefore as a precaution, I counted one cylinder less from the total available cylinders. ( i.e. 121534,0,0 )
The rest of the steps were easy.
Clean and resize the root partition.
$ sudo e2fsck -f /dev/mmcblk0p1
Allow it to add lost and found
$ sudo resize2fs /dev/mmcblk0p1
After the steps this was the result.