Вы находитесь на странице: 1из 5

Logical Volume Management (LVM) makes it easier to manage disk space.

If a file system needs more


space, it can be added to its logical volumes from the free spaces in its volume group and the file system
can be re-sized as we wish. If a disk starts to fail, replacement disk can be registered as a physical volume
with the volume group and the logical volumes extents can be migrated to the new disk without data loss.

Create LVM Storage in Linux


In a modern world every Server needs more space day by day for that we need to expand depending on our
needs. Logical volumes can be use in RAID, SAN. A Physical Disk will be grouped to create a volume
Group. Inside volume group we need to slice the space to create Logical volumes. While using logical
volumes we can extend across multiple disks, logical volumes or reduce logical volumes in size with some
commands without reformatting and re-partitioning the current disk. Volumes can stripes data across
multiple disks this can increase the I/O stats.

LVM Features
1. It is flexible to expand the space at any time.
2. Any file systems can be installed and handle.
3. Migration can be used to recover faulty disk.
4. Restore the file system using Snapshot features to earlier stage. etc

We can see the Physical Volume (PV), Volume Group (VG), Logical Volume (LV) by using following
command.

# pvs
# vgs
# lvs

Creating Physical Volumes (PV)

To create Physical Volumes (PV) using 3 disks by the following command.

# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1

Creating Volume Group (VG)

This will create the volume group using 32MB PE size in the name of myvg using 3 Physical
volumes.

# vgcreate -s 32M myvg /dev/sda1 /dev/sdb1 /dev/sdc1


Understanding vgs command output:

1. Volume Group name.


2. Physical Volumes used in this Volume Group.
3. Shows free space available in this volume group.
4. Total Size of the Volume Group.
5. Logical Volumes inside this volume group, Here we have not yet created so there is 0.
6. SN = Number of Snapshots the volume group contains. (Later we can create a snapshot).
7. Status of the Volume group as Writeable, readable, resizeable, exported, partial and
clustered, Here it is wzn- that means w = Writable, z = resizeable..
8. Number of Physical Volume (PV) used in this Volume Group.

To get more information about newly created volume groups, run the following command.

# vgdisplay tecmint_add_vg

List New Volume Groups


1. Volume group name
2. LVM Architecture used.
3. It can be read and write state, ready to use.
4. This volume group can be resizeable.
5. No of Physical disk used and they are active.
6. Volume Group total size.
7. A Single PE size was 32 here.
8. Total number of PE available in this volume group.
9. Currently we have not created any LV inside this VG so its totally free.
10. UUID of this volume group.

Method 1: Creating Logical Volumes using PE Sizes

# lvcreate -l 575 -n tecmint_public tecmint_add_vg

-l : Creating using Extent Size


-n : Give a Logical Volume name.

Creating file system


# mkfs.ext4 /dev/tecmint_add_vg/tecmint_manager

How to Extend/Reduce LVMs


For extending we need to add one physical volume (PV) if required, and then we have
to extend the volume group by extending the vg. We will get enough space to extend
the Logical volume size. So first we are going to add one physical volume.

# pvcreate /dev/sda1
# vgextend vg_tecmint /dev/sda1

We can even see which PV are used to create particular Volume group using.

# pvscan

Now we can extend thee LV

# lvextend -l +4607 /dev/vg_tecmint/LogVol01


# lvextent L +1G /dev/vg_tecmint/LogVol01
# lvresize 20G /dev/vg_tecmint/LogVol01

Use + to add the more space. After Extending, we need to re-size the file-system using.

# resize2fs /dev/vg_tecmint/LogVol01

Reducing Logical Volume (LVM)

Here we are going to see how to reduce the Logical Volumes. Everyone say its critical and may end
up with disaster while we reduce the lvm. Reducing lvm is really interesting than any other part in
Logical volume management.

1. Before starting, it is always good to backup the data, so that it will not be a headache if
something goes wrong.

2. To Reduce a logical volume there are 5 steps needed to be done very carefully.

3. While extending a volume we can extend it while the volume under mount status (online),
but for reduce we must need to unmount the file system before reducing.
Lets see what are the 6 steps below.

1. unmount the file system for reducing.

2. Check the file system after unmount.

3. Reduce the file system.

4. Reduce the Logical Volume size than Current size.

5. Recheck the file system for error.

6. Remount the file-system back to stage.

Unmount the file system


# umount -v /mnt/tecmint_reduce_test/

Then check for the file-system error using following command.

# e2fsck -ff /dev/vg_tecmint_extra/tecmint_reduce_test

Next, reduce the file-system.

# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test 8GB

Reduce the Logical volume using GB size.

# lvreduce -L -8G /dev/vg_tecmint_extra/tecmint_reduce_test

Re-size the file-system back, In this step if there is any error that means we have messed-up our
file-system.

# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test

Mount the file-system back to same point.

# mount /dev/vg_tecmint_extra/tecmint_reduce_test /mnt/tecmint_reduce_test/

________________________________________

How to Take Snapshot of Logical Volume and Restore in


LVM

LVM Snapshots are space efficient pointing time copies of lvm volumes. It works only with lvm
and consume the space only when changes are made to the source logical volume to snapshot
volume. If source volume has a huge changes made to sum of 1GB the same changes will be made
to the snapshot volume. Its best to always have a small size of changes for space efficient. Incase
the snapshot runs out of storage, we can use lvextend to grow. And if we need to shrink the
snapshot we can use lvreduce.

Take Snapshot in LVM

If we have accidentally deleted any file after creating a Snapshot we dont have to worry because
the snapshot have the original file which we have deleted. It is possible if the file was there when
the snapshot was created. Dont alter the snapshot volume, keep as it while snapshot used to do a
fast recovery.

Snapshots cant be use for backup option. Backups are Primary Copy of some datas, so we cant
use snapshot as a backup option.

Вам также может понравиться