Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, 24 March 2013

Vmware Performance tuning Tips


These posts explain about Vmware performance tuning on Linux servers. These links explains the tips to tune the disk io by setting read-aheads and memory based improvements by making changes to kernel parameters like vm.swapiness, vm.overcommit_memory, vm.dirty_background_ratio, vm.dirty_ratio. They also suggests some vmware config tweaks like mainMem.useNamedFile. Worth trying if you have Vmware performance issues. But dont try in production unless you are sure of what you are doing.

Configuring Persistent static route in Linux


Static routes will be added usually through "route add" command. The drawback of 'route' command is that, when Linux reboots it will forget static routes. But to make it persistent across reboots, you have to add it to /etc/sysconfig/network-scripts/route-<eth> .

To add static route using "route add":

# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.10.1 dev eth0


Adding Persistent static route:
You need to edit /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface.

GATEWAY0=192.168.10.1
NETMASK0=255.255.255.0
ADDRESS0=192.168.100.0

GATEWAY1=10.64.34.1
NETMASK1= 255.255.255.240
ADDRESS1=10.64.34.10


Save and close the file. Restart networking:

# service network restart

Verify new routing table:

# route –n
# netstat –nr

Netapp Snapvault guide


Netapp SnapVault is a heterogeneous disk-to-disk backup solution for Netapp filers and heterogeneous OS systems (Windows, Linux , Solaris, HPUX and AIX). Basically, Snapvault uses netapp snapshot technology to take point-in-time snapshot and store them as online backups. In event of data loss or corruption on a filer, the backup data can be restored from the SnapVault filer with less downtime. It has significant advantages over traditional tape backups, like
  • Reduce backup windows versus traditional tape-based backup
  • Media cost savings
  • No backup/recovery failures due to media errors
  • Simple and Fast recovery of corrupted or destroyed data
Snapvault consists of major two entities –  snapvault clients and a snapvault storage server. A snapvault client (Netapp filers and unix/windows servers) is the system whose data should be backed-up.  The SnapVault server is a Netapp filer – which gets the data from clients and backs up data. For Server to Netapp Snapvault, we need to install Open System Snapvault client software provided by Netapp, on the servers. Using the snapvault agent software, the Snapvault server can pull and backup data on to the backup qtrees. SnapVault protects data on a client system by maintaining a number of read-only versions (snapshots) of that data on a SnapVault filer. The replicated data on the snapvault server system can be accessed via NFS or CIFS. The client systems can restore entire directories or single files directly from the snapvault filer.  Snapvault requires primary and secondary license.

How snapvault works?

When snapvault is setup, initially a complete copy of the data set is pulled across the network to the SnapVault filer. This initial or baseline, transfer may take some time to complete, because it is duplicating the entire source data set on the server – much like a level-zero backup to tape. Each subsequent backup transfers only the data blocks that has changed since the previous backup. When the initial full backup is performed, the SnapVault filer stores the data on a qtree and creates a snapshot image of the volume for the data that is to be backed up. SnapVault creates a new Snapshot copy with every transfer, and allows retention of a large number of copies according to a schedule configured by the backup administrator. Each copy consumes an amount of disk space proportional to the differences between it and the previous copy.

Snapvault commands :

Initial step to setup Snapvault backup between filers is to install snapvault license and enable snapvault on all the source and destination filers. 

Source filer – filer1

    filer1> license add XXXXX
    filer1> options snapvault.enable on
    filer1> options snapvault.access host=filer2

Destination filer – filer2

    filer2> license add XXXXX
    filer2> options snapvault.enable on
    filer2> options snapvault.access host=filer1

Consider filer2:/vol/snapvault_volume as the snapvault destination volume, where all backups are done. The source data is filer1:/vol/datasource/qtree1. As we have to manage all the backups on the destination filer (filer2) using snapvault – manually disable scheduled snapshots on the destination volumes. The snapshots will be managed by Snapvault. Disabling Netapp scheduled snapshots, with below command.

    filer2> snap sched snapvault_volume 0 0 0

Creating Initial backup: Initiate the initial baseline data transfer (the first full backup) of the data from source to destination before scheduling snapvault backups. On the destination filer execute the below commands to initiate the base-line transfer. The time taken to complete depends upon the size of data on the source qtree and the network bandwidth. Check “snapvault status” on source/destination filers for monitoring the base-line transfer progress.

    filer2> snapvault start -S filer1:/vol/datasource/qtree1  filer2:/vol/snapvault_volume/qtree1

Creating backup schedules: Once the initial base-line transfer is completed, snapvault schedules have to be created for incremental backups. The retention period of the backup depends on the schedule created. The snapshot name should be prefixed with “sv_”. The schedule is in the form of “[@][@]”.

On source filer:

For example, let us create the schedules on source as below - 2 hourly, 2 daily and 2 weekly snapvault . These snapshot copies on the source enables administrators to recover directly from source filer without accessing any copies on the destination. This enables more rapid restores. However, it is not necessary to retain a large number of copies on the primary; higher retention levels are configured on the secondary. The commands below shows how to create hourly, daily & weekly snapvault snapshots.

    filer1> snapvault snap sched datasource sv_hourly 2@0-22 
    filer1> snapvault snap sched datasource sv_daily  2@23
    filer1> snapvault snap sched datasource sv_weekly 2@21@sun

On snapvault filer:

Based on the retention period of the backups you need, the snapvault schedules on the destination should be done. Here, the sv_hourly schedule checks all source qtrees once per hour for a new snapshot copy called sv_hourly.0. If it finds such a copy, it updates the SnapVault qtrees with new data from the primary and then takes a Snapshot copy on the destination volume, called sv_hourly.0. If you don’t use the -x option, the secondary does not contact the primary and transfer the Snapshot copy. It just creates a snapshot copy of the destination volume.

    filer2> snapvault snap sched -x snapvault_volume sv_hourly 6@0-22
    filer2> snapvault snap sched -x snapvault_volume sv_daily  14@23@sun-fri
    filer2> snapvault snap sched -x snapvault_volume sv_weekly 6@23@sun

To check the snapvault status, use the command "snapvault status" either on source or destination filer. And to see the backups, do a "snap list" on the destination volume - that will give you all the backup copies, time of creation etc.

Restoring data : Restoring data is as simple as that, you have to mount the snapvault destination volume through NFS or CIFS and copy the required data from the backup snapshot.

You can also try Netapp Protection manager to manage the snapvault backups either from OSSV or from Netapp primary storage. Protection manager is based on Netapp Operations manager (aka Netapp DFM). It is a client based UI, with which you connect to the Ops Manager and protect your storages.

Linux Network bonding – setup guide


Linux network Bonding is creation of a single bonded interface by combining 2 or more Ethernet interfaces. This helps in high availability of your network interface and offers performance improvement. Bonding is same as port trunking or teaming.

Bonding allows you to aggregate multiple ports into a single group, effectively combining the bandwidth into a single connection. Bonding also allows you to create multi-gigabit pipes to transport traffic through the highest traffic areas of your network. For example, you can aggregate three megabits ports into a three-megabits trunk port. That is equivalent with having one interface with three megabytes speed

Steps for bonding in Oracle Enterprise Linux and Redhat Enterprise Linux are as follows..

Step 1.

Create the file ifcfg-bond0 with the IP address, netmask and gateway. Shown below is my test bonding config file.

$ cat /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
IPADDR=192.168.1.12
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
Step 2.
Modify eth0, eth1 and eth2 configuration as shown below. Comment out, or remove the ip address, netmask, gateway and hardware address from each one of these files, since settings should only come from the ifcfg-bond0 file above. Make sure you add the MASTER and SLAVE configuration in these files.

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
# Settings for Bond
MASTER=bond0
SLAVE=yes

$ cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=none 
ONBOOT=yes
USERCTL=no
# Settings for bonding
MASTER=bond0
SLAVE=yes

$ cat /etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

Step 3.
Set the parameters for bond0 bonding kernel module.. The modes are

  • mode=0 (Balance Round Robin)
  • mode=1 (Active backup)
  • mode=2 (Balance XOR)
  • mode=3 (Broadcast)
  • mode=4 (802.3ad)
  • mode=5 (Balance TLB)
  • mode=6 (Balance ALB)



Add the following lines to /etc/modprobe.conf
# bonding commands
alias bond0 bonding
options bond0 mode=1 miimon=100
Step 4.

Load the bond driver module from the command prompt.

$ modprobe bonding

Step 5.

Restart the network, or restart the computer.

$ service network restart # Or restart computer

When the machine boots up check the proc settings.

$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.0.2 (March 23, 2006)

Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:13:72:80: 62:f0

Look at ifconfig -a and check that your bond0 interface is active. You are done!. 

To verify whether the failover bonding works..



  • Do an ifdown eth0 and check /proc/net/bonding/bond0 and check the “Current Active slave”.
  • Do a continuous ping to the bond0 ipaddress from a different machine and do a ifdown the active interface. The ping should not break. 

Squid Cache proxy – a quick setup guide



This post gives the steps to quickly setup squid proxy and make it up and caching in minutes. There are also some tips & tricks on squid. My squid proxy server runs on OpenSuSE 11.1.
opensuse:~ # cat /etc/SuSE-release
openSUSE 11.1 (i586)
VERSION = 11.1 


opensuse:~ #
To download “squid” packages on opensuse, use zypper. The Zypper is a package/patch management tool in Suse, which works similar to yum.

opensuse:~ # zypper install squid3 squidGuard yast2-squid
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW packages are going to be installed:
  libboost_regex1_36_0 squid3 squidGuard yast2-squid

Check the installed Squid rpms.
opensuse:~ # rpm -qa | grep squid
squidGuard-1.3-57.63
squid3-3.0.STABLE10-2.11
yast2-squid-2.17.5-1.11
opensuse:~ #

The default squid configuration file is /etc/squid/squid.conf. The below configuration shows my setup, where I have changed the proxy port number & the cache directory. Make sure you have the cache directory created with the owner as squid.

opensuse:~ # grep -v ^# /etc/squid/squid.conf | grep -v ^$
acl manager proto cache_object
acl localhost src 127.0.0.1/32
<snip> http_port 8080 hierarchy_stoplist cgi-bin ? cache_dir ufs /home/cache/squid 200 16 256 access_log /var/log/squid/access.log squid
coredump_dir /var/cache/squid
opensuse:~ #

Start Squid service using the below command.

opensuse:~ # service squid start
Starting WWW-proxy squid                                         done
opensuse:~ #

Now set your client browsers to access internet thorough this proxy. (opensuse:8080)


To check the squid detailed cache information, you can use the command “squidclient”, as described below

opensuse:~ # squidclient -p 8080 cache_object://localhost/info
Squid Object Cache: Version 3.0.STABLE10

Connection information for squid:
        Number of clients accessing cache:      1
        Number of HTTP requests received:       0
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   -0.0
        Average ICP messages per minute since start:    -0.0
        Select loop called: 23738 times, -143987.578 ms avg
<snip>

opensuse:~ # squidclient -p 8080 cache_object://localhost/info | grep -A10 ^Cache

Cache information for squid:
        Hits as % of all requests:      5min: 0.0%, 60min: 0.0%
        Hits as % of bytes sent:        5min: -0.0%, 60min: -0.0%
        Memory hits as % of hit requests:       5min: 0.0%, 60min: 0.0%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.0%
        Storage Swap size:      6324 KB
        Storage Swap capacity:   3.1% used, 96.9% free
        Storage Mem size:       116 KB
        Storage Mem capacity:    1.4% used, 98.6% free
        Mean Object Size:       14.85 KB
        Requests given to unlinkd:      0
opensuse:~ #

Some more very useful squid tips at : http://sial.org/howto/squid/


Dynamically detecting new disks in Linux


When you have new LUNs created on the SAN fabric, zoned & mapped it to the server; how can you detect the luns on the linux server online, without rebooting it?.
When you dynamically add new disks to a Linux VM running on ESX server, how do you detect that disks on the Linux virtual machine?.
Here are the steps to do that :
  1. Install sg3_utils and lsscsi package.

    [root@fedora01 ~]# # yum install –y sg3_utils lsscsi
  2. The “lsscsi” command will list the disks attached to it. If you have just attached a disk, you will not be able to see it. You can also list this using “fdisk –l”

    [root@fedora01 ~]# lsscsi
    [0:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sda
    [root@fedora01 ~]#

    As you can see above, I currently have one disk connected to the system. To scan for a new device I just added, we should run rescan-scsi-bus.sh from the host.
  3. Run the command “/usr/bin/rescan-scsi-bus.sh” , to dynamically detect and activate the new disk.
  4. [root@fedora01 ~]# /usr/bin/rescan-scsi-bus.sh -l
    Host adapter 0 (mptspi) found.
    Scanning SCSI subsystem for new devices
    Scanning host 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
    Scanning for device 0 0 0 0 ...
    OLD: Host: scsi0 Channel: 00 Id: 00 Lun: 00
          Vendor: VMware   Model: Virtual disk   Rev: 1.0
          Type:   Direct-Access                  ANSI SCSI revision: 02
    Scanning for device 0 0 1 0 ...
    NEW: Host: scsi0 Channel: 00 Id: 01 Lun: 00
          Vendor: VMware   Model: Virtual disk   Rev: 1.0
          Type:   Direct-Access                  ANSI SCSI revision: 02
    1 new device(s) found.
    0 device(s) removed.
    [root@fedora01 ~]#

    [root@fedora01 ~]# lsscsi
    [0:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sda
    [0:0:1:0]    disk    VMware   Virtual disk     1.0   /dev/sdb
    [root@fedora01 ~]#

    You see the new disk is visible. Now you can create a partition or filesystem on it.

After running those commands, check dmesg and /var/log/messages to see if there are any device detections. You can also do "fdisk -l" or "cat /proc/scsi/scsi" to see the attached LUNs. This works fine in RHEL5, SuSE 10, CentOS5, OEL5.

RPM Commands


 If you want to find which rpm contains a specific file in your linux system, you can use "rpm -qf" to get the package information.

opensuse:~ # rpm -qf /etc/vmware-tools/tools.conf
open-vm-tools-2008.09.03-5.49
opensuse:~ #


Find out what all dependencies on an package?

opensuse:~ # rpm -qR libgcrypt11
rpmlib(VersionedDependencies) <= 3.0.3-1
/bin/sh
/bin/sh
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(CompressedFileNames) <= 3.0.4-1
libc.so.6
libc.so.6(GLIBC_2.0)
libc.so.6(GLIBC_2.1)
libc.so.6(GLIBC_2.1.3)
libc.so.6(GLIBC_2.3)
libc.so.6(GLIBC_2.3.4)
libc.so.6(GLIBC_2.4)
libgpg-error.so.0
rpmlib(PayloadIsLzma) <= 4.4.2-1
opensuse:~ #


How to list what all files are part of a package?

opensuse:~ # rpm -q --filesbypkg libgcrypt11-1.4.1-4.1
libgcrypt11               /lib/libgcrypt.so.11
libgcrypt11               /lib/libgcrypt.so.11.4.4
libgcrypt11               /usr/share/doc/packages/libgcrypt11
libgcrypt11               /usr/share/doc/packages/libgcrypt11/AUTHORS
libgcrypt11               /usr/share/doc/packages/libgcrypt11/COPYING
libgcrypt11               /usr/share/doc/packages/libgcrypt11/COPYING.LIB
libgcrypt11               /usr/share/doc/packages/libgcrypt11/ChangeLog
libgcrypt11               /usr/share/doc/packages/libgcrypt11/NEWS
libgcrypt11               /usr/share/doc/packages/libgcrypt11/README
libgcrypt11               /usr/share/doc/packages/libgcrypt11/THANKS
libgcrypt11               /usr/share/doc/packages/libgcrypt11/TODO
opensuse:~ #

Monday, 11 March 2013

Linux-Logical Volume Manager (LVM)


This is a quick and dirty cheat sheet on LVM using Linux, I have highlighted many of the common attributes for each command however this is not an extensive list, make sure you look up the command.
With the pvs, vgs and lvs commands, the number of verboses added the more verbose information for example pvs -vvvvv
Directory and Files
Directories and Files## 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
Tools
diagnosticlvmdump
lvmdump -d <dir>
dmsetup [info|ls|status]

Note: by default the lvmdump command creates a tar ball
Physical Volumes
displaypvdisplay -v
pvs -v
pvs -a
pvs --segments (see the disk segments used)

pvs attributes are: 
1. (a)llocatable
2. e(x)ported
scanningpvscan -v

Note: scans for disks for non-LVM and LVM disks
addingpvcreate /dev/sdb1

## Create physical volume with specific UUID, used to recover volume groups (see miscellaneous section)
pvcreate --uuid <UUID> /dev/sdb1

Common Attributes that you may want to use:

-M2 create a LVM2 physical volume
removingpvremove /dev/sdb1
checkingpvck -v /dev/sdb1

Note: check the consistency of the LVM metadata
change physical attributes## do not allow allocation of extents on this drive
pvchange -x n /dev/sdb1

Common Attributes that you may want to use:
--addtag add a tag
-x allowed to allocate extents
-u change the uuid
movingpvmove -v /dev/sdb2 /dev/sdb3

Note: moves any used extents from this volume to another volume, in readiness to remove that volume. However you cannot use this on mirrored volumes, you must convert back to non-mirror using "lvconvert -m 0"
Volume Groups
displayvgdisplay -v
vgs -v
vgs -a -o +devices

vgs flags:
#PV - number of physical devices
#LV - number of configured volumes   

vgs attributes are: 
1. permissions (r)|(w)
2. resi(z)eable
3. e(x)ported
4. (p)artial
5. allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited
6. (c)luster
scanningvgscan -v
creatingvgcreate VolData00 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgcreate VolData00 /dev/sdb[123]

## Use 32MB extent size
vgcreate VolData00 -s 32 /dev/sdb1

Common Attributes that you may want to use:

-l  maximum logical volumes
-p maximum physical volumes
-s physical extent size (default is 4MB)
-A autobackup 
extendingvgextend VolData00 /dev/sdb3
reducingvgreduce VolData00 /dev/sdb3

vgreduce --removemissing --force VolData00
removingvgremove VolData00

Common Attributes that you may want to use:

-f force the removal of any logical volumes
checkingvgck VolData00

Note: check the consistency of the LVM metadata
change volume attributesvgchange -a n VolData00

Common Attributes that you may want to use:

-a control availability of volumes within the group
-l  maximum logical volumes
-p maximum physical volumes
-s physical extent size (default is 4MB)
-x resizable yes or no (see VG status in vxdisplay) 
renamingvgrename VolData00 Data_Vol_01

note: the volume group must not have any active logical volumes
converting metadata typevgconvert -M2 VolData00

Note: vgconvert allows you to convert from one type of metadata format to another for example from LVM1 to LVM2
mergingvgmerge New_Vol_Group Old_Vol_Group

Note: the old volumes group will be merged into the new volume group
splitingvgsplit Old_Vol_Group New_Vol_Group [physical volumes] [-n logical volume name]
importingvgimport VolData00

Common Attributes that you may want to use:

-a import all exported volume groups
exporting## to see if a volume has already been export use "vgs" and look at the third attribute should be a x
vgexport VolData00

Common Attributes that you may want to use:

-a export all inactive volume groups
backing up## Backup to default location (/etc/lvm/backup)
vgcfgbackup VolData00

# Backup to specific location
vgcfgbackup -f /var/backup/VolData00_bkup VolData00

Note: the backup is written in plain text and are by default located in /etc/lvm/backup
restoringvgcfgrestore -f /var/backup/VolData00_bkup VolData00

Common Attributes that you may want to use:

-l list backups of file
-f backup file
-M metadataype 1 or 2
cloningvgimportclone /dev/sdb1

Note: used to import and rename duplicated volume group
special filesvgmknodes VolData00

Note: recreates volume group directory and logical volume special files in /dev
Logical Volumes
displaylvdisplay -v
lvdisplay --maps      display mirror volumes

lvs -v
lvs -a -o +devices

## lvs commands for mirror volumes
lvs -a -o +devices
lvs -a -o +seg_pe_ranges --segments

lvs attributes are: 
1. volume type: (m)irrored, (M)irrored without initail sync, (o)rigin, (p)vmove, (s)napshot, invalid (S)napshot, (v)irtual, mirror (i)mage
                      mirror (I)mage out-of-sync, under (c)onversion
2. permissions: (w)rite, (r)ead-only
3. allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited
4. fixed (m)inor
5. state: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid (S)uspended snapshot, mapped (d)evice present with-out tables,
             mapped device present with (i)nactive table
6. device (o)pen (mounted in other words)
scanninglvscan -v
lvmdiskscan
creating## plain old volume
lvcreate -L 10M VolData00

## plain old volume but with a specific name web01
lvcreate -L 10M -n web01 VolData00

## plain old volume but on a specific disk
lvcreate -L 10M VolData00 /dev/sdb1

## a striped volume called lvol1 (note the captial i for the stripe size)
lvcreate -i 3 -I 32 -L 24M -n lvol1 vg01
## Mirrored volume
lvcreate -L 10M -m1 -n data01 vg01

## Mirrored volume without a mirror log file
lvcreate -L 10M -m1 --mirrorlog core -n data01 vg01

Common Attributes that you may want to use:

-L size of the volume [kKmMgGtT]
-l number of extents
-C contiguous [y|n]
-i stripes
-I stripe size
-m mirrors
--mirrorlog
-n volume name
extendinglvextend -L 20M /dev/VolData00/vol01
Common Attributes that you may want to use:
-L size of the volume [kKmMgGtT]
-l number of extents
-C contiguous [y|n]
-i stripes
-I stripe size

Note: you can extend a ext2/ext3 filesystem using the "resize2fs" or "fsadm" command

fsadm resize /dev/VolData01/data01
resize2fs -p /dev/mapper/VolData01-data01 [size]

The -p option displays bars of progress while extendingthe filesystem
reducing/resizinglvreduce -L 5M /dev/VolData00/vol01
lvresize -L 5M /dev/VolData00/vol01

Note: rounding will occur when extending and reducing volumes to the next extent (4MB by default), you can use resize2fs or fsadm to shrink the filesystem
fsadm resize /dev/VolData01/data01 [size]
resize2fs -p /dev/mapper/VolData01-data01 [size]
removinglvremove /dev/VolData00/vol01
adding a mirror to a non-mirrored volumelvconvert -m1 --mirrorlog core /dev/VolData00/vol01 /dev/sdb2
change volume attributeslvchange -a n /dev/VolData00/vol01

Common Attributes that you may want to use:
-a availability
-C contiguous [y|n]
renaminglvrename /dev/VolData00/vol_old /dev/VolData00/vol_new
snapshottinglvcreate --size 100M --snapshot -name snap /dev/vg01/data01
Miscellaneous
Simulating a disk failuredd if=/dev/zero of=/dev/sdb2 count=10
reparing a failed mirror no LVM corruption## check volume, persume /dev/sdb2 has failed
lvs -a -o +devices

# remove the failed disk from the volume (if not already done so) , this will convert volume into a non-mirrored volume
vgreduce --removemissing --force VolData00

## replace the disk physically, remember to partion it with type 8e
fdisk /dev/sdb
........

## add new disk to LVM
pvcreate /dev/sdb2

## add the disk back into volume group
vgextend VolData00 /dev/sdb2

## mirror up the volume
lvconvert -m1 --mirrorlog core /dev/VolData00/vol02 /dev/sdb2
corrupt LVM metadata without replacing drive# attempt to bring the volume group online
vgchange -a y VolData00

# Restore the LVM configation
vgcfgrestore VolData00

# attempt to bring the volume grou online
vgchange -a y VolData00

# file system check
e2fsck /dev/VolData00/data01
corrupt LVM metadata but replacing the faulty disk# attempt to bring the volume group online but you get UUID conflict errors make note of the UUID number
vgchange -a y VolData00
vgchange -a n VolData00

## sometimes it my only be a logical volume problem
lvchange -a y /dev/VolData00/web02
lvchange -a n /dev/Voldata00/web02

## replace the disk physically, remember to partion it with type 8e
fdisk /dev/sdb
........

# after replacing the faulty drive the disk must have the previuos UUID number or you can get it from /etc/lvm directory
pvcreate --uuid <previous UUID number taken from above command> /dev/sdb2

# Restore the LVM configation
vgcfgrestore VolData00

# attempt to bring the volume group online or logical volume
vgchange -a y VolData00
lvchange -a y /dev/VolData00/web02

# file system check
e2fsck /dev/VolData00/data01
Note: if you have backed the volume group configuration you can obtain the UUID number in the backup file by default located in /etc/lvm/backup or running "pvs -v"

Courtesy by http://www.datadisk.co.uk