Most of the single board computer images out there are set up for a 4GB SD card, but what if you have a 16 GB card? When you fire up the image and check the disk size with:
df -h .
Sometimes it reports that the size of the drive is just 4GB, even though we know that the real size of the drive is 16GB. Here’s how to change the partition sizes to use the entire space on the SD card.
Change Partition Size
I’m going to do this example on an OlinuXino, but the same procedure will work for a Raspberry Pi, SABRE Lite, or other single board computer.
To change the partition sizes, fire up the fdisk program:
sudo fdisk /dev/mmcblk0
Fdisk is a command line utility that allows you to change disk partition sizes.
Once inside the fdisk program, it will ask you for what command you want to do. The first thing that we want to do is print the partition sizes, which is the “p” command:
Ok, now we want to delete the partition that currently exists. Don’t worry, we are going to recreate partition in a second, but this time it is going to take up all of the available space. If you have multiple partitions, delete the larger one. Delete the partition with the “d” command:
Now, we go about creating a new (larger) partition. This is done with the “n” command:
We want to create a new partition “n” that’s going to be a primary partition “p”, with the same partition number as whatever you deleted in the previous step. This partition will have the default start position, so just press enter for that question. We also want the default stop position, which will be to use up all of the disk space.
After the new partition is defined, we need to write that to disk with the “w” command. This will also exit us out of the fdisk program.
Now that we have the new allocations defined, in order for them to take effect, we need to restart the board:
sudo shutdown –r now
When the reboot has completed, we need to do one more command to finish the resizing:
sudo resize2fs /dev/mmcblk0p<#>
Where <#> is the number of the partition that you deleted and recreated. Once that completes, then we can check the disk size with:
df -h .
And see that our OS has expanded to fill the entire microSD card. Great success!
Top Comments