When installing most distributions of Linux such as CentOS, Fedora, RHEL and I also believe Debian by default use all available space for an LV. If you want to shrink the main LV (LogVol00) you will first have to boot your system into rescue mode. I am going to do outline this for CentOS as this is the operating system I work on but this should work for any distro using LVM2.
This proccess can go completely wrong if you miss something so as always you should do a backup before attempting any of this.You will need to put the CentOS disc into the system (or virtually mount the iso) and reboot the system. When the install prompt comes up press F5 and use the following command to boot into Rescue Mode:
After you go through the prompts (similar to a fresh install such as language, keyboard layout etc…) You can drop to a command prompt.
Important Note: Make sure you check to see if anything was mounted when you were dropped to the prompt.
Now that we are into the system we can start.
We need to check the file system to make sure there is nothing wrong before we resize:
e2fsck -f /dev/VolGroup00/LogVol00
Once that completes we will resize the filesystem:
resize2fs /dev/VolGroup00/LogVol00 40G
Now the last step is to resize the Logical Volume:
lvm lvreduce -L40G /dev/VolGroup00/LogVol00
This step will prompt you with a warning but I just accepted it and then rebooted the system.
Now that we have finished resizing and creating the new LV we can now put a file system on our fresh partition and mount it. Once your OS has booted and you are logged in we can start. First up we will want to put a Filesystem on the partition:
lvcreate -l 40G -n name_of_your_vol name_of_your_vol_grp
The above command allocates 40G of space in my_vol_grp to the newly created name_of_your_vol. The -n switch specifies the name of the logical volume we are creating.
You can display what you have just done to make sure it is what you want with:
Now to put the Filesystem on the new partition. I am going to put ext3 on the partition so i would use the following.
mke2fs -j /dev/name_of_your_vol_grp/name_of_your_vol
The -j signifies journaling support for the ext3 filesystem we are creating.
Now we can mount the drive. I am going to use a folder called new_space but you can use any folder obviously:
mount /dev/name_of_your_vol_grp/name_of_your_vol /new_space
We are now all done. We can enjoy our fresh new partition. Also if you would like to have this automount you will have to edit the /etc/fstab with your favorite editor (Vim) you can just include the following:
/dev/name_of_your_vol_grp/name_of_your_vol /new_space ext3 defaults 0 0