REDHAT ES/AS/WS – What steps are needed to resize an existing disk partition when the Logical Volume Manager (LVM) is not being used?

Symptom:
You do not have enough space on one of your filesystems, but do on a filesystem located on another partition. You are not using the Logical Volume Manager (LVM) to “virtualize” your physical storage.

Solution:
Note: Resizing filesystems and their underlying partitions can be VERY dangerous. Also, you can only resize partitions from their end position on the disk, you can not move partitions on the disk or resize them from their beginning. While it is possible in most situations, it is not a practice Red Hat can provide support for, in any way. That said, proceed at your own risk!

Please be sure to read through all the steps first before executing the provided commands.

Here are the steps involved for SHRINKING a filesystem & partition:

  1. Backup your data.
  2. Print the output from the fdisk -l command on a printer, or write down the details by hand. This is in case you need to restore your partition table to it’s previous state.
  3. Make note of the cylinder size of the disk in bytes, and call this number C. For example, from the following output you would note C = 8225280
 
Disk /dev/hda: 40.0 GB, 40000000000 bytes
255 heads, 63 sectors/track, 4863 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
  1. Run the command tune2fs -l <device> where <device> represents the device file of the partition which contains the filesystem you are going to resize.
  2. Make note of the following values from the above output: Block count, Block Size, and Free blocks. Label the Block Count T, the Block Size K, and Free Blocks F.
  3. Reboot the system into rescue mode. Do this by booting off of the first CD and typing linux rescue at the boot: prompt.
  4. DO NOT mount any partitions, especially those on the device containing filesystems you are going to resize.
  5. Take the number of bytes you would like to resize the filesystem by, and label it Z.
  6. Divide Z by C, rounding any fraction up to the next whole number or add 1 if the result is zero. Call this resulting number N.
  7. Calculate ((N*C)/K)+1 and call the result X.
  8. Make sure that X is not greater than F. If it is, then you will need to reduce Z and repeat the last 2 steps.
  9. Subtract X from T calling the result R.
  10. Execute the command e2fsck -fy <device>.
  11. Execute the command resize2fs <device> <R>.
  12. Assuming the resize was successful, run the command e2fsck -y <device> to verify that the filesystem is still intact. If it it checks out, then continue. If it fails then you most likely have lost the data on this filesystem.
  13. Enter the fdisk utility with the command fdisk <device>.
  14. Display the current partition table with the p command.
  15. Use the d command to delete the partition the resized filesystem is on.
  16. Use the n command to create a new partition.
  17. For the starting cylinder, specify the same value as before. (You did print out the original partition table in step 2, right?)
  18. For the ending cylinder, specify the original ending cylinder minus N.
  19. Use the w command to save the new partition table.
  20. Run the command e2fsck -y <device> to verify that the filesystem is still intact.
  21. If it checks out, then your done. If the check fails to find a valid filesystem, then repeat the last 8 steps with a smaller value for N.
  22. If everything fails, you can usually recover by re-creating the partition table EXACTLY as it was before. Then resize the partition back to it’s original size with resize2fs <device> <T>. Again, use the e2fsck -y <device> command to verify that the filesystem is intact.

Here are the steps involved for EXPANDING a filesystem & partition:

  1. Backup your data.
  2. Print the output from the fdisk -l command on a printer, or write down the details by hand. This is in case you need to restore your partition table to it’s previous state.
  3. Make note of the cylinder size of the disk in bytes, and call this number C. For example, from the following output you would note C = 8225280
 
Disk /dev/hda: 40.0 GB, 40000000000 bytes
255 heads, 63 sectors/track, 4863 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
  1. Run the command tune2fs -l <device> where <device> represents the device file of the partition which contains the filesystem you are going to resize.
  2. Make note of the following values from the above output: Block count, Block Size, and Free blocks. Label the Block Count T, the Block Size K, and Free Blocks F.
  3. Reboot the system into rescue mode. Do this by booting off of the first CD and typing linux rescue at the boot: prompt.
  4. DO NOT mount any partitions, especially those on the device containing filesystems you are going to resize.
  5. Take the number of bytes you would like to add to the filesystem and label it Z.
  6. Divide Z by C, rounding any fraction up to the next whole number or add 1 if the result is zero. Call this resulting number N.
  7. Calculate ((N*C)/K) and call the result X.
  8. Add X to T calling the result R.
  9. Execute the command e2fsck -fy <device>.
  10. Enter the fdisk utility with the command fdisk <device>.
  11. Display the current partition table with the p command.
  12. Use the d command to delete the partition the resized filesystem is on.
  13. Use the n command to create a new partition.
  14. For the starting cylinder, specify the same value as before. (You did print out the original partition table in step 2, right?)
  15. For the ending cylinder, specify the original ending cylinder Plus N.
  16. Use the w command to save the new partition table.
  17. Run the command e2fsck -y <device> to verify that the filesystem is intact.
  18. Execute the command resize2fs -f <device> <R>
    Note: you must use -f to grow filesystem otherwise it will refuse the command.
  19. Assuming the resize was successful, run the command e2fsck -y <device> to verify that the filesystem is still intact. If it it checks out, your done! If it fails then you most likely have lost the data on this filesystem.