Or just use LVM which removes the error-prone and nail-biting fdisk step:
- Unmount filesystem.
- Extend the logical volume:
$ sudo lvextend -L2G /dev/vgname/lvname
- fsck the filesystem:
$ sudo fsck.ext3 -f /dev/vgname/lvname
- Extend the filesystem:
$ sudo resize2fs /dev/vgname/lvname
- Mount it again.
Note a couple of things:
- At no point did you have to delete a partition and create it again.
- There was no need to remember any strange numbers, only the final size you wanted it to go to. This size could also have been specified as an offset: -L+2G extends the existing LV by 2GiB.
- There is no need to remove the ext3 journal: a clean and unmounted ext3 filesystem has no journal anyway, that’s why the fsck step is done. resize2fs will tell you to do fsck if you don’t do it yourself anyway.
Also bear in mind that any logical volume can be extended as long as there are free extents available in the volume group. Whereas without LVM, it is hard to extend a partition in the middle of the disk.
Just some of the reasons why I think almost every Linux machine should use LVM.
Finally, I have heard that with recent kernels and e2fsprogs the resize2fs can be done on a mounted fs. I have not tried this though.