Create a Linux LVM Volume

TuxThe title may be redundant but the information should still be helpful.

First Steps

First thing that you need to do is to determine what your existing /dev/sd devices you have.

 ls /dev/sd*
/dev/sda  /dev/sda1

In the step above we can see that we currently have two sd devices.

Then run the following script called forcelip.ksh, below is the contents of this script so that you can create it on your box.

#!/bin/ksh

# Force a LIP on all FC ports and scan for new devices.  Use with caution!
if [ -z "$*" ]
then
        HBALIST=`cd /sys/class/fc_host;ls`
else
        HBALIST="$*"
fi
cd /sys/class/fc_host
for HBA in $HBALIST
do
        echo "Sending LIP to $HBA..."
        echo "1" > $HBA/issue_lip
done
sleep 10
cd /sys/class/scsi_host
for HBA in $HBALIST
do
        echo "Scanning for SCSI devices on $HBA..."
        echo "- - -" > $HBA/scan
done

[root@host1 tmp]# ./forcelip.ksh
Sending LIP to host0…
Sending LIP to host1…
Scanning for SCSI devices on host0…
Scanning for SCSI devices on host1…

Then do the following

# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sdb

Now you see the new disk as /dev/sdb.
You may now proceede.

How to use LVM in Linux

Format the disk by using fdisk and label the partition Linux LVM (hex code 8e)

fdisk /dev/cciss/c0d1

or

fdisk /dev/sdb (as in the case above)

Run partprobe & vgscan to scan all disks for volume groups and rebuild caches

partprobe
vgscan

Initialize the disk or partition(s) for use with LVM

pvcreate /dev/cciss/c0d1p1

Create a volume group and include the new partition(s)

vgcreate mydg_dg /dev/cciss/c0d1p1

Create the logical volume(s) in the existing volume group (size 10 GB, name v1)

lvcreate -L 10G -n v1 mydg_dg

Or if you want to use the whole available space

lvcreate -l 100%FREE -n v1 mydg_dg

Build the Linux filesystem on the newly created logical volume(s) (file system type ext3)

mkfs -t ext3 /dev/mydg_dg/v1

Create the mount point directory

mkdir -p /my/mount/v1

Mount the filesystem

mount /dev/mydg_dg/v1 /my/mount/v1

Add the volume(s) information in /etc/fstab

Useful commands

To display attributes of volume groups:

vgdisplay

To display attributes of physical volumes

pvdisplay

To display attributes of logical volumes

lvdisplay
pvscan
ioscan -fnC disk

How to rename a Volume Group

Deactivate and active Logical Volumes in the VG that you want to rename
lvchange -an /dev/my_dg/v1


Then rename the VG
vgrename my_dg your_dg

Reactivate the new Logical Volume
lvchange -ay /dev/your_dg/v1



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.