Resize Root LVM Logical Volume

If the volume to be reduced is the root partition that you currently have booted, then you won't be able to unmount, and a somewhat more involved procedure is needed. If you already have another bootable harddisk, then perhaps the easiest thing to do is boot that disk with the disk to be modified as a secondary disk, and then just modify the volume using the above mentioned steps. If you don't have another bootable harddisk, presumably you have a bootable OS installation cdrom/dvd, which can be booted in linux rescue mode. That is, allow the CD to boot, and at the first prompt, type "linux rescue". If that works, you are on your way. When a prompt is given asking whether you want it to find and mount partitions, select "skip". I found that if I allowed it to mount the root partition, I could not unmount it. After a few more moments, it should finish and drop you to a prompt. In rescue mode, the vgscan, etc commands are not directly present, but the executable lvm is, which can do all those things. When you run lvm, you will get a new prompt, where you type lvm commands. In the following, the linux prompt is '#' and the lvm prompt is '>'. And I have used the default group/volume names supplied by Fedora, since presumably a newbie reading this will have used the defaults, and anyone else will be able to figure out what to change. When we skipped allowing linux rescue to find and mount the logical volumes, it also did not create device files we will need to use. So the first task to be accomplished is to use lvm to create those device files.

# lvm
> vgscan

It should should show the existing group or groups. The first task required is to activate the group.

> vgchange -a y VolGroup00
Then generate the device files.
> vgmknodes
> exit

Now shrink the existing filesystem to something a bit smaller than what you want the final filesystem size to be. You will first need to run fsck on the filesystem. For example, I wanted a 36GByte final size, so I used:

# e2fsck -f /dev/mapper/VolGroup00-LogVol00
# resize2fs /dev/mapper/VolGroup00-LogVol00 35G

Now we can shrink the volume to the desired size. Yes, the lvreduce command uses a different device file name.

# lvm
> lvreduce -L36G /dev/VolGroup00/LogVol00
> exit

Now expand the filesystem to the full size of the volume. Notice that no size parameter is used in the resize command this time.

# resize2fs /dev/mapper/VolGroup00-LogVol00
Now you can try to mount and look at it.
# mkdir /mnt/sysimage
# mount /dev/mapper/VolGroup00-LogVol00 /mnt/sysimage
# df
# ls /mnt/sysimage
It should show up with the right 36GByte size, and everything intact.
Courtesy: Redhat Archives
Note: All the Postings here are tested and then posted

Leave a Reply

Your email address will not be published. Required fields are marked *

*