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:
Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes 4 heads, 32 sectors/track, 121280 cylinders Units = cylinders of 128 * 512 = 65536 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ee283 Device Boot Start End Blocks Id System /dev/mmcblk0p1 -- -- -- c W95 FAT32 (LBA) /dev/mmcblk0p2 ADD1 ** ** 83 Linux /dev/mmcblk0p3 ADD2 ** ** 82 Linux swap / Solaris
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 now
sudo 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.
My new partition table looks like this:
Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes 4 heads, 32 sectors/track, 121280 cylinders Units = cylinders of 128 * 512 = 65536 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ee283 Device Boot Start End Blocks Id System /dev/mmcblk0p1 17 1216 76800 c W95 FAT32 (LBA) /dev/mmcblk0p2 1233 121280 7683072 83 Linux and I was now easily able to download and install a lot of other softwares and media things. :)