Using a Scipt to configure filesystems with Logical Volume Manager (LVM) under HP-UX


Scenario:  I have just created 15 luns on a san for use by HP-UX to create a new filesystem.  Now, I need to have those luns recognized by the operating system and to be made into a single filesystem.  Because there are 15 luns, it is likely I will have to repeat the same step 15 times.  To better utilize my time, and to eliminate mistakes, here are the steps required to script much of the process.

1.  Make the luns visible to the server as disk devices. 

The steps for this are:

2.  Verify that none of the luns are already being used

This should not be the case, but I am paranoid and this is a very easy to do sanity check.

Redirect the xpinfo -il command to a file and with vi save just the devices for the new luns - use awk '{print N$}' to print out just the device. Save the file (/tmp/wte_devices.txt).  The file should look something like this:

/tmp/wte_devices.txt:
/dev/rdsk/c5t0d1
/dev/rdsk/c5t9d0
/dev/rdsk/c5t9d1
/dev/rdsk/c5t9d2
/dev/rdsk/c5t0d2
/dev/rdsk/c5t1d7
/dev/rdsk/c5t2d0
/dev/rdsk/c5t2d1
/dev/rdsk/c5t3d0
/dev/rdsk/c5t3d6
/dev/rdsk/c5t8d3
/dev/rdsk/c5t8d4
/dev/rdsk/c5t8d5
/dev/rdsk/c5t8d6
/dev/rdsk/c5t8d7

For each device in the file check to see if there is an existing device in an existing volume group.  Use the command vgdisplay -v|grep <disk device>.  Here is the command line script to do this.

     for disk in `cat wte_devices.txt | sed 's/\/dev\/rdsk\///g'`
        do
        echo "Disk device /dev/rdsk/$disk:  "
        vgdisplay -v|grep $disk
        echo " "
        done

3.  Initialized the luns for use by LVM


First create the script to do this by issuing the following command:

cat wte_devices.txt | sed 's/\/dev/pvcreate -f \/dev/g' > wte_pvcreate.sh

This should result in a script that contains the following lines:

server: /tmp # cat wte_pvcreate.sh
pvcreate -f /dev/rdsk/c5t0d1
pvcreate -f /dev/rdsk/c5t9d0
pvcreate -f /dev/rdsk/c5t9d1
pvcreate -f /dev/rdsk/c5t9d2
pvcreate -f /dev/rdsk/c5t0d2
pvcreate -f /dev/rdsk/c5t1d7
pvcreate -f /dev/rdsk/c5t2d0
pvcreate -f /dev/rdsk/c5t2d1
pvcreate -f /dev/rdsk/c5t3d0
pvcreate -f /dev/rdsk/c5t3d6
pvcreate -f /dev/rdsk/c5t8d3
pvcreate -f /dev/rdsk/c5t8d4
pvcreate -f /dev/rdsk/c5t8d5
pvcreate -f /dev/rdsk/c5t8d6
pvcreate -f /dev/rdsk/c5t8d7

chmod +x and running the script:

server: /tmp # ./wte_pvcreate.sh
Physical volume "/dev/rdsk/c5t0d1" has been successfully created.
Physical volume "/dev/rdsk/c5t9d0" has been successfully created.
Physical volume "/dev/rdsk/c5t9d1" has been successfully created.
Physical volume "/dev/rdsk/c5t9d2" has been successfully created.
Physical volume "/dev/rdsk/c5t0d2" has been successfully created.
Physical volume "/dev/rdsk/c5t1d7" has been successfully created.
Physical volume "/dev/rdsk/c5t2d0" has been successfully created.
Physical volume "/dev/rdsk/c5t2d1" has been successfully created.
Physical volume "/dev/rdsk/c5t3d0" has been successfully created.
Physical volume "/dev/rdsk/c5t3d6" has been successfully created.
Physical volume "/dev/rdsk/c5t8d3" has been successfully created.
Physical volume "/dev/rdsk/c5t8d4" has been successfully created.
Physical volume "/dev/rdsk/c5t8d5" has been successfully created.
Physical volume "/dev/rdsk/c5t8d6" has been successfully created.
Physical volume "/dev/rdsk/c5t8d7" has been successfully created.

4.  Extend an existing volume group.

For this example I was able to extend an existing volume group - if this is not possible then a new volume group would have to be created.

vgextend /dev/vgdata11 /dev/dsk/diskid

server: /tmp # cp wte_pvcreate.sh wte_vgextend.sh
server: /tmp # chmod +x wte_vgextend.sh

using the vi substitution command, change the "pvcreate -f" to "vgextend /dev/vgdata11"  and change rdsk to dsk

%s/pvcreate -f/vgextend \/dev\/vgdata11/g

server: /tmp # cat wte_vgextend.sh
vgextend /dev/vgdata11 /dev/rdsk/c5t0d1
vgextend /dev/vgdata11 /dev/rdsk/c5t9d0
vgextend /dev/vgdata11 /dev/rdsk/c5t9d1
vgextend /dev/vgdata11 /dev/rdsk/c5t9d2
vgextend /dev/vgdata11 /dev/rdsk/c5t0d2
vgextend /dev/vgdata11 /dev/rdsk/c5t1d7
vgextend /dev/vgdata11 /dev/rdsk/c5t2d0
vgextend /dev/vgdata11 /dev/rdsk/c5t2d1
vgextend /dev/vgdata11 /dev/rdsk/c5t3d0
vgextend /dev/vgdata11 /dev/rdsk/c5t3d6
vgextend /dev/vgdata11 /dev/rdsk/c5t8d3
vgextend /dev/vgdata11 /dev/rdsk/c5t8d4
vgextend /dev/vgdata11 /dev/rdsk/c5t8d5
vgextend /dev/vgdata11 /dev/rdsk/c5t8d6
vgextend /dev/vgdata11 /dev/rdsk/c5t8d7

Run the script:

server: /tmp # ./wte_vgextend.sh
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf
Volume group "/dev/vgdata11" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf

5.  Create the logical volume

server: /tmp # lvcreate -L 100000 -n lvol_u20 /dev/vgdata11
Logical volume "/dev/vgdata11/lvol_u20" has been successfully created with
character device "/dev/vgdata11/rlvol_u20".
Logical volume "/dev/vgdata11/lvol_u20" has been successfully extended.
Volume Group configuration for /dev/vgdata11 has been saved in /etc/lvmconf/vgdata11.conf

6.  Make the new filesystem

server: /tmp # mkfs -F vxfs -o bsize=8192,largefiles /dev/vgdata11/lvol_u20
    version 3 layout
    102400000 sectors, 12800000 blocks of size 8192, log size 256 blocks
    unlimited inodes, 12800000 data blocks, 12799232 free data blocks
    391 allocation units of 32768 blocks, 32768 data blocks
    last allocation unit has 20480 data blocks
    first allocation unit starts at block 0
    overhead per allocation unit is 0 blocks

7.  Mount the new filesystem

Make the mountpoint:
server: /tmp # mkdir -p <mount point>
Edit /etc/fstab
/dev/vgdata11/lvol_u20 <mount point> vxfs rw,suid,largefiles,delaylog,datainlog 0 2
Mount the filesystem
server: /tmp # mount <mount point>
Change ownership of the filesystem
server: /tmp # chown oracle:dba <mount point>

8.  Verify the size and permissions

bdf <mount point>
ls -ld <mount point>