ext3

Find size of ext3 Journal

The journal is located at inode:

# tune2fs -l /dev/sda1 | awk '/Journal inode/ {print $3}'

The size of journal in Bytes is:

# debugfs -R "stat <inodenumber>" /dev/sda1 | awk '/Size: /{print $6}'|head -1

Note: "<>" is necessary around the inode number.

Extending ext3 partition

*** Make sure you have a back up prior to proceeding. ***

  1. Boot into rescue mode.
  2. Unmount partition if mounted and check disk:
    umount /dev/sda1
    e2fsck -vn /dev/sda1
  3. Delete /dev/sda1 partition and create a bigger one with fdisk:
    fdisk /dev/sda
  4. Recreate the partition /dev/sda1 with the starting point at the default location and the ending point at highest possible cylinder. (Note: if you are extending by merging two partitions, the data in the second partition is lost so make sure to backup data you need.)
  5. Run partprobe and resize2fs utility with no size arguments:
    partprobe /dev/sda
    resize2fs /dev/sda1
  6. Reboot and check everything in file-system is intact.

Shrinking ext3 partition

*** Make sure you have a back up prior to proceeding. ***

  1. Boot into rescue mode.
  2. Unmount partition if mounted and check disk:
    umount /dev/sda1
    e2fsck -vn /dev/sda1
  3. Remove journaling from ext3 partition and revert to ext2, as resize2fs does not work on ext3 partition. (Note: This step should not be necessary in recent kernels.)
    tune2fs -O ^has_journal /dev/sda1
  4. Force check the partition:
    e2fsck -vf /dev/sda1
  5. Resize the partition making sure that you don't shrink it lesser than the disk space currently used else you may lose data.
    resize2fs /dev/sda1 6000M
  6. Make a note of the blocks and block size. You can also run:
    dumpe2fs /dev/sda1
  7. Delete /dev/sda1 partition and create a smaller one with fdisk:
    fdisk /dev/sda
  8. Recreate the partition /dev/sda1 with the starting point at the default location and the ending point at number of blocks from the resize2fs output (1536000) multiplied by the size of a block (4K). So, the end point would be 1536000 * 4 = 6144000K.
  9. Run partprobe and resize2fs utility with no size arguments:
    partprobe /dev/sda
    resize2fs /dev/sda1

    Note: If resize2fs errors out, you may need to further increase the block size by a small percentage (3 to 5%).

  10. Run a disk check for the final time before restoring the journal.
    e2fsck -vn /dev/sda1
    tune2fs -j /dev/sda1
  11. Reboot and check everything in file-system is intact.

Convert root filesystem to LVM

I converted root filesystem to lvm since the root partition was huge and I needed more flexibility in managing the partitions. Besides, lvm would also enable for easy backups with lvm snapshots.

I had a sizable swap partition of 2GB which I used to transfer my root files to and rebooted to it, prior to the conversion.

Please know what you are doing prior and make sure to create backups.

Comment