How to resize the Root volume on LVM
LVM is a great utility for being able to resize volumes on the fly. However, resizing the root (/) volume is tricky since you need to unmount the volume to do file system checks, and that is impossible if you are using it. I wrote this because I could not find a way to do it anywhere else, so I studied and figured it out on my own and figure others out there may want to do this.
My reason for this was because I needed more space in my /home directories, and my root directory was way to large for what I was using it for. I made it 30GB in size, and was only using 6GB and it was not going to grow any more. I decided to shrink the root file system from 30GB to 15GB and give the other 15GB to /home. This is how I did it.
The best way to do it is with the Ubuntu Live CD for Alternate Install. It has the LVM applications already to go.
1. Reboot the computer with the CD in and boot off of CD.
2. Select Rescue a Broken System. When it gets to the point of asking you to mount a file system, tell it not to mount any file system and run from the install root.
3. From the command line, type lvmdiskscan
4. This will show you all the disks. You will see your root volume. For these purposes, it is called /dev/VolGrp000/root.
5. Run e2fsck -f /dev/VolGrp000/root
6. After that completes, run resize2fs /dev/VolGrp000/root 3932160
I went to http://www.unitconversion.org/unit_converter/data-storage.html to convert 15Gb to Blocks. Make sure you use Gb and not GB. Also, do not shrink your root filesystem smaller than what it being used. Make sure you know how much is being used and allow some room for growth. This takes a while to run.
7. Once complete you can mount the volume and verify that it did shrink by running mount /dev/VolGrp000/root /mnt and then run df and you will see the new size. After this, unmount the volume with umount /mnt
8. Now we can put the rest of the space back into the LV pool. Run
lvreduce -L 15G /dev/VolGrp000/root
Word of caution, don't shrink it smaller then what you resize2fs it otherwise you will really break your system. This will put the space back into a Spare status and you can use it as you wish.
9. Now, you can move the free 15GB to /home logical volume.
lvextend -L+15G /dev/VolGrp000/home
10. Now you have to resize the filesystem to match the size of the logical volume
11. Reboot your PC and you are done.
I hope this helps anyone.
Tags for this Thread