How to reduce the size of a non-root LVM and assign that space to the root LVM?
Issue
- Need to reduce the size of a non-root LVM and assign that space to the root LVM as / is running out of space.
Environment
- Red Hat Enterprise Linux 5.6
Resolution
- The following instructions can be followed in order to achive it. Since the file system which needs to be reduced is not root file system, this steps can be done from the current runlevel itself. For reducing root LVM, it is needed to boot in to rescue mode.
- Unmout the file system which needs to be reduced.
- # umount <file_system>
- Reduce the file system by using resize2fs command.
- # resize2fs <full_path_of_LVM> <size_which you want the file system to be>
Example;
# resize2fs /dev/VolGroup00/LogVol05 400G
- Then, reduce the corresponding LVM of that file system.
- # lvreduce -L -size <full_path_of_LVM>
(size should be the value which we want to reduce)
Example here;
# lvreduce -L -62G
/dev/VolGroup00/LogVol05
(For RHEL5) This command will reduce the LV and the
file system together. (If you have done Step 2 and/or 3, you don't need to do
this step.)
# lvreduce -L -62G -r /dev/VolGroup00/LogVol05
Here, this file system is presently 462GB, and it is
reducing to 400 in this example.
- Then, increase the size of corresponding LVM of /.
- # lvextend -L +size <full_path_of_LVM>
- Extent / file system online.
- # resize2fs /
Please verify the sizes by using df -h command.
Note:
online shrink a filesystem is not supported and it will
probably not be supported since the problems it can raise
Root Cause
Shrink a filesystem is possible while umounted depending on
the filesystem (not all filesystems are able to be shrinked). But, do it in a
online way is almost impractical.
While online resizing a filesystem, the filesystem itself
does not need to care about hashing or locking the new blocks added to the
filesystem (operations that may cause deadlocks or data corruption). Once these
blocks are new, there are no users using it or page/buffers mapped on them.
To shrink a filesystem, the filesystem needs to care about
possible allocated blocks and inodes on the space to be freed, such operations
like reallocate inodes and/or data blocks, besides to be an expensive operation
to the filesystem, it will need to ensure there are no pages or buffers using
the blocks and/or inodes to be re-allocated, which can lead to deadlocks and also
filesystem corruptions.
No comments:
Post a Comment