Friday, 11 July 2008

get_vgids

This script will get the VGID for the named volume group and it's PDs

#!/usr/bin/ksh

# find all the disks presented to the system that have the VGID of the named
# volume groups.
# This is helpful when you present the BCVs for a devicegroup that has
# a number of volume groups on it.

[[ $# -lt 1 ]] && echo "[FATAL]Must give one or more volume groups" && exit 1
[[ $(uname -s) != 'HP-UX' ]] && echo "[FATAL]Only works on Solaris" && exit 1

# get VGIDs from lvmtab
typeset _volume_groups="$@"
typeset _volume_group
typeset _offset
typeset _vg_path
typeset _vgid
typeset _vgid1
typeset _vgid2
typeset _disk
typeset _disk_vgid

# find the VGID of the volumes.
for _volume_group in $_volume_groups
do
_volume_group=$(basename $_volume_group)
strings -t d /etc/lvmtab | grep $_volume_group | read _offset _vg_path
if [[ -n "$_offset" && -n "$_vg_path" ]]; then
xd -An -j$(($_offset+1024)) -N8 -tuL /etc/lvmtab | grep -vE '^$'| read _vgid1 _vgid2
_vgid="${_vgid1}-${_vgid2}"
print $_vg_path $_vgid
# get VGIDs from PV
for _disk in /dev/rdsk/*
do
_size=$(diskinfo -b $_disk 2> /dev/null)
if [[ $_size -gt 0 ]]; then
_disk_vgid=$(xd -An -j8208 -N8 -tuL $_disk | awk '/[0-9]/ {print $1 "-" $2}')
if [[ "$_disk_vgid" = "$_vgid" ]]; then
print $_vg_path $_disk $_disk_vgid
fi
fi
done
else
print "[FATAL]Can't find $_volume_group in /etc/lvmtab"
fi
done

to add CPU and memory to a vpar


# Unix - Shutdown vpar the target vpar
shutdown -r -o now

# on another vpar in the complex
vparstatus > /var/tmp/vparstatus

# Unix - change cpu's from 4 to 5
vparmodify -p $target_vpar -m cpu::5

# Unix - Change physical memory from 12288 to 16384
vparmodify -p $target_vpar -m mem::16384

# Unix - startup vpar
vparboot -p $target_vpar

# back on $target_vpar
# Unix - check cpu is active and memory is there
# sam->Performance Monitors-> System Properties

lock / unlock account user id on HP-UX trusted system


# lock / unlock account user id on HP-UX trusted system
/usr/lbin/getprpw useraccount

# unlock / enable / reactivate:
/usr/lbin/modprpw -k useraccount

# lock / expire password:
/usr/lbin/modprpw -e useraccount

# Do not use a capital E, as it will expire the password on all user accounts.

to create a tape depot (as a file) from a real depot

Must be run locally to on the depot server

swpackage -d /tmp/SG_A.11.15.00.depot -x target_type=tape -s /tmp/Rel_11.15 B3935DA B7609BA B8324BA

show the current npar


# show the current npar

root@HP-cell_machine:/ # parstatus -w
The local partition number is 2.

# show info about that npa
root@HP-cell_machine:/ # parstatus -Vp 2
[Partition]
Partition Number : 2
Partition Name : Partition 2
Status : Active
IP Address :
Primary Boot Path : 5/0/1/1/0/4/0.10
Alternate Boot Path : 7/0/1/1/0/4/0.8.0
HA Alternate Boot Path : 0/0/0/0/0/0/0/0.0
PDC Revision : 22.3
IODCH Version : 88c0
Cell Architecture : PA-RISC
CPU Compatibility : 35008-PA
CPU Speed : 1100 MHz
Core Cell : cab0,cell5
Core Cell Choice [0] : cab0,cell5
Core Cell Choice [1] : cab0,cell7
Total Good Memory Size : 40.0 GB
Total Interleave Memory: 40.0 GB
Total Requested CLM : 0.0 GB
Total Allocated CLM : 0.0 GB

Export/Import a volume group


vgdisplay -v > /tmp/vgdisplay.backup
cp -p /etc/mnttab /tmp/mnttab.backup

umount /oraback
umount /oraarch
umount /opt/application
umount /oradb02
umount /oradb01

# export
vgexport -m /etc/lvmconf/vg02.map -p /dev/vg02
vgchange -a n /dev/vg02
vgexport -m /etc/lvmconf/vg02.map -s /dev/vg02


# import
mkdir /dev/vg02
mknod /dev/vg02/group c 64 0x020000
#vgimport -m /etc/lvmconf/vg02.map -s /dev/vg02
#vgimport -m /etc/lvmconf/vg02.map /dev/vg02 /dev/dsk/c13t4d3 /dev/dsk/c16t4d4 /dev/dsk/c13t4d5 /dev/dsk/c18t0d0 /dev/dsk/c16t4d3 /dev/dsk/c13t4d4 /dev/dsk/c16t4d5 /dev/dsk/c19t0d0
vgchange -a y /dev/vg02

mount /oraback
mount /oraarch
mount /opt/application
mount /oradb02
mount /oradb01

Some sample LVM commands


#backup the config of a volume group
vgcfgbackup -f /tmp/vg02.backup vg02

# save vg configuration in human readable format
vgdisplay -v vg02 > /tmp/vg02.config

# extend VG onto new disk and in this case, it's alternate path
vgextend /dev/vg02 /dev/dsk/c18t0d0 /dev/dsk/c17t0d0

# extend a logical volume to be 301120MB long
lvextend -L 301120 /dev/vg02/lvol1

# extend the (umounted) filesystem
extendfs -F vxfs /dev/vg02/lvol1

## remove the disks. restore original size
# destroy the lv. pvmove might allow you to move from one PV to another and not have to do this
lvremove /dev/vg10/lvol1

# pull the released PVs out of the VG
vgreduce /dev/vg10 /dev/dsk/c18t10d4 /dev/dsk/c17t10d4

# recreate the LV
lvcreate -L 117760 -n lvol1 vg010

# recreate it's filesystem
newfs -F vxfs -o largefiles /dev/vg10/rlvol1

##### to import disks that have been created as BCVs (/dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1 /dev/rdsk/c0t0d2)
# create the BCV (clone, split)
# change the VGIDs on the disks so that they can be imported
vgchgid /dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1 /dev/rdsk/c0t0d2
# make a new volume group by hand
mkdir /dev/vgbcv
mknod /dev/vgbcv/group c 64 0x040000
# import the pvs into it.
vgimport /dev/vgbcv /dev/dsk/c0t0d0 /dev/dsk/c0t0d1 /dev/dsk/c0t0d2
# Activate the VGs
vgchange -a y /dev/vgbcv
# backup the config
vgcfgbackup /dev/vgbcv
# mount and use
mkdir /bcv/lvol1 /bcv/lvol2
mount /dev/vgbcv/lvol1 /bcv/lvol1
mount /dev/vgbcv/lvol2 /bcv/lvol2


##########
# /etc/lvmrc contains defalts for LV
# like AUTO_VG_ACTIVATE=1 etc.
# it's sourced by /sbin/lvmrc during boot.


##########
# from ITRC
#a cross-device link error is typically issued if the PVID on disk does not match the one stored in lvmtab. A corrupted or wiped-out LVM header may be also a potential reson.
#
# Run this to see the VGIDs in lvmtab:
strings -t d /etc/lvmtab |grep /dev |grep -v /dev/dsk | while read offset path; do
xd -An -j$(($offset+1024)) -N8 -tuL /etc/lvmtab | read vgid1 vgid2
echo $path $vgid1-$vgid2
done | sort -n
# Run this to see a VGID on a given disk:
xd -An -j8208 -N8 -tuL /dev/dsk/cXtYdZ
##########

## vgcfgrestore for vg02 from multiple disks, from ITRC
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t8d0
Volume Group configuration has been restored to /dev/rdsk/c3t8d0
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t9d0
Volume Group configuration has been restored to /dev/rdsk/c3t9d0
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t10d0
Volume Group configuration has been restored to /dev/rdsk/c3t10d0
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t11d0
Volume Group configuration has been restored to /dev/rdsk/c3t11d0
## then this to get the LVs back?
vgexport /dev/vg02
vgscan -av
# and (might need to name the disks in the vgimport, might not.)
vgimport /dev/vg02