Discussion:
Script to Spin Down Disks
rachezor
2011-04-17 11:23:31 UTC
Permalink
I'm currently in the process of building a new all-in-one server based on ESXi 4.1 with a VM running Solaris 11 Express as the file server.

I've added the disk to the Solaris VM as raw device maps, and want the to spin down after a set period of time. I've tried to use the build power management option and have edited the power.conf file to no avail.

Sendning the spin down command work fine when issuing "sg_start -S /dev/rdsk/c*t*d0 using the sg3_utils tools.

After a lot of googling I found this script for linux:

The first step in getting this going is a simple bash script that checks /proc/diskstats for disk activity, and if there is no activity, it uses the sdparm command to spin down the drive. The script is as follows:

#!/bin/bash
DISKNAME=`ls -l /dev/disk/by-uuid/ | grep "<strong>46BA-C6C7</strong>" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__`
a=0
#check 100 times with 0.1s gaps,
#and go on adding
for i in `seq 0 100`
do
b=`cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }'`
a=`expr $a + $b`
sleep 0.1s
done
echo $a
if [ $a == 0 ]
then
echo "No Activity"
sdparm -C stop /dev/$DISKNAME
else
echo "Disk Active"
fi
exit 0

originating url: http://everydaylht.com/howtos/multimedia/spin-down-idle-usb-drives/

Unfortunatly I suck at developing scripts or code in general. My skills only reach as far as to modify existing scripts, mostly on a trail and error basis :-)

Could someone help me and the comunity with making an equivalent script for Solaris based on the sg_start command ?
--
This message posted from opensolaris.org
Andre Lue
2011-04-17 17:56:43 UTC
Permalink
Rac,

It's better to try and get the native solaris stuff working than trying to find the parallel for that script
esp these 2 things
cat /proc/diskstats
sdparm

see for tidbits to cross reference your power.conf and help
http://www.opensolaris.org/jive/thread.jspa?threadID=109809&tstart=0
http://www.mysysad.com/2008/06/configure-power-management-with.html
http://www.nexenta.org/boards/1/topics/105#message-108
--
This message posted from opensolaris.org
rachezor
2011-04-17 22:26:55 UTC
Permalink
After being hard at work on this issue most of the day,
I've managed to create a working script based on the one I linked in the OP.

Here's how it looks so far:

#!/bin/bash
a=0
#check for 45 minutes with 30s gaps, and go on adding.
for i in `seq 0 89`
do
b=`iostat -MCxn 30 2 |grep -w "c8" |sed '1d' |cut -c 60-61`
a=`expr $a + $b`
done
echo $a
if [ $a == 0 ]
then
echo "No Activity"
sg_start -S /dev/rdsk/c8t0d0
sg_start -S /dev/rdsk/c8t1d0
sg_start -S /dev/rdsk/c8t2d0
sg_start -S /dev/rdsk/c8t3d0
sg_start -S /dev/rdsk/c8t4d0
sg_start -S /dev/rdsk/c8t5d0
sg_start -S /dev/rdsk/c8t6d0
sg_start -S /dev/rdsk/c8t8d0
else
echo "Disk Active"
fi
exit 0


What it does is running a loop 90 times that lasts for 30 secs each, and sums the %b number from iostat (percent of time the disk is busy)
If the sum of %b during those 45 minutes is zero, then it spins down the disks.

I'll try and explain what the different commands used in the script does.

In -MCxn for iostat the "M" is to keep the output of iostat properly formated as the kr/s and kw/s column's will screw up the output when reading or writing to the array.
Using the "M" switch will present the data as MB/s and not KB/s, keeping the column's in place.
The "C" is to get the controllers listed in the output as to not rely on the %b stat from a single disk.
"x" is for getting extended disk statistics, must be used for the "C" switch to work and to get the %b statistic shown.
"n" is for disk names to display in the cXtYdZ format.
"30 2" makes iostat report I/O statistics twice with a 30 sec interval between the 1st and 2nd run.

The output of iostat is then piped to grep. "-w" makes grep look specifically for the controller name "c8".
The output of grep is then piped to sed. " '1d' " is used to delete the line from the first run of iostat, leaving the output of the 2nd run untouched.
(The first run of iostat shows accumulated statistics. It is useless info for use in this script, and is why iostat is asked to run twice, showing accumulated statistics for the last 30 secs only.)
The output of sed is then piped to cut to remove everything else but the %b column data with the "-c 60-61" switch.
It tells cut to remove all characters before and after character 60.

Now b is defined and can be added to a using expr.
The loop is done and runs again until it has done so 90 times.
It is then determined if the disks on the c8 controller was active during the last 45 minutes or not.
If not then sg_start command, from the sg3_utils tools (SUNWsg3utils), is used to spin down the disks on controller c8 using the "-S" switch.

The plan is to run the script via cron, but it would be much better if it could be made to run permantly at bootup and be using a rolling 45 minutes,
as to always spin down the disks when they've been idle for exact 45 minutes or whatever interval you'd like.
Ideas are most certainly welcome :-)
--
This message posted from opensolaris.org
Loading...