Wednesday, August 10, 2011

HPUX: Extending File Systems with the LVM

If you have installed the LVM Logical Volume Manager on the root disk drive of your HP-UX 10.X system, you can use it to dynamically extend the size of a given file system. Here are some step by step instructions. Please see the individual man pages on each command for more information.

Procedure for using LVM to extend an existing file system. You must be user root to perform these steps.

 

Part I - Checking for Free Space

1. Check the current volume group for the amount of free space in the volume group. Check the number of free physical extents (Free PE):

# /usr/sbin/vgdisplay /dev/vgxx

where xx is the appropriate number for your volume group. Use bdf to see a list of all your volume groups and logical volumes.

2. You may use any free PE's to extend a file system. If you have enough free PE's already available, skip down to Part IV.

If you do not have any free PE's, you will need to create some. You can create free PE's by reducing the number of PE's in an existing logical volume, or by removing a logical volume entirely.

Part II - Removing an Existing Logical Volume

1. First, you must first unmount the logical volume:

# /etc/umount /dev/vgxx/lvolx

where xx and x are the appropriate number for your volume group and logical volume.

2. If the logical volume won't unmount because the "device is busy", the first thing to do is make sure that no users are accessing that logical volume. For example, if you are currently in the /tmp directory, you can't unmount the /tmp logical volume. Change directories to another directory outside the logical volume.

Additionally, you can use the fuser command to get a list of process IDs currently using a specified logical volume:

# fuser /dev/vgxx/lvolx

This will return either a blank line, or a list of numbers followed by lower case letters. These numbers are process IDs.

Use /bin/ps -elf | grep pid to find what these processes are and kill them. Once you've killed the processes accessing the logical volume, run the /etc/umount command again.

3. There are some logical volumes for which the /etc/umount command will always fail. For example, the /usr volume can't be unmounted. In these
cases, you will have to boot your system into single user mode. In single user mode, these volumes will automatically be unmounted for you. To get to single user mode, run the command

# shutdown

4.Now that you've unmounted the logical volume, you can remove it. Obviously, when you remove the logical volume, you lose the contents of that file system. To remove the volume use the command:

# /usr/sbin/lvremove /dev/vgxx/lvolx

You will be prompted to approve this action.

Note: If you are removing the /usr logical volume, you must use /sbin/lvremove rather than /usr/sbin/lvremove, because you just unmounted the
/usr directory.

5. Now that you have created some free physical extents, use /usr/sbin/vgdisplay /dev/vgxx to verify that new free PE's exist. Once you've verified that enough free PE's exist, skip down to Part IV.

Part III - Reducing the Size of an Existing Logical Volume

1. If you want to reduce the size of a logical volume, the process is a bit more complicated. Reducing the size of the logical volume destroys the file system. So, you need to first make a back up of the contents of the file system on the logical volume. For example, if you are reducing the /tmp logical volume, you must back up the /tmp directory tree. You can make a tape back up of the files, or you can create a tar file on another disk drive. Either way, make sure your back up is successful because the process below will destroy all the files on the logical volume.

2. Once the file system has been backed up, unmount the logical volume. Please see Part II steps 1-3 for instructions on how to unmount the logical volume.

3. Now you can reduce the size of the logical volume. For example, to reduce the size of logical volume 3 to 50 PE's, use the following command:

# /usr/sbin/lvreduce -l 50 /dev/vg00/lvol3

Note: If you are reducing the /usr logical volume, you must use /sbin/lvreduce rather than /usr/sbin/lvreduce, because you just unmounted the
/usr directory. Also note that the number specified on the command line is the final size of the logical volume, not the amount you want to reduce it by.

4. Now that you have reduced the size of the logical volume, you must create a new file system in the smaller volume. Use the command:

# /usr/sbin/newfs -F hfs /dev/vgxx/rlvolx

Note: If you are reducing the /usr file system, you must use /sbin/newfs rather than /usr/sbin/newfs, because you just unmounted the /usr directory.

5. Now, re-mount the logical volume:

# /etc/mount /dev/vgxx/lvolx

and restore the files from your back up tape or tar file. This will complete the reduction process and free up some physical extents in the volume group.

6. Now that you have created some free physical extents, use /usr/sbin/vgdisplay /dev/vgxx to verify that new free PE's exist. Once you've verified that enough free PE's exist, continue with Part IV.

 

Part IV - Extending the Logical Volume and File System

1. Now you will work with the logical volume that you want to extend. First, display the characteristics of the logical volume you are intending to extend. Use the command:

# /usr/sbin/lvdisplay /dev/vgxx/lvolx

2. Look for the keywords strict or contiguous. If you see strict, any space you add to the logical volume has to be on the same physical disk with the original space. Usually, this is not a problem. If you see contiguous, all space allocated for the logical volume (even what you want to add) has to be "together" on the physical disk. This restriction usually precludes extending the logical volume, because it is extremely unlikely that the free PE's are contiguous with this logical volume on the physical disk.

3. If the logical volume you want to extend is restricted to contiguous, you must change the configuration to non-contiguous using the command:

# /usr/sbin/lvchange -C n /dev/vgxx/lvolx


If the logical volume is labeled strict, skip this step.

4. Now unmount the logical volume. Please see Part II steps 1-3 for instructions on how to unmount the logical volume.

5. Once the logical volume is unmounted, you can assign the available PE's to the logical volume. For example, if currently the logical volume has 25 PE's allocated, and you have freed up 10 more PE's, you can extend the logical volume to a total of 35 PE's using the command:

# /usr/sbin/lvextend -l 35 /dev/vgxx/lvolx

Note: If you are extending the /usr logical volume, you must use /sbin/lvextend rather than /usr/sbin/lvextend, because you just unmounted the
/usr directory. Also note that the number specified on the command line is the final size of the logical volume, not the amount you want to increase it by.

6. Now that you have allocated additional PE's for this logical volume, you must extend the file system on the logical volume so that you can take advantage of the extra space. Use the command:

# /usr/sbin/extendfs -F hfs /dev/vgxx/rlvolx

Note: If you are extending the /usr file system, you must use /sbin/extendfs rather than /usr/sbin/extendfs, because you just unmounted the /usr directory.

7. Finally, you can mount the extended file system using the command

# /etc/mount /dev/vgxx/lvolx /mount_point

where mount_point is the directory on which the logical volume is mounted. Or, you can simply reboot the system. Use the bdf command to verify that your changes have taken affect.

(c) Originally prepared by Peggy Bruehl

No comments: