Skip to content

Instantly share code, notes, and snippets.

@bjornbouetsmith
Last active November 23, 2018 18:00
Show Gist options
  • Save bjornbouetsmith/81e64a625da17f5bce1819dc1e011344 to your computer and use it in GitHub Desktop.
Save bjornbouetsmith/81e64a625da17f5bce1819dc1e011344 to your computer and use it in GitHub Desktop.
Ubuntu update disk configuration via hdparm to disable power management to prevent sleep
#!/bin/sh
#Updates /etc/hdparm.conf to prevent spindown of disks
file=/etc/hdparm.conf
cmd=$1
add_disk()
{
echo "$1 {" >> $file
echo " apm = 255" >> $file
echo " spindown_time = 0" >> $file
echo "}" >> $file
}
set_disk()
{
hdparm -S 0 -B 255 $1
}
usage()
{
echo "$0"
echo " -set sets all ata drives to never sleep direcly via hdparm"
echo " -add adds all ata drives to the $file so hdparm will set values on next boot"
}
if [ "$#" -eq "0" ]
then
usage
exit
fi
for disk in `ls /dev/disk/by-id/ata*`
do
echo $disk | grep "\-part[0-9]" > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
if [ "$cmd" = "-set" ]; then
echo "Updating $disk"
set_disk $disk
else
echo "Adding $disk to $file"
add_disk $disk
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment