Monday, July 26, 2010

Lvm


Issue:
What steps are needed to resize an existing disk partition when the Logical Volume Manager (LVM) is not being used?
Resolution:
Release Found: Red Hat Enterprise Linux version 3
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
        
  4. Run the command tune2fs -l  where represents the device file of the partition which contains the filesystem you are going to resize.
  5. 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.
  6. Reboot the system into rescue mode. Do this by booting off of the first CD and typing linux rescue at the boot: prompt.
  7. DO NOT mount any partitions, especially those on the device containing filesystems you are going to resize.
  8. Take the number of bytes you would like to resize the filesystem by, and label it Z.
  9. 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.
  10. Calculate ((N*C)/K)+1 and call the result X.
  11. 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.
  12. Subtract X from T calling the result R.
  13. Execute the command e2fsck -fy .
  14. Execute the command resize2fs .
  15. Assuming the resize was successful, run the command e2fsck -y  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.
  16. Enter the fdisk utility with the command fdisk .
  17. Display the current partition table with the p command.
  18. Use the d command to delete the partition the resized filesystem is on.
  19. Use the n command to create a new partition.
  20. For the starting cylinder, specify the same value as before. (You did print out the original partition table in step 2, right?)
  21. For the ending cylinder, specify the original ending cylinder minus N.
  22. Use the w command to save the new partition table.
  23. Run the command e2fsck -y  to verify that the filesystem is still intact.
  24. 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.
  25. If everything fails, you can usually recover by re-creating the partition tableEXACTLY as it was before. Then resize the partition back to it's original size withresize2fs . Again, use the e2fsck -y  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
        
  4. Run the command tune2fs -l  where represents the device file of the partition which contains the filesystem you are going to resize.
  5. 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.
  6. Reboot the system into rescue mode. Do this by booting off of the first CD and typing linux rescue at the boot: prompt.
  7. DO NOT mount any partitions, especially those on the device containing filesystems you are going to resize.
  8. Take the number of bytes you would like to add to the filesystem and label it Z.
  9. 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.
  10. Calculate ((N*C)/K) and call the result X.
  11. Add X to T calling the result R.
  12. Execute the command e2fsck -fy .
  13. Enter the fdisk utility with the command fdisk .
  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 Plus N.
  19. Use the w command to save the new partition table.
  20. Run the command e2fsck -y  to verify that the filesystem is intact.
  21. Execute the command resize2fs -f
    Note: you must use -f to grow filesystem otherwise it will refuse the command.
  22. Assuming the resize was successful, run the command e2fsck -y  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.
The information provided in this document is for your information only. The origin of this information may be internal or external to Red Hat. While Red Hat attempts to verify the validity of this information before it is posted, Red Hat makes no express or implied claims to its validity.