Operating System - HP-UX
1829596 Members
1959 Online
109992 Solutions
New Discussion

Script to list all unused disks on the Server.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

Script to list all unused disks on the Server.

Hi All,

I am looking for a shell script which should generate a report of ONLY all unused disk attached on our HP-UX server.

We have more than 200 JBOD disk attached to the server, previously I was using SAM to get the list of all unused disks. But now I want a script to do the same.

Thanks in advance for your anticipated help.

Gulam.
Everyday Learning.
10 REPLIES 10
Muthukumar_5
Honored Contributor

Re: Script to list all unused disks on the Server.

Unused disks? Are you saying that disk which are attached to a machine and not used for work. That is with 0% usage?

We can get all file system usage informations with bdf or df -h.
Easy to suggest when don't know about the problem!
Gulam Mohiuddin
Regular Advisor

Re: Script to list all unused disks on the Server.

All disks which doesn't belongs to any Volume group or logical volumes or filesystem.

So that I can utilize those unused disks for creating more filesystes.

bdf will not show unused disks.

Thanks.

Gulam.
Everyday Learning.
Steven E. Protter
Exalted Contributor

Re: Script to list all unused disks on the Server.

Sam has a little feature to look at the commands that were used to generate the output.

Use sam to do the list one more time.

Then go to the menu and try these options:
options
view sam log

set it to commands only.

You will see the command which you can copy and paste into a script.

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Geoff Wild
Honored Contributor
Solution

Re: Script to list all unused disks on the Server.

#!/bin/sh

for i in `ioscan -funC disk |grep dsk |grep -v c0t0d0 |awk '{print $1}'`
do
DISK=`strings /etc/lvmtab |grep $i`
if [ "$DISK" = "" ]; then
echo "$i is not part of a volume group..."
fi
done


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rick Garland
Honored Contributor

Re: Script to list all unused disks on the Server.

There can be a few options here.

Do you want a comparison of what the ioscan -fnCdisk reports against the vgdisplay output?

What about disks that are used via VxVM?

Is MC/SG in the mix? If so then disks activated on one system will not be readily seen on the other system.

These are just a couple of avenues to pursue. Need to get more info about the environment.
harry d brown jr
Honored Contributor

Re: Script to list all unused disks on the Server.


Not knowing what disks belong to what is a serious issue for an administrator. If you have a database or some other application that is using raw disk drives, and that fact is not documented, then you have some serious potential to destroy those databases and or applications. I have seen this done time and time again by admins that didn't have a clue, couldn't read or didn't want to be bothered reading the system documentation and then went on to assign a disk drive to a file system when that disk drive was part of a database. OOPS - database is now toast!

Learn from others mistakes and keep concise documentation on your systems!

You can't write a script for this, you either know or don't know, and if you don't know, well then you had better learn.

Use things like print_manifest, vgdisplay -v, bdf, ioscan -fn, documentation from your DBA's, ...

live free or die
harry d brown jr

Live Free or Die
Geoff Wild
Honored Contributor

Re: Script to list all unused disks on the Server.

BTW - c0t0d0 is my cdrom...change as necessary...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Patrick Wallek
Honored Contributor

Re: Script to list all unused disks on the Server.

I've been trying to post this for the last hour.....

The below script will compare the output of 'ioscan -kfnC disk' and 'strings /etc/lvmtab' and output the disks that are not in lvmtab.


#!/usr/bin/sh

ioscan -kfnC disk | grep dsk | awk '{print $1}' > /var/tmp/disk.list

for DISK in $(cat /var/tmp/disk.list)
do
strings /etc/lvmtab | grep -q ${DISK}
if [[ $? != 0 ]] ; then
echo "Disk ${DISK} is not part of a VG"
fi
rm -f /var/tmp/disk.list
done
Senthil Kumar .A_1
Honored Contributor

Re: Script to list all unused disks on the Server.

Hi Gulam,

As others have observed, i too would join the general concensus that it would be hard to tell whether the disk would be really used or unused. Because there are applications that could use the device in raw format.

But, alas as far as LVM is concerned you could perform the following test...

ioscan -funC disk |grep dsk | awk '{print $1}' | while read x
do
pvdisplay $x 1> /dev/null 2> /dev/null
if [ $? -eq 0 ]
then
echo "$x USED"
else
echo "$x UNUSED"
fi
done

But, even if this tells you used...the sure way is to grep it in /etc/lvmtab, because..after removing a disk from a VG, many a time we might miss ysing pvremove on certain disk. so there is no hard and fast rule here either.

As far as wether the disk could be used by vxvm is concerned.. we need to eloborate the above test further...using "vxprivutil" or...

"strings -t d /dev/dsk/c0t1d0 | grep VMDB"

Like i said there is no hard and fast rule.. we need to dvelve further to make the script impeccable...


Hope this helped :)
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Doug O'Leary
Honored Contributor

Re: Script to list all unused disks on the Server.

Hey;

One more option. None of the prior inline scripts will identify alternate links that haven't been added to the volume groups - a bad situation to say the least. To find disks that are not part of the LVM you can run the following:

ioscan -funC disk | grep dsk | awk '{print $1}' | while read dsk
do
vgid=$(echo 0x2010?2X| adb ${dsk} | expand | tr -d " " | sed 's/2010://g')
[[ ${vgid} = "00" ]] && echo ${dsk}
done

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html