Shrink size of a LVM Volume Group

The next things are a very short resume of an article on how to shrink a Logical Volume group by using the rescue mode of the installation disk.

The article itself can be found at http://forums.fedoraforum.org .

The context is Redhat or Oracle Enterprise Linux.

In order to shrink an LVM volume group the only prerequisite is that you have the installation media.

1. Verify the content in advance of the logical volume group.
This can be done via the volume management tool (graphical) where you see the layout of the filesystems, or simply by using df -h on the command line. Verify the space that is in effect used in the filesystem.

2. Launch the rescue mode.
This can be achieved by booting the machine using the installation media of Redhat/Fedora/Oracle linux.
The option to launch the rescue mode is documented in the startup screen. See F2 for more informaiton after booting from the dvd/cd.
On the command prompt enter "linux rescue".
Enter the language, keyboard and network parameters. The network is not required to be available.

3. identify the filesystems to be unmounted
Typically the existing filesystems will be mounted in rescue mode in
/mnt/sysimage.
Use df -h to see a list of filesystems.

4. unmount the filesystems
Execute an umount for each of the filesystems named /mnt/sysimage/* ending with the /mnt/sysimage itselve.

5. Identify the volumegroup
Two options here:
- you looked closely to the df -h output
- you look in the /dev directory to identify the structure of the volumegroup.

6. Check the logical volumes.

Perform an e2fsck on the logical volume:
$> e2fsck -f /dev/VolGroup00/LogVol00
At the end of the command the statistics show the usage of the filesystem.

7. Resize the filesystem.
Execute resize2fs to move all files in a consistent way to the beginning of the device.
resize2fs /dev/VolGroup00/LogVol00 3G
The 3G is the indication of the size that will be used for the filesystem after the operation.

8. Release not used space.
This will physically change the size of the partition occupied.
Some OS's do not have an lvm command shell but all commands have to be passed to lvm. This is something that was not documented in the original article.
To know the existence of the lvm shell, simply type lvm. If you enter the shell ... there is one, obvious. All commands can be taken as in the original article. In the other case - so no lvm shell exists - you will need to use the command format lvm .
To resize execute the following command (for the shell way, refer to the original article).
Execute the command:
lvm lvresize --size 3G /dev/VolGroup00/LogVol00
The endpoint (cilinder) of the partition will change.

9 exit the rescue mode and restart.
This should be the most easy command ...

Tested the procedure on a OEL virtual machine running under VMWare Fusion 3 on an Apple MacBook Pro.

Me.

No comments: