Move free space out of LVM
Simple answer - you can't. (But you may want to do something else to get what you want - see below)
LVM2 has 3 'levels', the Physical Volumes (which is what I assume you are referring to as an LVM2 container), Volume Groups and Logical Volumes.
Generally you define one or more partitions to be Physical Volumes for LVM2. Once this is done, the partition cannot be used for anything else (in the same way a partition can only be used for one filesystem).
E.g.:
# pvcreate /dev/sdb3
You then create a new Volume Group or add the physical volume to an existing group
# vgcreate MyVolGroup /dev/sdb3
or
# vgextend MyVolGroup /dev/sdb3
You then create the Logical Volume, which actually gets used for a filesystem.
# lvcreate -L100G --name MyVolume MyVolGroup
The Logical Volumes can be resized without losing data, although it's non-trival. But the Physical Volumes' sizes are fixed as the partition sizes.
If you actually want to use your 400Gb of space which is already allocated to a Physical Volume (LVM2 container) then the answer is to create another Logical Volume and use that.
To find then name of the Volume Group (if you don't already know it) use the vgs
command.
# lvcreate -L400G --name MySpace VolGroup
# mkfs -text4 /dev/VolGroup/MySpace
# mount /dev/VolGroup/MySpace /mnt
The more advanced alternative, if you have enough spare space to create a new partition, is to force the existing Logical Volume to be moved (using pvmove
) so that you can free up the 500Gb Physical Volume (vgreduce
and pvremove
commands) and then create a smaller container and move the data back again, but there's probably little advantage over simply using Logical Volumes for everything.
You didn't specify why you want to shrink the LVM partition, so it is possible that you may just want to create new logical volumes within the LVM container. If you are sure that you really want to reduce the size of the LVM container, then you can use pvresize
to reduce the size of the Physical Volume, and then partitioning tools such as fdisk
or parted
to reduce the size of the disk partition that contains the physical volume. You need to make sure that you are using units of sectors when partitioning ( in parted, the unit s
command will do this ). You will need to delete the partition, then recreate it with the same starting sector, but a smaller size. If you specify the size to pvresize
in GB, you will need to convert to sectors by multiplying by 1024 * 1024 * 2, and should round up for safety, i.e. add an extra GB. You will need to reboot for the changes to the partition table to take effect, and then you may want to use pvresize
again without a size argument to expand it back up to the maximum size the new partition holds. You will then have unpartitioned space to do with as you wish.