Operating System - HP-UX
1833995 Members
3932 Online
110063 Solutions
New Discussion

script to find the unused disk

 
ashan-HPUX
Occasional Contributor

script to find the unused disk

Hi ,

Any has a script to find the unuse disk in system.

Thx!
Ashan

3 REPLIES 3
RAC_1
Honored Contributor

Re: script to find the unused disk

No script with me, but following code should
do it.

for i in $(ls -1 /dev/dsk/)
do
pvdisplay /dev/dsk/${i}
vg_name=$(pvdisplay /dev/dsk/${i}|awk '/VG Name/ {print $NF}')
stat=$?
if [ ${stat} -eq 0 ];then
echo "/dev/dsk/${i} - ${vg_name}"
else
echo "/dev/dsk/${i} not used"
fi

This will not take care, if a disk is used as raw device. Only apps can tell about it then.
There is no substitute to HARDWORK
Ninad_1
Honored Contributor

Re: script to find the unused disk

Hi,

You can also use SAM to check unused disks

sam -> disks and filesystems -> disks and devices .
Then save to file from the options.

But mind you as mentioned above if a disk is directly used - as raw disk without configuring into LVM then it wont be known to SAM.
Also from the disks in the Volume groups already configured there may be free space in the VGs. Youcan find it as below
vgdisplay | egrep -i 'VG Name|PE Size|Free PE' | awk 'BEGIN {print "VGname Free_space(MB)"} {a=$NF;getline;b=$NF;getline;c=$NF;print a,b*c}'


Regards,
Ninad
Bill Hassell
Honored Contributor

Re: script to find the unused disk

You can use SAM to locate disks which are not currently bound into a volume group (disks/filesystems -> volume groups -> Action tab -> create -> make up a temporary name -> select disks.

SAM will search through all the volume groups, then report on the disks that are not in any volume groups.

However, you need to know if special applications are using raw disks without the volume manager. Databases such as Informix and Sybase commonly use raw disks although the majority use the volume manager (like LVM) to partition the actual space. But only the applicaiton knows about these disks.

Still another solution is to download the Xvg utility (requires an Xwindow display) to map all the disks and volumes). Unused disks, lvols and space are glagged graphically.


So a scripted approach is somewhat difficult because there is no way to identify truly unused disks and raw disks actively used by applications. If you have inherited systems with very poor documentation, the are a couple of manual methods you can use. The first is to download/install lsof and run it on each of the disk device files. If the device file is open, it is currently in use. Of course, an application may only intermittently use the file. The other method is brute force: rename the raw disk device file and see if anything complains after after a couple of days...


Bill Hassell, sysadmin