Monday, March 19, 2007

Resizing Linux File Systems

I hadn't done this in a while and got some new linux servers, so I'm pleased to learn that it has gotten much easier to change disk partitions with LVM. I'm doing the following on RHEL ES 4.

I'll assume logical groups and volumes have already been created, say by Dell. They'll probably do this because of the immutable physical law that it is easier to get bigger than to get smaller. If you are happy with these predefined logical volumes, you'll just need to increase the space on the existing file systems.

All of the following commands should be done as root. I'll assume your PATH is reasonable, but if not you can probably find them in /sbin/ or /usr/sbin.

  1. fdisk -l: This will show you the available devices and partitions. Use this to decide how much to increase any of the existing files.
  2. df -k: shows existing file systems. This will also show you the names of any logical volumes.
  3. vgdisplay: this will display info on your volume groups (i.e. see how much size is available).
  4. pvcreate /dev/sba: use this to initialize a new partition. You will need to do this if you have added new disks to your RAID. Get the actual device name (/dev/xyz) from the df command.
  5. lvextend -L100G /dev/VolGroup00/LogVol00: this will set the logical volume 100 GB in size. You can also use -L+10G to increase the size further. This will take a few moments to run.
  6. Use lvreduce to reduce logical volume sizes. Use this if you accidentally extend the wrong volume in the previous step (doh!).
  7. ext2online /dev/VolGroup00/LogVol00: increases the actual file system size (but see below).
The last step can depend on your file system type (mine was ext3). Look in /etc/fstab to see. This step caused some uncertainty at first, since many pages that I googled used resize2fs, but this was not in my path and so made me suspect this info may be obsolete or not appropriate for RHEL. http://kbase.redhat.com/faq/FAQ_96_4842.shtm was helpful.

[Looks like resize2fs is back in RHEL5 and Fedora Core 7, and ext2online's functionality has been incorporated in it. You just need to replace "ext2online" with "resize2fs".]

That's it. You probably will want to verify that everything worked, so do the following:
  1. umount /dev/VolGroup00/LogVol01: unmounts the volume.
  2. e2fsck /dev/VolGroup00/LogVol01: verifies the file system.
  3. mount /dev/VolGroup00/LogVol01: brings the volume and associated file system back up.
  4. df: verify the file system is mounted as expected.

No comments: