Tuesday , 19 March 2019
Breaking News

Create/Extend/reduce file system using LVM (Logical Volume Manager)

Configure disk under LVM control

Create 2 or 3 partition using fdisk and change the partition id as 8e instead 83.

Suppose, you have 2 partitions => /dev/sda12 /dev/sda13

1-Create physical volume using /dev/sda12 /dev/sda13

#pvcreate /dev/sda12 /dev/sda13

2-Create volume group

#vgcreate VolGroup0 /dev/sda12 /dev/sda13

3-Create logical volume

#lvcreate –L 100M –n LogVol1 VolGroup0

4-Create ext3 file system

#mkfs.ext3 /dev/VolGroup0/LogVol1

5- Make entry in /etc/fstab file to make it persistent across reboot.

#vi /etc/fstab
 /dev/VolGroup0/LogVol1 /mylvm ext3 defaults 1 2

6- #mount –a

Extending a Filesystem:

Create a new partition of 512 MB and be sure to set the partition type to Linux LVM and extend the file system to 40MB?

Suppose new partition you created is /dev/sda8

1- Create PV using /dev/sda8

#pvcreate /dev/sda8

Add the new partition to your volume group:

#vgextend VolGroup0 /dev/sda8

Increase or extend the LogVol0 logical volume and file system by 40MB and verify the increased size

#lvextend –L +40M /dev/VolGroup0/LogVol1
#resize2fs /dev/VolGroup0/LogVol1 

#resize2fs –p /dev/VolGroup0/LogVol1

Reducing a File System:-

1) To reduce the volume, the file system has to be reduced first.

Reduce the file system and the logical Volume by 100 MB. Assume original size is 536 MB

a) The File system has to be unmounted before reducing

#umount /mylvm

b) Make sure that the file system is in consistent state before reducing.

#fsck –f /dev/VolGroup0/LogVol1

c) Now reduce the file system by 100MB

#resize2fs /dev/VolGroup0/LogVol1 436M

d) Its now possible to reduce the LV

#lvreduce /dev/VolGroup0/LogVol1 -L 436M

e) Verify the new size by mounting the FS and running df –h

2) Remove the non redundant partition from the Volume Group. To remove the VG, the PV needs to be entirely unallocated first.

a) #pvmove /dev/sda12
b) #vgreduce VolGroup0 /dev/sda12 (=> remove the PV from VG)

Check Also

Migrating Physical Volumes in a LVM2 Volume Group

Scenario: mpath0p1 – 1 TB SATA disk                mpath1    – 3 TB SAN LUN …

Leave a Reply