Site icon UnixArena

How to Install LVM on Linux and Disk Operations

LVM will be installed by default on Redhat Linux installation.But sometimes if you select the minimum package installation method,LVM will not be installed.So you need to install LVM package separately .Here we will see the LVM installation method and if its already installed how to verify it .Logical volume manager has two versions and those are 1.LVM-1 2.LVM-2 . In this tutorials, we are going  see about LVM2 which is default volume manager in Redhat Linux newer releases.
In later part we will see about disk operations on LVM. That will cover bringing the disk under LVM control,Replacing failed disk and Removing the disk from LVM.
1.1 Installation of LVM
1.Verify LVM is installed or not on the server.
[root@mylinz ~]#  rpm -qa |grep -i lvm
lvm2-libs-2.02.72-8.el6.x86_64
lvm2-2.02.72-8.el6.x86_64
[root@mylinz ~]#
 
2.Here LVM is already installed.If its not already installed,use yum to install LVM.
Here is the procedure to configure yum repo.
[root@mylinz ~]#  yum install lvm2*
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Package lvm2-libs-2.02.72-8.el6.x86_64 already installed and latest version
Package lvm2-2.02.72-8.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package lvm2-cluster.x86_64 0:2.02.72-8.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================
 Package        Arch         Version        Repository             Size
==============================================================================
Installing:
lvm2-cluster   x86_64     2.02.72-8.el6   local-installation       304 k
Transaction Summary
==============================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 304 k
Installed size: 580 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : lvm2-cluster-2.02.72-8.el6.x86_64                1/1
Installed:
  lvm2-cluster.x86_64 0:2.02.72-8.el6
Complete!
[root@mylinz ~]#

As per about output,LVM2 packages are already installed.But there is other package called lvm2-cluster is installed now.Its cluster logical volume manager.

3.Verify the installed LVM packages.

[root@mylinz ~]# rpm -qa |grep -i lvm
lvm2-libs-2.02.72-8.el6.x86_64
lvm2-cluster-2.02.72-8.el6.x86_64
lvm2-2.02.72-8.el6.x86_64
[root@mylinz ~]#

4.Check the LVM version.

[root@mylinz ~]# lvm version
  LVM version:     2.02.72(2) (2010-07-28)
  Library version: 1.02.53 (2010-07-28)
  Driver version:  4.17.0
[root@mylinz ~]#


5.Use “help” sub command to see the list of commands on LVM.
[root@mylinz ~]# lvm help
  Available lvm commands:
  Use 'lvm help ' for more information

  dumpconfig      Dump active configuration
  formats         List available metadata formats
  help            Display help for commands
  lvchange        Change the attributes of logical volume(s)
  lvconvert       Change logical volume layout
  lvcreate        Create a logical volume
  lvdisplay       Display information about a logical volume
  lvextend        Add space to a logical volume
  lvmchange       With the device mapper, this is obsolete and does nothing.
  lvmdiskscan     List devices that may be used as physical volumes
  lvmsadc         Collect activity data
  lvmsar          Create activity report
  lvreduce        Reduce the size of a logical volume
  lvremove        Remove logical volume(s) from the system
  lvrename        Rename a logical volume
  lvresize        Resize a logical volume
  lvs             Display information about logical volumes
  lvscan          List all logical volumes in all volume groups
  pvchange        Change attributes of physical volume(s)
  pvresize        Resize physical volume(s)
  pvck            Check the consistency of physical volume(s)
  pvcreate        Initialize physical volume(s) for use by LVM
  pvdata          Display the on-disk metadata for physical volume(s)
  pvdisplay       Display various attributes of physical volume(s)
  pvmove          Move extents from one physical volume to another
  pvremove        Remove LVM label(s) from physical volume(s)
  pvs             Display information about physical volumes
  pvscan          List all physical volumes
  segtypes        List available segment types
  vgcfgbackup     Backup volume group configuration(s)
  vgcfgrestore    Restore volume group configuration
  vgchange        Change volume group attributes
  vgck            Check the consistency of volume group(s)
  vgconvert       Change volume group metadata format
  vgcreate        Create a volume group
  vgdisplay       Display volume group information
  vgexport        Unregister volume group(s) from the system
  vgextend        Add physical volumes to a volume group
  vgimport        Register exported volume group with system
  vgmerge         Merge volume groups
  vgmknodes       Create the special files for volume group devices in /dev
  vgreduce        Remove physical volume(s) from a volume group
  vgremove        Remove volume group(s)
  vgrename        Rename a volume group
  vgs             Display information about volume groups
  vgscan          Search for all volume groups
  vgsplit         Move physical volumes into a new or existing volume group
  version         Display software and driver version information
[root@mylinz ~]#


1.2 LVM DISK OPERATIONS
 If you want to use LVM, then you have to bring the disks in to LVM control using “pvcreate” command. 


1.List the physical disks.

[root@mylinz ~]#
[root@mylinz ~]# fdisk -l |grep /dev/ |grep -v dm
Disk /dev/sdd doesn't contain a valid partition table
Disk /dev/sde doesn't contain a valid partition table
Disk /dev/sdf doesn't contain a valid partition table
Disk /dev/sdg doesn't contain a valid partition table
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1 doesn't contain a valid partition table
Disk /dev/sda: 21.5 GB, 21474836480 bytes
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              64        2611    20458496   8e  Linux LVM
Disk /dev/sdb: 536 MB, 536870912 bytes
/dev/sdb1               1         512      524272   8e  Linux LVM
Disk /dev/sdc: 536 MB, 536870912 bytes
/dev/sdc1               1         512      524272   8e  Linux LVM
Disk /dev/sdd: 536 MB, 536870912 bytes
Disk /dev/sde: 536 MB, 536870912 bytes
Disk /dev/sdf: 5368 MB, 5368709120 bytes
Disk /dev/sdg: 106 MB, 106954752 bytes
[root@mylinz ~]#


2.Use “fdisk” to label disks with LVM flags.

[root@mylinz ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x57899b26.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-512, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-512, default 512):
Using default value 512

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@mylinz ~]#


3.Verify disk label in fdisk.

[root@mylinz ~]# fdisk -l /dev/sdd

Disk /dev/sdd: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x57899b26

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         512      524272   8e  Linux LVM
[root@mylinz ~]#


4.Use pvcreate command to bring the disk under LVM control.

[root@mylinz ~]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created
[root@mylinz ~]#


5.If you are getting any error while bringing the disk to LVM control,use force flag.

[root@mylinz ~]# pvcreate -f /dev/sdd1
  Physical volume "/dev/sdd1" successfully created
[root@mylinz ~]#



6.Verify your work.

[root@mylinz ~]# pvs /dev/sdd1
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sdd1       lvm2 a-   511.98m 511.98m
[root@mylinz ~]#


How to replace a failed DISK in LVM ? 
Now most of the Linux servers are using SAN boxes for data storage.So the disk failure rate is very less compare to internal disks. But in some cases customer would like use internal disks for the LVM volumes.Here we will see how to replace a failed disk if the volume is mirrored. If any disk got failed for non-mirror volume then there is no way to recover the data and its better to remove the volume and recreate it with good disk.

High Level Plan:
1.Find out which disk is failed and what are the mirrored volumes are affected
2.Remove the volume from the diskgroup forcefully
3.Replace a new disk
4.Add a new mirror to the volumes which are affected.

Thank you for reading this article.

Exit mobile version