1. create a partition
# fdisk /dev/sdb
n > p > 3 > +100M
Change the partition type:
t > 3 > l (overview) > 8e (Linux LVM) > p (verify) > w
# partprobe – push the changes to kernel.
2. create the physical volume.
# pvcreate –help
# pvcreate /dev/sdb3
Put it into Volume Group:
# vgcreate –help
# vgcreate vgmyvg /dev/sdb3
vgmyvg – this is volume group name which should be started with “vg”. Make it easy to find the volume group.
Volume group have 94MB. 4 MB are used for metadata.
3. create the logical volume from volume group:
# lvcreate –help | less
# lvcreate -n lvmylv -L 96M vgmyvg
-n is for name….is for see better
-L is required and is for size in M or G.
vgmyvg – is the name of volume group used for creation.
Now I can put file system on it.
# mkfs.ext2 /dev/vgmyvg/lvmylv
Now mount it
# mount /dev/vgmyvg/lvmylv /mnt
Now check if the LVM volume has been mounted:
# mount | grep ^/dev
The mount is /dev/mapper/
Both /dev/vgmyvg/lvmylv and /dev/mapper/vgmyvg/lvmylv are pointing to same device: ../dm-3
This is the same device mapper used for creating luks and volumes.
Growing an LVM Logical volume
Can be resizable easy.
# df -h (disk free human readable format)
If the disk is full, must make the file system bigger.
check the volume group in order to see if there is some space available.
Check VG for space available
No disk free space available.
I have to make VG bigger by adding physical volume.
# fdick /dev/sdb
I have 3 partitions. There is room for one more:
Maybe I will have to add partitions in future. For that I will have to make an extended partition and inside this extended partition I will create logical partitions. In logical partitions I will use pv.
n > e (extended) > (extended partitions consume the all remaining space).
p to test
# n > +100M > t (type) > 8e (Linux LVM) > w
I will not create the PV. I’m starting direct to resize the volume group.
# vgextend –help
# vgextend vgmyvg /dev/sdb5
# lvextend –help
# lvextend -l +100%FREE -r /dev/vgmyvg/lvmylv
-l is used to use 100% of free space
-r is to resize the file system.
Check the file system
# df -h
Shrinking an LVM Logical Volume
Need a fs which support shrinking. NFS is not supporting shrinking. ext4 is supporting
# df -h
The /moredata is not used and is ok to shrink.
# mount | grep lvmmylv
Is using an ext4 file system.
Must unmount the file system.
1. reduce file system.
Check the file system:
# e2fsck -f /dev/vgmyvg/lvmylv
and now can reduce it without issues
# man -k resize
# resize2fs /dev/vgmyvg/lvmylv 100M
2. reduce the Logical Volume
# lvreduce –help
# lvreduce -L 102400K /dev/vgmyvg/lvmylv
Press yes in order to accept.
Now I have to mount the filesystem:
# mount -a (I will mount all)
Another approach will be with lvreduce with “-r” option.
Unmount hte directory.
# umount /moredata
# lvreduce -L 50M -r /dev/vgmyvg/lvmylv
This command is doing all.
# mount -a
The volume group will be done later.
!!!!! -r is not working on all file systems.