Tuesday, February 24, 2015

Create filesystem using LVM on Redhat 6

aigsun15% cat LVM_SYBASE
# File_name: LVM_SYBASE
# Sam; Only for personal use
# This is a config file for sybase FS.
# mPoint        Size (GB)       vg              LV
#-------------------------------------------------------
#/web           10              datavg          WEB
#/webdata       15              datavg          WEBDATA
#
# system: scsi-(0:1)  Total (GB):- 36
/opt/sybase     15              system          OPT_SYBASE
/opt/foglight   10              system          OPT_FOGLIGHT
/opt/gaurdium   10              system          OPT_GUARDIUM
#
# sybdata scsi-(1:0)  Total (GB):- 176
/data/sybdata   175             sybdata         DATA_SYBDATA
#
# syblog scsi-(2:0)   Total (GB):- 71
/data/syblog    70              syblog          DATA_SYBLOG
#
# sybtemp scsi-(3:0)  Total (GB):- 156
/data/sybtemp   25              sybtemp         DATA_SYBTEMP
/data/sybdump   130             sybtemp         DATA_SYBDUMP
#
# sybserver: scsi-(3:1) Total (GB):- 36
/data/sybase    10              sybserver       DATA_SYBASE
/data/sybserver 25              sybserver       DATA_SYBSERVER
aigsun15% ls -l
total 14
-rw-r--r--   1 sam   sysadmin     1068 Aug 20 16:13 LVM_SYBASE
-rw-r--r--   1 sam   sysadmin      492 Aug 20 16:15 LVM_WEBLOGIC
-rw-r--r--   1 sam   sysadmin     2680 Aug 20 16:55 lvm_create_fs_SB.sh
-rw-r--r--   1 sam   sysadmin     1924 Aug 20 16:18 lvm_create_fs_WL.sh
aigsun15% cat lvm_create_fs_SB.sh
#!/bin/sh
# Sam; Only for personal use
# Automate FS creation task. This script tested and verified on Redhat Enterprise 6.x version.
# Mon Feb 24 12:13:24 EST 2014
# Update: Thu Aug 14 09:55:12 EDT 2014
# 1. Added the entry for mount point on config file.
# 2. Added entry to the fstab.
# 3. Ownership Change
#
# Config file entry eg.
# # File_name: LVM_SYBASE
# # For SYBASE Server
# Note: Please understand the config file LVM_SYBASE before running this script.
# echo "- - -" > /sys/class/scsi_host/host[0-3]/scan
# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
# vgextend system /dev/sdb1
# vgcreate sybdata /dev/sdc1
# vgcreate syblog /dev/sdd1
# vgcreate sybtemp /dev/sde1
# vgcreate sybserver /dev/sdf1
#
# This is a config file for sybase FS.
# mPoint        Size (GB)       vg              LV
#-------------------------------------------------------
#/web           10              datavg          WEB
#/webdata       15              datavg          WEBDATA
#
if [ `/usr/bin/whoami` != "root" ]
then
        echo "You must be root to run this script"
        exit 1
fi
# Creating LVM.
echo "###########################################################################" >>/etc/fstab
/bin/cat LVM_SYBASE | grep -v "^#" | while read mymt mysize myvg myfs
do
        echo " "
        # Check if mount point already exists.
        #/bin/df -h ${mymt}
        /bin/ls -ld ${mymt}
        if [ $? -eq 0 ]; then
                echo "Mount Point exists."
                echo "Please review the config file."
                exit 1
        fi
        /sbin/lvcreate -L ${mysize}G -n ${myfs} ${myvg}
        /sbin/mkfs.ext4 /dev/${myvg}/${myfs}
        # Create mount point
        /bin/mkdir -p ${mymt}
        # Add Entry to fstab
#       echo "###########################################################################" >>/etc/fstab
        echo "/dev/${myvg}/${myfs}      ${mymt} ext4    defaults        1 2" >>/etc/fstab
        # Mount the filesystem.
        /bin/mount -a
        # Verify if the filesystems were created.
        /bin/df -hP      ${mymt}
        # Check the condition if the process is successful.
        if [ $? -eq 0 ]; then
                echo "Successfully Created fileystem."
                continue
        else
                echo "Failed, please review the error"
                # exit
        fi
        # Change the ownership
        /bin/chown sybase:users /data/syb*
        /bin/chown sybase:users /opt/sybase
        /bin/chown qstinsp:qstcinsg /opt/foglight
echo " ----------------end----------------"
done
# Backout Plan
# List your LVMs
# lvscan
# lvremove /dev/${myvg}/${myfs}
# vgdestroy datavg
aigsun15% ls -l
total 14
-rw-r--r--   1 sam   sysadmin     1068 Aug 20 16:13 LVM_SYBASE
-rw-r--r--   1 sam   sysadmin      492 Aug 20 16:15 LVM_WEBLOGIC
-rw-r--r--   1 sam   sysadmin     2680 Aug 20 16:55 lvm_create_fs_SB.sh
-rw-r--r--   1 sam   sysadmin     1924 Aug 20 16:18 lvm_create_fs_WL.sh

aigsun15% cat LVM_WEBLOGIC
# File_name: LVM_WEBLOGIC
# Script Name: lvm_create_WL.sh
# Sam; Only for personal use
# For Weblogic
# vg    FS      Size(GB)  mPoint
#--------------------------------
#datavg WEB     10      /web
#datavg WEBDATA 15      /webdata
#
datavg  PKGS            20      /pkgs
datavg  CLOUD             10      /cloud
datavg  CLOUD_DOCROOT     10      /cloud/docroot
datavg  CLOUD_SERVERS     10      /cloud/servers
datavg  DATA_TEST       10      /data/test
datavg  DATADATA        10      /datadata
aigsun15% ls -l
total 14
-rw-r--r--   1 sam   sysadmin     1068 Aug 20 16:13 LVM_SYBASE
-rw-r--r--   1 sam   sysadmin      492 Aug 20 16:15 LVM_WEBLOGIC
-rw-r--r--   1 sam   sysadmin     2680 Aug 20 16:55 lvm_create_fs_SB.sh
-rw-r--r--   1 sam   sysadmin     1924 Aug 20 16:18 lvm_create_fs_WL.sh

aigsun15% cat lvm_create_fs_WL.sh
#!/bin/sh
# Sam; Only for personal use
# Automate FS creation task. This script tested and verified on Redhat Enterprise 6.x version.
# Config file entry eg.
# # Config File Name: LVM_WEBLOGIC
# # For Weblogic
# # vg    FS      Size(GB) Mnt point
# --------------------------------
# datavg  WEB     10     /web
# datavg  WEBDATA 15     /webdata
#
# Mon Feb 24 12:13:24 EST 2014
# Update: Thu Aug 14 09:55:12 EDT 2014
# Added the entry for mount point on config file.
# Added entry to the fstab.
#
if [ `/usr/bin/whoami` != "root" ]
then
        echo "You must be root to run this script"
        exit 1
fi
# Creating LVM.
echo "###########################################################################" >>/etc/fstab
/bin/cat LVM_WEBLOGIC | grep -v "^#" | while read myvg myfs mysize mymt
do
        echo " "
        # Check if mount point already exists.
        #/bin/df -h ${mymt}
        /bin/ls -ld ${mymt}
        if [ $? -eq 0 ]; then
                echo "Mount Point exists."
                echo "Please review the config file."
                exit 1
        fi
        /sbin/lvcreate -L ${mysize}G -n ${myfs} ${myvg}
        /sbin/mkfs.ext4 /dev/${myvg}/${myfs}
        # Create mount point
        /bin/mkdir -p ${mymt}
        # Add Entry to fstab
        echo "/dev/${myvg}/${myfs}      ${mymt} ext4    defaults        1 2" >>/etc/fstab
        # Mount the filesystem.
        /bin/mount -a
        # Verify if the filesystems were created.
        /bin/df -h      ${mymt}
        # Check the condition if the process is successful.
        if [ $? -eq 0 ]; then
                echo "Successfully Created fileystem."
                continue
        else
                echo "Failed, please review the error"
                # exit
        fi
echo " ----------------end----------------"
done
# Backout Plan
# List your LVMs
# lvscan
# lvremove /dev/${myvg}/${myfs}
# vgdestroy datavg
aigsun15%

No comments:

Post a Comment