Create LVM in Linux

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

1.What are LVM1 and LVM2?

LVM1 and LVM2 are the versions of LVM.


LVM2 uses device mapper driver contained in 2.6 kernel version.
LVM1 was included in the 2.4 kernel version.

2.What is the maximum size of a single LV, logical volume?

For 2.4 based kernels, the maximum LV size is 2TB.


For 32-bit CPUs on 2.6 kernels, the maximum LV size is 16TB.
For 64-bit CPUs on 2.6 kernels, the maximum LV size is 8EB(Exabyte).

3.List of important LVM related files and Directories?

## Directories
/etc/lvm - default lvm directory location
/etc/lvm/backup - where the automatic backups go
/etc/lvm/cache - persistent filter cache
/etc/lvm/archive - where automatic archives go after a volume group change
/var/lock/lvm - lock files to prevent metadata corruption

# Files
/etc/lvm/lvm.conf - main lvm configuration file
$HOME/.lvm - lvm history

Bash is the shell, or command language interpreter,

Also Linux shell is a user interface used for executing the commands........
This article describes a basic logic behind a Linux logical volume manager by showing real examples
of configuration and usage. Although Debian Linux will be used for this tutorial, you can also apply the
same command line syntax with other Linux distributions such as Red Hat, Mandriva, SuSe Linux and
others.

This is what we are going to do


Create Partitions
For this Linux lvm example you need an unpartitioned hard disk /dev/sdb. First you need to create
physical volumes. To do this you need partitions or a whole disk. It is possible to run pvcreate command
on /dev/sdb, but I prefer to use partitions and from partitions I later create physical volumes.

Use your preferred partitioning tool to create partitions. In this example I have used cfdisk.
Partitions are ready to use.

Create physical volumes


Use the pvcreate command to create physical volumes.

# pvcreate /dev/sdb1
# pvcreate /dev/sdb2
The pvdisplay command displays all physical volumes on your system.

# pvdisplay

Alternatively the following command should be used:

# pvdisplay /dev/sdb1

Create Virtual Group


At this stage you need to create a virtual group which will serve as a container for your physical volumes.
To create a virtual group with the name "mynew_vg" which will include /dev/sdb1 partition, you can
issue the following command:

# vgcreate mynew_vg /dev/sdb1

To include both partitions at once you can use this command:

# vgcreate mynew_vg /dev/sdb1 /dev/sdb2


Feel free to add new physical volumes to a virtual group by using the vgextend command.

# vgextend mynew_vg /dev/sdb2


Create Logical Volumes
From our big cake (virtual group) you can cut pieces (logical volumes) which will be treated as a
partitions for our linux system.

To create a logical volume, named "vol01", with a size of 400 MB from the virtual group "mynew_vg"
use the following command:

 create a logical volume of size 400 MB -L 400


 create a logical volume of size 4 GB -L 4G

# lvcreate -L 400 -n vol01 mynew_vg

With a following example you will create a logical volume with a size of 1GB and with the name vol02:

# lvcreate -L 1000 -n vol02 mynew_vg

Or

lvcreate -L 1000 -n name_of_logical_volume name_of_volume_grp


Note the free size in virtual group.
Create File system on logical volumes
The logical volume is almost ready to use. All you need to do is to create a filesystem .:

Mkfs , means “make file system”

# mkfs.ext3 -m 0 /dev/mynew_vg/vol01

the -m option specifies the percentage reserved for the super-user, set this to “0” if you wish not to
waste any space, the default is 5%

Edit /etc/fstab
Add an entry for your newly created logical volume into /etc/fstab
Mount logical volumes
Before you mount do not forget to create a mount point.

# mkdir /home/foobar
Extend logical volume
The biggest advantage of logical volume manager is that you can extend your logical volumes any time
you are running out of the space. To increase the size of a logical volume by another 800 MB you can run
this command:

# lvextend -L +800 /dev/mynew_vg/vol01

The command above does not actually increase the physical size of volume, to do that you need to:

# resize2fs /dev/mynew_vg/vol01

Look at the figure below to see what problems you may encounter when extending a volume:
6.How to reduce the File system size in Linux?

1.First we need to reduce the file system size using "resize2fs"


2.Then reduce the lvol size using "lvreduce"

#resize2fs -f /dev/VolGroup00/LogVol00 3G

#lvreduce -L 5G /dev/VG1/Lvol1
Remove logical volume
The command lvremove can be used to remove logical volumes. Make sure that before you attempt to
remove logical volumes your logical volume does not have any valuable data stored on it, moreover,
make sure the volume is unmounted.

# lvdisplay

# lvremove /dev/mynew_vg/vol02
How to find server is configured with LVM RAID ?

1. How to check linux LVM RAID ?

check the RAID status in /proc/mdstat

#cat /proc/mdstat

or

# lsraid -a /dev/mdx

2.Check the Volume group disks

#vgdisplay –v vol01(name of volume grp)

In disk we will get the device names like /dev/md1 , /dev/md2 . It means LVM RAID disks are
configured and its added to Volume Group.
How to check Linux server is configured with power path disks?

1.Check power path is installed on server?

#rpm –qa |grep -i emc

2.Check the power path status on server?

#/etc/init.d/PowerPath status

# lsmod |grep -i emc

3.Check the Volume group disks

#vgdisplay -v vg01

In disk we will get the device names like /dev/emcpowera , /dev/emcpowerb . It means
powerpath disks are configured and its added to Volume Group.

4.Check the power path disk status using below command

#powermt display dev=all


12.How to list the imported volume groups ?
Answer: Use “vgs” command to display the imported volume group.

13.How to list the available logical volumes on the system?


Answer: Use “lvs” command to list the available logical volumes on the system.

14.How to list the available physical volumes in LVM?


Answer: Use “pvs” command to list the available physical volumes.

18.How to rename volume Group ? can we rename the VG on fly ?

Answer: Yes. Its possible to rename the volume group on fly.


But the mounted volumes will not reflect the same unless you re-mount the volume with
new VG name.
Need to update the /etc/fstab with new VG name to mount the volumes across the
system reboot.

How are snapshots in LVM2 different from LVM1 in Redhat Linux?


Answer: LVM1 snapshots are readonly by default where LVM2 snapshots were read/write.

How to re-create the device files for LVM volumes ?


Answer: Run “vgmknodes” to recreate the LVM devices files.

What is lvmdump ?
Answer: “lvmdump” is tool for LVM2 to collect the various information for diagnostic
purposes.

Assume Volume group “vg02” is already exists. How do you extend the volume group with
50GB ? Provide all the steps with commands.
Answer:
1.Get the 50GB lun from SAN team.(/dev/sdd)
2.Create physcical volume ( # pvcreate /dev/sdd )
2.Extend the volume group (# vgextend vg02 /dev/sdd)
If the vg02 has two physical volumes called /dev/sdc/ & /dev/sdd. How do you remove
/dev/sdd from vg02.
Answer: “vgreduce vg02 /dev/sdd/”

How to decommission/remove LVM completely from the host ?


Answer:
1.Un-mount all the logical filesystems
2.Remove the logical volumes using “lvremove” command.
3.Destroy the volume group using “vgremove” command.
4.Use “pvremove” command remove the physical volumes from the system.

soft link and a hard link?

This example shows the difference between a soft (also


known as a symbolic link) and a hard link on a Linux
system:

echo "hello" > a ---> create a file called "a"

ln a b ---> create hard link called "b" to "a"

ln -s a c ---> create soft link called "c" to "a"

You might also like