Wednesday, January 12, 2011

Exapnding ext4 root filesystem

Almost doomed the box while doing it :)

resize2fs utility allows you to expand e2fs filesystem online but there is a catch -> you cannot expand the filesystem beyond its partition boundary. Your filesystem is most likely using entire partition anyway.

- Use fdisk and first "p"rint the existing partition table

Disk /dev/sda: 8032 MB, 8032092160 bytes
64 heads, 32 sectors/track, 7660 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk identifier: 0x00027054
Device Boot Start End Blocks Id System
/dev/sda1 * 1 7660 7843824 83 Linux

- Note the Start and End of the partition and partition number (sda"X")
- Delete the required partition
- Create same partition again. Use same partition number and start cylinder number
- fdisk should prompt you with maximum number cylinders you can expand to. You might need to delete partitions before doing this.
- "p"rint the partition table again and make sure that the partition number and start cylider matches
- Make sure that you toggle the bootable flag if the partition was already bootable. I missed this step and subsequent boot failed. Luckily the bootable installation media was around
- "w"rite the changes, exit and reboot. (You can abort at this step and you would be still fine if you wish not to continue)
- After reboot, resize the filesystem

root@atom:~# resize2fs /dev/sda1
resize2fs 1.41.9 (22-Aug-2009)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/sda1 to 1960956 (4k) blocks.
The filesystem on /dev/sda1 is now 1960956 blocks long.

- Enjoy!
  
NOTE: As long as your partition table is properly aligned on cylinder boundaries, you should be ok. These steps worked for me and you can follow them on your own :)