First, we have to delete our current partition and create a bigger one (don’t be afraid, no data will be lost):
# fdisk /dev/xvda
Type m to get a list of all commands:
Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)
Let’s print out the partition table and look for the ext3 partition, we want to enlarge (it’s easy here, there is just one partition):
Command (m for help): p Disk /dev/xvda: 5218 MB, 5218304000 bytes 255 heads, 63 sectors/track, 634 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/xvda1 * 1 634 5092573+ 83 Linux
Now we delete the old partition (/dev/xvda1) and create a new one with the maximum available size:
Command (m for help): d Selected partition 1 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-634, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-634, default 634): Using default value 634
Our original /dev/xvda1 had the bootable flag (see fdisk -l output), so we must add it to our new /dev/xvda1 again:
Command (m for help): a Partition number (1-4): 1
Now let’s write our new partition table and exit fdisk:
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. 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. Syncing disks.
After rebooting the system (!) we can online-resize the filesystem with a simple command:
# resize2fs /dev/xvda1 resize2fs 1.39 (29-May-2006) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required Performing an on-line resize of /dev/xvda1 to 1522150 (4k) blocks. The filesystem on /dev/xvda1 is now 1522150 blocks long.