1826663 Members
2754 Online
109695 Solutions
New Discussion

Re: LVM Script

 
SOLVED
Go to solution
Siddhartha Sinha
Occasional Advisor

LVM Script

I have a unique situation. I am in a test environment and I need to test all the disks in a Server before I release. Now I am trying to create a file system using all the available disks (leaving any disks which are being used by any volume groups). To do this I wrote a simple script which run pvcreate on all unused disks and create a vg and then it should create the LV and run newfs and mount it. But it fails while trying to create the LV. Can anyone please help me. With many thanks. Here is the script attached.

Siddhartha
4 REPLIES 4
Robert-Jan Goossens
Honored Contributor

Re: LVM Script

Hi,

Could you attach the script?

Robert-Jan
Siddhartha Sinha
Occasional Advisor

Re: LVM Script

Sorry, I clicked the attachment but it didn't upload for some reason

I am pasting here. lvcreate is not taking the variable after -L $DISKSZ.

With thanks

Siddhartha

#!/usr/bin/sh
echo "Author - Siddhartha Sinha,"
echo " Here is the list of disks you have here!!"
ioscan -funCdisk|grep -i dsk |awk '{print $1}'|sort|tee total_disks
echo " This the disks used by different Volume Groups"
vgdisplay -v|grep -i dsk|awk '{print $3}'|sort|tee used_disks
echo "Now you are going to create a Volume Group named vg-test"
echo "Keep patience, it may take longer time depending on the amount"
echo "of the Disks you have in this System"
vgchange -a n /dev/vg-test
vgexport /dev/vg-test
comm -23 total_disks used_disks|sed -e s/dsk/rdsk/g|while read DISK
do
dd if=/dev/zero of=$DISK bs=4096 count=1000
pvcreate -f $DISK
done
rm -r /dev/vg-test
mkdir /dev/vg-test
mknod /dev/vg-test/group c 64 0x080000
comm -23 total_disks used_disks|sort|sed -e 's/^/vgextend \/dev\/vg\-test /' -e '1s/vgextend/vgcreate \-s 64 \-p 32 /'| tee free_disks
chmod +x free_disks
./free_disks
PE_SZ=`vgdisplay /dev/vg-test|egrep -i 'PE Size'|awk '{print $4}'`
TOT_PE=`vgdisplay /dev/vg-test|egrep -i 'Total PE'|awk '{print $3}'`
DISKSZ=`expr $PE_SZ \* $TOT_PE`
lvcreate -L $DISKSZ -l lv-test /dev/vg-test
newfs -F vxfs -o largefiles /dev/vg-test/rlv-test
mkdir /test
mount /dev/vg-test/lv-test /test
Siddhartha Sinha
Occasional Advisor

Re: LVM Script

I figured out. It was a typo in the script. Instead of -n I typed -l so it was failing and I didn't notice the message carefully. Thanks a lot
Dennis Handly
Acclaimed Contributor
Solution

Re: LVM Script

>lvcreate is not taking the variable after -L $DISKSZ.

What was the lvcreate error?

You might want to print out $DISKSZ, $PE_SZ and
$TOT_PE.

(Any reason you use egrep when just grep (or even fgrep) will do?)