Raspberry Pi Basics: Part III-No space left problem!

When I got my RasPi, I was trying to install quite a softwares but was facing a problem of low or almost no memory left in root file system. So I have to think ways out to repartition my SD card so as to give more space to my root file system. The default image comes with three partitions. Just check it with fdisk

sudo fdisk /dev/mmcblk0

You will get a prompt, type m for help there and see the possible options. The important ones are as follows:

d – for deleting a partition

p – print the partition table

n – create a new partition

v – verify the partition table

w – write the partition table to disk & exit

You may actually know this ancient thing already because dealing with file systems is not a new task for linux users.

Print the current partition table by using the “p” command there. You may see output like this:

Now as I could see, my space on 8 gb card is not utilised for root file system. So I just thought to alter the partition table. The points to remember are as follows:

Don`t forget the Start block address of the modifying partition.

You are actually just changing the END block address no the START, that too with same size of clusters, cylinders etc. so there is no point of data loss.

The Next partition over which you are going to extend your Current partition i.e. the partition whose is getting big and the partition who is being covered up were two different partitions but now we are overwriting the Current over the Next, so there is a complete data loss of Next partition because most probably the Next partition is of different filesystem and so the different inodes,superblock,bootblocks etc. may be there resulting in proper corruption and data loss. (Hope I made my point)

Steps to enlarge the root partition

Delete the root and next partition to it, most probably it is the swap one (so not point of data loss).

Now create a new partition giving it the same “START” address as was of the previous root partition i.e. ADD1 and press Enter for End address. It takes the default one for this.

Write everything to SD device by “w” command and then exit fdisk and reboot

Resize the system nowsudo resize2fs /dev/mmcblk0p2

It will take time, my card was of 8gb so it took quite a long. now see the disk space and availability using the “df” command. Your rootfs is changed to 3.X gb incase of 4gb card and 7.X gb in case of 8gb card.

Great help! Thnaks!
I was running low on space.
Its worth mention that an error may be displayed when running “w” option;
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.

I rebooted Raspeberry and run sudo resize2fs /dev/mmcblk0p2 after it.
All was OK.