Resizing ext3 partitions with parted

The other day I got an new laptop and , due to the windows tax, it came with Windows Vista pre-installed. I usually don't even bother booting into windows but just slap in the Linux DVD and choose "Use entire disk" at the appropriate point in the installation.

However we are getting more and more client switching their MSSQL databases over to MySQL and we usually need to migrate their data across. With the MySQL data migration tool this is usually not a problem, having a place to restore the MSSQL database before migration is. I therefore decided to keep the partition.

So for the first time during installation I kept the existing partition and proceeded with the installers recommended options for the partition sizes. All went well and in about 20 minutes I had a complete system up and running.

Later however I noticed that there was a large amount of unpartitioned disk space and I needed to resize my Linux ext3 partition. Usually I use LVM so resizing isn't a problem but during the installation an ordinary primary partition had been created.

GNU Parted to the rescue

I knew about GNU's parted programme so decided to give it a bash. I booted off of Knoppix 5.1.1 went to the command line (the ati card was not detected properly) and ran:

parted -i /dev/sda
print <=== to get the current partition table and starting size for the linux partition.
resize <partition> <start> <end>

My partition was 3 and the start and end values I got from the table produced by the print command. Start was the start value for the existing partition and the end was the size of the disk provided in the table header.

At this point I got the error "Incompatible file system features" Parted has problems with the resize_inode and dir_index features that were enabled on my file system. To disable them I ran

debugfs -w -R "feature -dir_index -resize_inode"

Back to parted. I ran the command resize <partition> <start> <end> I then got the error along the lines of

"This ext2 filesystem has a rather strange layout! Parted
can't resize this (yet)"

It turned out Knoppix 5.1.1 was running parted 6.9.1 and I needed parted 7.1. So I booted off of the Ubuntu Feisty DVD which had the correct version. When I ran the above command I got warnings and error messages and the resize failed.

The next step was to boot the Ubuntu CD choose "text install" and get to the stage about resizing partitions. I used the installer to resize the partition, redefined its mount point, bootable flag, chose "leave existing data" and wrote the results to the partition table. I then canceled the install.

This sorted out the partition problems. I could now boot my Linux system fine but the file system still showed the previous file size even though the partition had been resized. I booted off the Ubuntu DVD again and ran

e2fsck -f /dev/sda3;
resize2fs /dev/sda3;

I decided to re-enable the features I had disabled with:

debugfs -w -R "feature dir_index resize_inode"

and rebooted. Ubuntu can up fine. Ask me to run one more fsck manually, rebooted and all was as it should be.