My Server Installation - A Work In Progress

Discussion and Technical Support for general software applications and utilities including OS related issues.
Post Reply
Beeblebear
Member
Member
Posts: 8
Joined: July 31st, 2012, 9:55 pm

My Server Installation - A Work In Progress

Post by Beeblebear »

Hi, all!

As I mentioned in my previous posts, I have been taking notes to help me in my repeated re-installs of my system, over the course of the last several months and have lately based much of it upon the foundation provided by this site.

At the moment, all of it works, except for my HDD temperature script, mentioned in my previous post, so I'll just 'dump' my installation process it in it's current, raw form, so that people can scan through it to see if there is anything useful and applicable to them in it's content.

Please let me know if it is of any help to you and please ask any questions that it may raise for you.

I intend to update and clarify it all over time, but time is something which I have in pretty short supply at the moment, so if anyone has any suggestions or improvements, please let me know...

--------------------------------------------------------------

Server Install:

Install Ubuntu Server 12.04 and select SSH Server and Samba Server from the tasksel prompt.

--------------------------------------------------------------

Server Configuration:

Preliminaries:

Code: Select all

sudo apt-get update
sudo aptitude safe-upgrade
lsb_release -a
---------------------------------------------------------------

Install Graphical Desktop and VNC Server:

http://ubuntuforums.org/showthread.php?t=1925948
http://complete-concrete-concise.com/
http://complete-concrete-concise.com/ub ... tall-a-gui
http://kmandla.wordpress.com/2010/03/22 ... in-ubuntu/
http://kmandla.wordpress.com/2010/03/22 ... in-ubuntu/
http://kmandla.wordpress.com/2010/03/19 ... e-on-arch/
http://www.szewong.com/2009/06/setting- ... slicehost/

GNOME-CORE

Code: Select all

sudo apt-get install gnome-core
sudo apt-get install vnc4server
vncserver
vncserver -kill :1
vim .vnc/xstartup

Code: Select all

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
:wq

Code: Select all

sudo vim /etc/init/gdm.conf

Code: Select all

# gdm - GNOME Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services

description "GNOME Display Manager"
author "William Jon McCann <mccann@jhu.edu>"

#start on ((filesystem
# and runlevel [!06]
# and started dbus
# and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
# or stopped udev-fallback-graphics))
# or runlevel PREVLEVEL=S)

stop on runlevel [016]

emits login-session-start

...
:wq

XFCE

Code: Select all

 sudo apt-get install xfce4 lightdm-gtk-greeter
sudo apt-get install vnc4server
vncserver
vncserver -kill :1
vim .vnc/xstartup

Code: Select all

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
startxfce4

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
:wq

Code: Select all

sudo vim /etc/init/lightdm.conf

Code: Select all

# LightDM - light Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services
#
# based on gdm upstart script

description     "LightDM Display Manager"
author          "Robert Ancell <robert.ancell@canonical.com>"

#start on ((filesystem
#           and runlevel [!06]
#           and started dbus
#           and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
#                or stopped udev-fallback-graphics))
#          or runlevel PREVLEVEL=S)

stop on runlevel [016]

emits login-session-start


...
:wq

Code: Select all

cd /home/server
mkdir Scripts
cd Scripts
vim StartVNC.sh

Code: Select all

#!/bin/sh
echo "JOB RUN AT $(date)"
echo "========================================"
echo ""
echo "Starting VNC Server..."
echo ""
echo "========================================"
echo ""
/usr/bin/vncserver -geometry 1280x800
:wq

Code: Select all

chmod a+x StartVNC.sh
./StartVNC.sh
-----------------------------------------------------------------

Useful Stuff:

GNOME-CORE:

Code: Select all

sudo apt-get install gedit
sudo apt-get install molly-guard
sudo apt-get install gparted
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
XFCE:

Code: Select all

sudo apt-get install mousepad
sudo apt-get install molly-guard
sudo apt-get install gparted
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
sudo apt-get install synaptic
From within your VNC session, launch gparted with:

Programs -> Terminal:

Code: Select all

sudo gparted
and set up any drives which need it, there.

--------------------------------------------------------------

Install Webmin:

http://www.havetheknowhow.com/Configure ... ebmin.html
http://www.havetheknowhow.com/Configure ... -boot.html

Code: Select all

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.590_all.deb
sudo apt-get update
sudo apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl libapt-pkg-perl apt-show-versions
sudo dpkg -i webmin_1.590_all.deb
sudo apt-get install -f
sudo /usr/share/webmin/changepass.pl /etc/webmin root YourNewPassword
rm webmin_1.590_all.deb
https://localhost:10000/
https://server:10000/

--------------------------------------------------------------

Partition Drives In Ubuntu Server Using Webmin:

http://www.havetheknowhow.com/Configure ... rives.html
https://Server:10000/

In Webmin:

Hardware -> Logical Volume Management

Logical Volumes

Create a logical volume in Server

Volume name: System

Leave the Absolute size as is and click the Create button.

Click on the new volume you just created and ensure the drop-down says New Linux Native (ext4) and click the Create file system of type: button. Leave everything as the default and click the Create button. This should take a while to run through and when it's finished you'll have a shiny new empty partition.

--------------------------------------------------------------

Mounting partitions at startup:

In Webmin:

System -> Disk and Network Filesystems

Type: New Linux Native Filesystem (ext4)

Add mount

Click the button next to Mounted As and then double-click on the media folder (some people use the mnt folder. either one will do).

Then in the edit box at the bottom, which currently reads "/media" (or "/mnt") add another slash and then give the mount point a name e.g. UserData. The final string should read something along the lines of "/media/UserData".

"/media/System"

Click the OK button.

Then in the Linux Native Filesystem or Linux Native Filesystem section (depending on your choice earlier) ensure the LVM logical volume option is checked and select the new Logical Volume you've just created (LV UserData).

LVM logical volume: LVM VG Server, LV Storage

Avoid updating last access times? No

Leave all other options as is and click the Create button. You now have the rest of your drive ready for use.

For the rest of the drives, which are not part of a readily identifiable, logical group, I would recommend identifying your drives by their unique ID rather than simply using /dev/hd*# or /dev/sd*#. This is because device assignments can change between system boots. I actually had this happen to me when I left a bootable USB rescue drive plugged in. On the next boot, it took over the sda label and pushed the rest of my storage drives on, up the alphabet. This caused me some concern before I realised what had happened.

https://help.ubuntu.com/community/UsingUUID

In terminal:

Code: Select all

ls -l /dev/disk/by-id

Code: Select all

total 0
llrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-MATSHITABD-MLT_UJ240AS_WJ42_003694 -> ../../sr0
lrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-name-Server-root -> ../../dm-0
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-name-Server-swap_1 -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-name-Server-System -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdb9h3Rs23fJ2io8zxPjbpedP4eUrC3OVw -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdG5s3dBd4rFdt34hdJoyhJxB5oCw7l6RI -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdVJQezcxe7NQVplQeVfQFMlqY4dAwq73D -> ../../dm-0
lrwxrwxrwx 1 root root  9 Aug  1 09:13 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 09:13 wwn-0x5000cca22bc063f2 -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5000cca22bc063f2-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 wwn-0x5002538043584d30 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5002538043584d30-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5002538043584d30-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5002538043584d30-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 09:13 wwn-0x5e83a97edd3455aa -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5e83a97edd3455aa-part1 -> ../../sdc1
In Webmin:

System -> Disk and Network Filesystems

Type: New Linux Native Filesystem (ext4)

Add mount

Mounted as: "/media/Recordings"

OK

Choose: Other device; /dev/disk/by-id/scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1
Avoid updating last access times? No

Create

System -> Disk and Network Filesystems

Type: New Linux Native Filesystem (ext4)

Add mount

Mounted as: "/media/4TB_Storage"

OK

Choose: Other device; /dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ-part1

Avoid updating last access times? Yes

Create

To ensure that the server's storage drives are fully available for use where they are needed, we need to check the available permissions for each of these and alter them as necessary. The most straight-forward and easily understandable way of doing this is to log into a VNC session, open a terminal window and launch the file browser as root.

Code: Select all

sudo nautilus
Your drives will be listed on the left-hand pane under 'Computer' and if they are already mounted (which they should be if they were set up to do so in Webmin), they will show an 'eject' symbol next to them.

Just right-click on each of the drives' icons in turn, click Properties -> Permissions tab and set ownership and access rights to Create and delete files where necessary. I found this step necessary as Webmin seemed to create the auto-mounts under root authority and did not necessarily allow full read-write access to user accounts. You will need to check and alter these permissions if neccessary, to allow access to other users.

--------------------------------------------------------------

Hardware Sensors:

Code: Select all

sudo apt-get install lm-sensors
sudo -s
sensors-detect
service module-init-tools start
sensors
--------------------------------------------------------------

CPU:

Following the instructions on http://www.havetheknowhow.com/Configure ... tures.html
I took the script kindly provided there and modified it for my own purpouses.

Code: Select all

 cd Scripts

Code: Select all

vim CPUTempShutdown.sh

Code: Select all

#!/bin/bash

# PURPOSE: Script to check temperature of CPU cores and report/shutdown if specified temperatures exceeded
#
# Modified for this server!
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com

# Expects two arguments:
#    1. Warning temperature
#    2. Critical shutdown temperature
#    eg. using ./CPUTempShutdown.sh 30 40
#        will warn when temperature of one or more cores hit 30degrees and shutdown when either hits 40degrees.

# NOTES:
# Change the strings ">>/home/htkh" as required
# Substitute string "myemail@myaddress.com" with your own email address in the string which starts "/usr/sbin/ssmtp myemail@myaddress.com"

# Assumes output from sensors command is as follows:
#
# coretemp-isa-0000
# Adapter: ISA adapter
# Core 0:      +35.0 C  (high = +78.0 C, crit = +100.0 C)
#
# coretemp-isa-0001
# Adapter: ISA adapter
# Core 1:      +35.0 C  (high = +78.0 C, crit = +100.0 C)
#
# if not then modify the commands str=$(sensors | grep "Core $i:") & newstr=${str:14:2} below accordingly

echo "JOB RUN AT $(date)"
echo "======================================="

echo ''
echo 'CPU Warning Limit set to => '$1
echo 'CPU Shutdown Limit set to => '$2
echo ''
echo ''

sensors

echo ''
echo ''

for i in 0 1 2 3
do

  str=$(sensors | grep "Core $i:")
  newstr=${str:17:2}

  if [ ${newstr} -ge $1 ]
  then
    echo '============================'                             >>/home/server/Logs/CPUWarning.Log
    echo $(date)                                                    >>/home/server/Logs/CPUWarning.Log
    echo ''                                                         >>/home/server/Logs/CPUWarning.Log
    echo ' WARNING: TEMPERATURE CORE' $i 'EXCEEDED' $1 '=>' $newstr >>/home/server/Logs/CPUWarning.Log
    echo ''                                                         >>/home/server/Logs/CPUWarning.Log
    echo '============================'                             >>/home/server/Logs/CPUWarning.Log

    echo '============================'                           
    echo $(date)                                                  
    echo ''                                                       
    echo ' WARNING: TEMPERATURE CORE' $i 'EXCEEDED' $1 '=>' $newstr
    echo ''                                                       
    echo '============================'                           
  fi
 
  if [ ${newstr} -ge $2 ]
  then
    echo '============================'                             >>/home/server/Logs/CPUWarning.Log
    echo ''                                                         >>/home/server/Logs/CPUWarning.Log
    echo 'CRITICAL: TEMPERATURE CORE' $i 'EXCEEDED' $2 '=>' $newstr >>/home/server/Logs/CPUWarning.Log
    echo ''                                                         >>/home/server/Logs/CPUWarning.Log
    echo '============================'                             >>/home/server/Logs/CPUWarning.Log

    echo '============================'
    echo ''
    echo 'CRITICAL: TEMPERATURE CORE' $i 'EXCEEDED' $2 '=>' $newstr
    echo ''
    echo '============================'

    /usr/sbin/pm-hibernate
    /usr/sbin/ssmtp YOUR@EMAIL.com </home/server/Logs/CPUWarning.Log

    echo 'Email Sent.....'
    exit
  else

    echo ''
    echo ' Temperature Core '$i' OK at =>' $newstr
    echo ''
  fi
done

echo 'All CPU Cores are within limits'
echo ''
:wq

Code: Select all

chmod a+x CPUTempShutdown.sh
./CPUTempShutdown.sh 45 60
--------------------------------------------------------------

HDD:

Code: Select all

sudo fdisk -l
sudo apt-get install smartmontools
sudo smartctl -a /dev/sdb
cd Scripts
vim DriveTempShutdown.sh
Note on modified Drive Temperature Shutdown script:

Following the instructions on http://www.havetheknowhow.com/Configure ... tures.html
I took the script kindly provided there and modified it for my own purposes.

I then uncovered a potential problem and decided to modify it more extensively: Basically, I was testing a USB rescue drive on my server system, to see if it booted properly and left it in by mistake when I shut down. It was early in my install of the base system (Ubuntu Server 12.04) and so upon my next reboot, I happened to be playing around with hdparm parameters, continuing from my last session. After a period of some alarm and confusion, I eventually realised that this USB drive had stolen the sda position and had forced all the rest of my disks down the table. Remembering about UUIDs, I did a little research and figured that this would be the best way to go in referencing my partitions, so I set about changing my settings and scripts to use these instead. To do this, I used the contents of the dev/disk/by-id folder.

Here is how I went about creating a Thermal Shutdown script (DriveTempShutdown.sh) to reflect this policy:

https://help.ubuntu.com/community/UsingUUID

Code: Select all

ls -l /dev/disk/by-id

Code: Select all

total 0
llrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-MATSHITABD-MLT_UJ240AS_WJ42_003694 -> ../../sr0
lrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-name-Server-root -> ../../dm-0
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-name-Server-swap_1 -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-name-Server-System -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdb9h3Rs23fJ2io8zxPjbpedP4eUrC3OVw -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdG5s3dBd4rFdt34hdJoyhJxB5oCw7l6RI -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdVJQezcxe7NQVplQeVfQFMlqY4dAwq73D -> ../../dm-0
lrwxrwxrwx 1 root root  9 Aug  1 09:13 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 09:13 wwn-0x5000cca22bc063f2 -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5000cca22bc063f2-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 09:13 wwn-0x5002538043584d30 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5002538043584d30-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5002538043584d30-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5002538043584d30-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 09:13 wwn-0x5e83a97edd3455aa -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 09:13 wwn-0x5e83a97edd3455aa-part1 -> ../../sdc1
I'm after the ID of the physical drive sdb here, for my purposes, so the line;
lrwxrwxrwx 1 root root 9 Aug 1 09:13 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ -> ../../sdb
is what I'm looking for.

The path to this symbolic link is therefore:

/dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ

So the modified Thermal Shutdown script for this method looks like:

Code: Select all

 #!/bin/bash

#PURPOSE: Script to check temperature of installed hard drives and report/shutdown if specified temperatures exceeded
#
# Modified for this server!!
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com

# Expects three arguments:
#    1. Warning temperature
#    2. Critical shutdown temperature
#    3. If argument 3 is present then just check that drive letter
#    eg. using ./DriveTemps.sh 35 45
#    will warn when temperature of one or more drives reaches 35degrees and shutdown when any one of them hits 45
#    eg. using ./DriveTemps.sh 35 45 c
#    will warn when temperature of drive sdc reaches 35degrees and shutdown when it hits 45

# NOTES:
#  Change the string ">>/home/htkh" as required
#  Substitute string "myemail@myaddress.com" with your own email address in the string which starts "/usr/sbin/ssmtp myemail@myaddress.com"
#  Change the command   MyList='a b c d e' to the number of drives you have. In this case I'm using 6 drives

# Assumes  /usr/sbin/smartctl -n standby -a /dev/sd$i returns the string 'Temperature_Celsius' somewhere

echo "JOB RUN AT $(date)"
echo '============================'
echo ''
echo 'Drive Warning Limit set to =>' $1
echo 'Drive Shutdown Limit set to =>' $2
echo ''
echo ''

if [ $# -eq 2 ]
 then
  MyList='scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ'
  echo 'Testing all drives'
  else
   MyList=($3)
   echo 'Testing only the system drive'
fi

echo ''

for i in $MyList
 do
  echo 'Drive /dev/disk/by-id/'$i
  /usr/sbin/smartctl -n standby -a /dev/disk/by-id/$i | grep Temperature_Celsius
 done

echo ''
echo ''

for i in $MyList
 do
  #Check state of drive 'active/idle' or 'standby'
  stra=$(/sbin/hdparm -C /dev/disk/by-id/$i | grep 'drive' | awk '{print $4}')

  echo 'Testing Drive with ID: '$i

  if [ ${stra} = 'standby' ]
   then
    echo '    Drive with ID: '$i ' s in standby'
    echo ''
   else

    str1='/usr/sbin/smartctl -n standby -a /dev/disk/by-id/'$i
    str2=$($str1 | grep Temperature_Celsius | awk '{print $10}')

   if [ ${str2} -ge $1 ]
    then

     echo '========================================'                             >>/home/server/Logs/DriveWarning.Log
     echo $(date)                                                                >>/home/server/Logs/DriveWarning.Log
     echo ''                                                                     >>/home/server/Logs/DriveWarning.Log
     echo 'WARNING: TEMPERATURE FOR DRIVE with ID: '$i 'EXCEEDED' $1 '=>' $str2  >>/home/server/Logs/DriveWarning.Log
     echo ''                                                                     >>/home/server/Logs/DriveWarning.Log
     echo '========================================'                             >>/home/server/Logs/DriveWarning.Log

     echo '========================================'
     echo $(date)
     echo ''
     echo 'WARNING: TEMPERATURE FOR DRIVE with ID: '$i 'EXCEEDED' $1 '=>' $str2
     echo ''
     echo '========================================'

    fi

    if [ ${str2} -ge $2 ]
     then

      echo '========================================'                             >>/home/server/Logs/DriveWarning.Log
      echo $(date)                                                                >>/home/server/Logs/DriveWarning.Log
      echo ''                                                                     >>/home/server/Logs/DriveWarning.Log
      echo 'CRITICAL: TEMPERATURE FOR DRIVE with ID: '$i 'EXCEEDED' $2 '=>' $str2 >>/home/server/Logs/DriveWarning.Log
      echo ''                                                                     >>/home/server/Logs/DriveWarning.Log
      echo '========================================'                             >>/home/server/Logs/DriveWarning.Log

      echo '========================================'
      echo $(date)
      echo ''
      echo 'CRITICAL: TEMPERATURE FOR DRIVE with ID: '$i 'EXCEEDED' $2 '=>' $str2
      echo ''
      echo '========================================'

      /usr/sbin/pm-hibernate
      /usr/sbin/ssmtp YOUR@EMAIL.com.com </home/server/Logs/DriveWarning.Log
      echo 'Email Sent.....'
      exit
     else

      echo ''
      echo '    Temperature of Drive with ID: '$i' is OK at =>' $str2
      echo ''
    fi
   fi
  done

echo 'All Drives are within limits'
echo ''
:wq

Code: Select all

chmod a+x DriveTempShutdown.sh
sudo ./DriveTempShutdown.sh 35 45
:wq

--------------------------------------------------------------
Enable Hibernation Feature:

Both of the above scripts use the pm-hibernate command. To be able to use this, just install pm-utils:

Code: Select all

sudo apt-get install pm-utils
--------------------------------------------------------------

Active Cooling:

Code: Select all

sudo apt-get update
sudo apt-get install fancontrol
sudo reboot -h now

Code: Select all

sudo -s
sudo pwmconfig

Code: Select all

# pwmconfig revision 5857 (2010-08-22)
This program will search your sensors for pulse width modulation (pwm)
controls, and test each one to see if it controls a fan on
your motherboard. Note that many motherboards do not have pwm
circuitry installed, even if your sensor chip supports pwm.

We will attempt to briefly stop each fan using the pwm controls.
The program will attempt to restore each fan to full speed
after testing. However, it is ** very important ** that you
physically verify that the fans have been to full speed
after the program has completed.

Found the following devices:
   hwmon0/device is coretemp
   hwmon1/device is nct6776
   hwmon2/device is nouveau

Found the following PWM controls:
   hwmon1/device/pwm1
   hwmon1/device/pwm2

Giving the fans some time to reach full speed...
Found the following fan sensors:
   hwmon1/device/fan1_input     current speed: 2039 RPM
   hwmon1/device/fan2_input     current speed: 6459 RPM

Warning!!! This program will stop your fans, one at a time,
for approximately 5 seconds each!!!
This may cause your processor temperature to rise!!!
If you do not want to do this hit control-C now!!!
Hit return to continue:

Testing pwm control hwmon1/device/pwm1 ...
  hwmon1/device/fan1_input ... speed was 2039 now 1016
    It appears that fan hwmon1/device/fan1_input
    is controlled by pwm hwmon1/device/pwm1
Would you like to generate a detailed correlation (y)? y
    PWM 255 FAN 2048
    PWM 240 FAN 1893
    PWM 225 FAN 1809
    PWM 210 FAN 1735
    PWM 195 FAN 1679
    PWM 180 FAN 1624
    PWM 165 FAN 1560
    PWM 150 FAN 1503
    PWM 135 FAN 1440
    PWM 120 FAN 1373
    PWM 105 FAN 1309
    PWM 90 FAN 1240
    PWM 75 FAN 1183
    PWM 60 FAN 1116
    PWM 45 FAN 1046
    PWM 30 FAN 1012
    PWM 28 FAN 1005
    PWM 26 FAN 1011
    PWM 24 FAN 1007
    PWM 22 FAN 1006
    PWM 20 FAN 1010
    PWM 18 FAN 1006
    PWM 16 FAN 1012
    PWM 14 FAN 1012
    PWM 12 FAN 1009
    PWM 10 FAN 1013
    PWM 8 FAN 1008
    PWM 6 FAN 1008
    PWM 4 FAN 1012
    PWM 2 FAN 1009
    PWM 0 FAN 1013

  hwmon1/device/fan2_input ... speed was 6459 now 6650
    no correlation

Testing pwm control hwmon1/device/pwm2 ...
  hwmon1/device/fan1_input ... speed was 2039 now 2067
    no correlation
  hwmon1/device/fan2_input ... speed was 6459 now 2299
    It appears that fan hwmon1/device/fan2_input
    is controlled by pwm hwmon1/device/pwm2
Would you like to generate a detailed correlation (y)? y
    PWM 255 FAN 6650
    PWM 240 FAN 6338
    PWM 225 FAN 6338
    PWM 210 FAN 5947
    PWM 195 FAN 5895
    PWM 180 FAN 5672
    PWM 165 FAN 5314
    PWM 150 FAN 5113
    PWM 135 FAN 5037
    PWM 120 FAN 4838
    PWM 105 FAN 4470
    PWM 90 FAN 4354
    PWM 75 FAN 4090
    PWM 60 FAN 3802
    PWM 45 FAN 3435
    PWM 30 FAN 3260
    PWM 28 FAN 3054
    PWM 26 FAN 3020
    PWM 24 FAN 3068
    PWM 22 FAN 2928
    PWM 20 FAN 2973
    PWM 18 FAN 2934
    PWM 16 FAN 2800
    PWM 14 FAN 2836
    PWM 12 FAN 2710
    PWM 10 FAN 2657
    PWM 8 FAN 2694
    PWM 6 FAN 2641
    PWM 4 FAN 2576
    PWM 2 FAN 2436
    PWM 0 FAN 2393


Testing is complete.
Please verify that all fans have returned to their normal speed.

The fancontrol script can automatically respond to temperature changes
of your system by changing fanspeeds.
Do you want to set up its configuration file now (y)? y
What should be the path to your fancontrol config file (/etc/fancontrol)? /etc/fancontrol

Select fan output to configure, or other action:
1) hwmon1/device/pwm2  3) Change INTERVAL     5) Save and quit
2) hwmon1/device/pwm1  4) Just quit           6) Show configuration
select (1-n):
Now that the testing is complete, you must select each of your fans in turn, pair them up with the sensor which will provide the temperature data in order to configure and control them automatically. So In my case I first:

Select #1) hwmon1/device/pwm2

Code: Select all

Select fan output to configure, or other action:
1) hwmon1/device/pwm2  3) Change INTERVAL     5) Save and quit
2) hwmon1/device/pwm1  4) Just quit           6) Show configuration
select (1-n): 1

Devices:
hwmon0/device is coretemp
hwmon1/device is nct6776
hwmon2/device is nouveau

Current temperature readings are as follows:
hwmon0/device/temp1_input       31
hwmon0/device/temp2_input       29
hwmon0/device/temp3_input       27
hwmon0/device/temp4_input       31
hwmon0/device/temp5_input       30
hwmon1/device/temp1_input       64
hwmon1/device/temp2_input       37
hwmon1/device/temp3_input       62
hwmon1/device/temp4_input       27
hwmon2/device/temp1_input       37

Select a temperature sensor as source for hwmon1/device/pwm2:
 1) hwmon0/device/temp1_input
 2) hwmon0/device/temp2_input
 3) hwmon0/device/temp3_input
 4) hwmon0/device/temp4_input
 5) hwmon0/device/temp5_input
 6) hwmon1/device/temp1_input
 7) hwmon1/device/temp2_input
 8) hwmon1/device/temp3_input
 9) hwmon1/device/temp4_input
10) hwmon2/device/temp1_input
11) None (Do not affect this PWM output)
select (1-n):
From lm-sensors output:

hwmon1/device/fan1_input is CPU fan;
hwmon1/device/fan2_input is GPU/Chipset fan;
CPUTIN is CPU temp;
SYSTIN is Chipset temp?
AUXTIN is GPU temp?

pwmconfig's output tells us: "It appears that fan hwmon1/device/fan2_input is controlled by pwm hwmon1/device/pwm2"

This fan's top speed appears to be 6459rpm: Checking the fan speeds in BIOS tells me that this is definitely the GPU/Chipset fan.

And "hwmon1/device/temp1_input 64" correlates with the 64°C of the SYSTIN sensor, via lm-sensors.

So I choose: "6) hwmon1/device/temp1_input".

Code: Select all

select (1-n): 6

Enter the low temperature (degree C)
below which the fan should spin at minimum speed (20): 70
As this is running at 65°C in idle, I will enter 70 as the lower temperature.

Code: Select all

Enter the high temperature (degree C)
over which the fan should spin at maximum speed (60): 90
I'm told by an authoritative source that these chipsets can get to over 100°C, so I'll pick 90 as a safe option (hopefully) for the top temperature.

Code: Select all

Enter the PWM value (0-255) to use when the temperature
is over the high temperature limit (255): 255
Top speed is 255, so I'll pick that.

Next I select:

2) hwmon1/device/pwm1

Code: Select all

Select fan output to configure, or other action:
1) hwmon1/device/pwm2  3) Change INTERVAL     5) Save and quit
2) hwmon1/device/pwm1  4) Just quit           6) Show configuration
select (1-n): 2

Devices:
hwmon0/device is coretemp
hwmon1/device is nct6776
hwmon2/device is nouveau

Current temperature readings are as follows:
hwmon0/device/temp1_input       31
hwmon0/device/temp2_input       29
hwmon0/device/temp3_input       26
hwmon0/device/temp4_input       31
hwmon0/device/temp5_input       30
hwmon1/device/temp1_input       65
hwmon1/device/temp2_input       37
hwmon1/device/temp3_input       62
hwmon1/device/temp4_input       27
hwmon2/device/temp1_input       36

Select a temperature sensor as source for hwmon1/device/pwm1:
 1) hwmon0/device/temp1_input
 2) hwmon0/device/temp2_input
 3) hwmon0/device/temp3_input
 4) hwmon0/device/temp4_input
 5) hwmon0/device/temp5_input
 6) hwmon1/device/temp1_input
 7) hwmon1/device/temp2_input
 8) hwmon1/device/temp3_input
 9) hwmon1/device/temp4_input
10) hwmon2/device/temp1_input
11) None (Do not affect this PWM output)
select (1-n):
From lm-sensors output:

hwmon1/device/fan1_input is CPU fan;
hwmon1/device/fan2_input is GPU/Chipset fan;
CPUTIN is CPU temp;
SYSTIN is Chipset temp?
AUXTIN is GPU temp?

pwmconfig's output tells us that "It appears that fan hwmon1/device/fan1_input is controlled by pwm hwmon1/device/pwm1"

This fan's top speed appears to be 2039rpm: Checking the fan speeds in BIOS tells me that this is definitely the CPU fan.

And "hwmon1/device/temp2_input 37" correlates with the 37°C of the CPUTIN sensor, via lm-sensors.

So I choose: "7) hwmon1/device/temp2_input"

Code: Select all

select (1-n): 7

Enter the low temperature (degree C)
below which the fan should spin at minimum speed (20): 40
As this is running at 37°C in idle, I enter 40 as the lower temperature.

Code: Select all

Enter the high temperature (degree C)
over which the fan should spin at maximum speed (60): 70
I'll pick 70 as the high temperature.

Code: Select all

Enter the PWM value (0-255) to use when the temperature
is over the high temperature limit (255): 255
Top speed is 255, so I'll pick that.

Finally, I'll set the update interval to 5 seconds and so I pick 3) Change INTERVAL.

Code: Select all

Select fan output to configure, or other action:
1) hwmon1/device/pwm2  3) Change INTERVAL     5) Save and quit
2) hwmon1/device/pwm1  4) Just quit           6) Show configuration
select (1-n): 3

Current interval is 10 seconds.
Enter the interval at which fancontrol should update PWM values (in s): 5
Enter "5"

Now: 6) Show configuration

Code: Select all

Select fan output to configure, or other action:
1) hwmon1/device/pwm2  3) Change INTERVAL     5) Save and quit
2) hwmon1/device/pwm1  4) Just quit           6) Show configuration
select (1-n): 6

Common Settings:
INTERVAL=5

Settings of hwmon1/device/pwm2:
  Depends on hwmon1/device/temp1_input
  Controls hwmon1/device/fan2_input
  MINTEMP=70
hwmon1/device/pwm2
  MAXTEMP=90
  MINSTART=150
  MINSTOP=0
  MAXPWM=255

Settings of hwmon1/device/pwm1:
  Depends on hwmon1/device/temp2_input
  Controls hwmon1/device/fan1_input
  MINTEMP=40
  MAXTEMP=70
  MINSTART=150
  MINSTOP=0
  MAXPWM=255
Finally: 5) Save and quit

Code: Select all

Select fan output to configure, or other action:
1) hwmon1/device/pwm2  3) Change INTERVAL     5) Save and quit
2) hwmon1/device/pwm1  4) Just quit           6) Show configuration
select (1-n): 5

Saving configuration to /etc/fancontrol...
Configuration saved
--------------------------------------------------------------

Spinning down HDDs, troubleshooting and setting other drive parameters:

Note: If you have a Western Digital 'Green' HDD, you may not be able to spin this drive down, due to all of its power management features being automatically controlled by the drive itself and aggressive head-parking being used instead of Standby mode. This renders APM unavailable. I believe that has been done in order to make the drive more energy efficient in consumer electronics useage, where there is no advanced (or any) user-configurability available. This can cause problems and dramatically shorten the drive's lifespan when used in a linux box, if the user is not very careful, so I therefore chose a Hitachi drive for my server. I would definitely recommend reading up on this if you are considering using one of these popular drives in your system:
http://koitsu.wordpress.com/2012/05/30/ ... d-parking/

The first thing to do is to check if your drives will spin down:

Code: Select all

sudo hdparm -y /dev/sd[abc]

/dev/sda:
 issuing standby command

/dev/sdb:
 issuing standby command

/dev/sdc:
 issuing standby command
After 5-10 minutes, check to see if the drives are still in standby, by entering:

Code: Select all

sudo hdparm -C /dev/sd[abc]

/dev/sda:
 drive state is:  active/idle

/dev/sdb:
 drive state is:  standby

/dev/sdc:
 drive state is:  standby
If they are not in standby, then you may have a problem which will need solving before this process will work. To attempt remedy this, please check out the troubleshooting suggestions at the bottom of this section, though it is worth bearing in mind that, as in the example above, sda is very likely to be the system drive (and an SSD, in my case) and will likely not spin down anyway, no matter what you do, so it may benefit you to not even bother with this process for such drives.

Also, make sure that you check the APM settings of your drives in order to make sure that they are set up to support spinning down:

http://technomancer.me.uk/howto-hdparm- ... isk-tuning
http://www.linuxguide.it/command_line/l ... ile=hdparm
http://manpages.ubuntu.com/manpages/pre ... onf.5.html

Terminal:

Code: Select all

man hdparm

Code: Select all

[...]

-B     Get/set  Advanced  Power  Management feature, if the drive supports it. A low value
              means aggressive power management and a high value means better performance.   Pos�
              sible settings range from values 1 through 127 (which permit spin-down), and values
              128 through 254 (which do not permit spin-down).  The highest degree of power  man�
              agement  is  attained  with  a setting of 1, and the highest I/O performance with a
              setting of 254.  A value of 255 tells hdparm to disable Advanced  Power  Management
              altogether on the drive (not all drives support disabling it, but most do).

[...]
To check if your drives support APM:

Code: Select all

sudo hdparm -B /dev/sd[abc]

/dev/sda:
 APM_level      = not supported

/dev/sdb:
 APM_level      = off

/dev/sdc:
 APM_level      = 254
Set APM mode with:

Code: Select all

sudo hdparm -B127 /dev/sd[bc]

/dev/sdb:
 setting Advanced Power Management level to 0x7f (127)
 APM_level      = 127

/dev/sdc:
 setting Advanced Power Management level to 0x7f (127)
 APM_level      = 127
It is incredibally worthwhile to have a good look at that hdparm Man Page mentioned above, as it can help you to set up your drives just as you want them.
For example, you might want to change the Acoustic Management setting for your drives, to make them as quiet as possible (this should not have a major impact on performance):

Code: Select all

sudo hdparm -M /dev/sd[abcd]

/dev/sda:
 acoustic      = not supported

/dev/sdb:
 acoustic      = not supported

/dev/sdc:
 acoustic      = not supported

/dev/sdd:
 acoustic      = 254 (128=quiet ... 254=fast)

Code: Select all

sudo hdparm -M128 /dev/sdd

/dev/sdd:
 setting acoustic management to 128
 acoustic      = 128 (128=quiet ... 254=fast)
In order to make these changes permanent (some changes are kept over reset and power-off, but not all), they need to be written to /etc/hdparm.conf. There are detailed notes commented in the file which explain the procedure and syntax, so have a good read of them before you start altering the file.

For example, the following is a direct cut and paste from hdparm.conf which lists the available options:

Code: Select all

# -q be quiet
quiet
# -a sector count for filesystem read-ahead
#read_ahead_sect = 12
# -A disable/enable the IDE drive's read-lookahead feature
#lookahead = on
# -b bus state
#bus = on
# -B apm setting
#apm = 255
# -c enable (E)IDE 32-bit I/O support - can be any of 0,1,3
#io32_support = 1
# -d disable/enable the "using_dma" flag for this drive
#dma = off
# -D enable/disable the on-drive defect management
#defect_mana = off
# -E cdrom speed
#cd_speed = 16
# -k disable/enable the "keep_settings_over_reset" flag for this drive
#keep_settings_over_reset = off
# -K disable/enable the drive's "keep_features_over_reset" flag
#keep_features_over_reset = on
# -m sector count for multiple sector I/O
#mult_sect_io = 32
# -P maximum sector count for the drive's internal prefetch mechanism
#prefetch_sect = 12
# -r read-only flag for device
#read_only = off
# -s Turn on/off power on in standby mode
# poweron_standby = off
# -S standby (spindown) timeout for the drive
#spindown_time = 24
# -u interrupt-unmask flag for the drive
#interrupt_unmask = on
# -W Disable/enable the IDE drive's write-caching feature
#write_cache = off
# -X IDE transfer mode for newer (E)IDE/ATA2 drives
#transfer_mode = 34
# -y force to immediately enter the standby mode
#standby
# -Y force to immediately enter the sleep mode
#sleep
# -Z Disable the power-saving function of certain Seagate drives
#disable_seagate
# -M Set the acoustic management properties of a drive
#acoustic_management
# -p Set the chipset PIO mode
# chipset_pio_mode
# --security-freeze Freeze the drive's security status
# security_freeze
# --security-unlock Unlock the drive's security
# security_unlock = PWD
# --security-set-pass Set security password
# security_pass = password
# --security-disable Disable drive locking
# security_disable
# --user-master Select password to use
# user-master = u
# --security-mode Set the security mode
# security_mode = h
I would recommend identifying your drives by their unique ID rather than simply using /dev/hd*# or /dev/sd*#, as device assignments can change between system boots. I had this happen to me when I left my bootable USB rescue drive plugged in. It took the sdb label and pushed the rest of my storage drives on up the alphabet. This caused me some concern before I realised what had happened.

https://help.ubuntu.com/community/UsingUUID

Code: Select all

ls -l /dev/disk/by-id

Code: Select all

total 0
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-MATSHITABD-MLT_UJ240AS_WJ42_003694 -> ../../sr0
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-name-Server-root -> ../../dm-0
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-name-Server-swap_1 -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-name-Server-System -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdb9h3Rs23fJ2io8zxPjbpedP4eUrC3OVw -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdG5s3dBd4rFdt34hdJoyhJxB5oCw7l6RI -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdVJQezcxe7NQVplQeVfQFMlqY4dAwq73D -> ../../dm-0
lrwxrwxrwx 1 root root  9 Aug  1 14:09 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 14:09 wwn-0x5000cca22bc063f2 -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5000cca22bc063f2-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 wwn-0x5002538043584d30 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5002538043584d30-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5002538043584d30-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5002538043584d30-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 14:09 wwn-0x5e83a97edd3455aa -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5e83a97edd3455aa-part1 -> ../../sdc1
So for the device sdb, I would choose:

/dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ

Code: Select all

sudo vim /etc/hdparm.conf
Add your devices and their hdparm options to the bottom of the file:

Code: Select all

/dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ {
        apm = 127
        keep_features_over_reset = on
        spindown_time = 242
}
AS you can see, I've opted to set Advanced Power Management to 127 as this is the setting with the highest performance which still allows spin-down, I've told the drive to keep features over reset, in order to preserve the settings on a soft restart, and spin-down delay has been set to 242 (1 hour).

I have also enabled Power On In Standby to limit instant power drain on system power-up (DO NOT use this unless your mother board supports it!), by entering in a terminal:

Code: Select all

sudo hdparm -s --yes-i-know-what-i-am-doing  /dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ
As stated above; don't do this unless you really know what you are doing! Your drive will not power up and you will therefore be unable to change this setting again unless you can connect it to a motherboard and OS which supports this feature and has it enabled in BIOS (in my BIOS, this feature is listed as 'Enable Staggered Spin-up'). Unless your system meets these criteria, your drive will, to all intents and purposes be 'bricked' upon the next restart!

Patch "/lib/hdparm/hdparm-functions" File:

For some unknown reason, the ability to set HDD parameters in /etc/hdparm.conf using ID symlinks been broken for years and although a fix has been around for almost as long (in one form or another), it has never been implemented.

https://bugs.launchpad.net/ubuntu/+sour ... bug/799312
https://launchpadlibrarian.net/73763550 ... ions.patch

In Terminal:

Code: Select all

wget https://launchpadlibrarian.net/73763550/hdparm-functions.patch
sudo patch /lib/hdparm/hdparm-functions /home/server/hdparm-functions.patch
rm /home/server/hdparm-functions.patch
sudo reboot now
Troubleshooting:
Drive still won't spin down?

After setting this all up, I found to my dismay that I still couldn't get this to work on my 4TB Hitachi drive: It simply refused to spin down unless told to do so with the hdparm -y command. To troubleshoot this issue, I set spindown_time = 24 (2 minutes) and checking APM showed that my settings in hdparm.conf were definitely being applied;

Code: Select all

sudo hdparm -B /dev/sd[abc]

/dev/sda:
 APM_level      = not supported

/dev/sdb:
 APM_level      = 127

/dev/sdc:
 APM_level      = 254
but for some reason the spindown setting was not taking. The same problem seemed to be happening to others in the following thread; http://forum.havetheknowhow.com/viewtop ... 0&start=10, but the proposed solution; http://forum.havetheknowhow.com/viewtop ... p=825#p825, wouldn't work for me as Gnome-Core doesn't seem to have the "Spin down hard disks when possible" tick-box in it's power settings. The Settings dialogue is now called "Power", not "Power Management" and has only the option to set standby time. Even installing XFCE instaed of Gnome-Core as my graphical desktop environment and installing power manager with;

Code: Select all

sudo apt-get install xfce4-power-manager
lead to a dead-end, as the "Spin down hard disks when possible" tick-box was greyed out and inaccessible. Launching power manager with;

Code: Select all

sudo xfce4-power-manager
sudo xfce4-power-manager-settings
gave me the tick-box back, but this still didn't help.

The following page gives a lot of advice and excellent suggestions for solving spin-down problems:
http://info4admins.com/tips-to-spindown ... or-ubuntu/

First, I tried a solution from the comments section of that page:
http://sourceforge.net/tracker/?func=de ... tid=117457

In Webmin:

Webmin -> Webmin Configuration -> Background Status Collection

Collect system status in background? Never
Collect available package updates? Yes
Collect drive temperatures? No


I next tried stopping Samba from Webmin with: Servers -> Samba Windows File Sharing -> Stop Samba Servers

No joy.

http://ubuntuforums.org/showthread.php?t=1488614&page=2
http://smartmontools.sourceforge.net/ma ... onf.5.html
http://ubuntuforums.org/archive/index.p ... 25263.html
https://wiki.archlinux.org/index.php/S.M.A.R.T.

Next up, I tried configuring smartmontools in case the SMART daemon was preventing spin-down:

Code: Select all

sudo vim /etc/default/smartmontools
adding the line

Code: Select all

smartd_opts=”-q never -i 7200"
to the end. I then altered the settings in /etc/smartd.conf, changing the configuration line from;

Code: Select all

DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner
to;

Code: Select all

DEVICESCAN -d removable ata -n standby,q -m root -M exec /usr/share/smartmontools/smartd-runner
(Key: -d removable = treat missing drives as if they might be plugged in later,
[-d] ata = treat drives as ATA rather than SCSI etc,
-n standby = don't wake up drives in standby or sleep - just 'skip',
,q = don't log the 'skip',
-m root = email SMART error messages to root,
-M exec /.../... = send email via smartd-runner.)

Still no luck, so I tried commenting out the whole line:

Code: Select all

#DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner
The result:

Code: Select all

sudo hdparm -C /dev/sd[abc]

/dev/sda:
 drive state is:  active/idle

/dev/sdb:
 drive state is:  active/idle

/dev/sdc:
 drive state is:  active/idle
This is driving me to distraction! :x :crazy:

Is there something I've overlooked here?
If anyone can help me to solve this problem and get this blasted drive to spin down, I'd be extremely grateful as this is the only thing left to do to get my base operating system working as I want.

--------------------------------------------------------------

Send email alerts from Ubuntu Server using ssmtp:

http://www.havetheknowhow.com/Configure ... ssmtp.html

Code: Select all

sudo apt-get update
sudo apt-get install ssmtp
sudo vim /etc/ssmtp/ssmtp.conf

Code: Select all

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
#root=postmaster
root=YOUR@EMAIL.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=smtp.YOURISP.com:25

AuthUser=YOUR@EMAIL.com
AuthPass=PASSWORD
UseTLS=NO
UseSTARTTLS=NO

# Where will the mail seem to come from?
#rewriteDomain=
rewriteDomain=btinternet.com

# The full hostname
#hostname=Server.home
hostname=YOUR@EMAIL.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
Test it:

Code: Select all

sudo ssmtp YOUR@EMAIL.com


To: YOUR@EMAIL.com
From: YOUR@EMAIL.com
Subject: test email

Hello World!
ctrl-d

--------------------------------------------------------------

External IP script:

http://forum.havetheknowhow.com/viewtop ... 1436#p1436

Code: Select all

cd Scripts
vim MyIP.sh

Code: Select all

    #!/bin/bash
    #
    # PURPOSE: e-Mail me my external IP on change.
    #
    #
    THISHOST=$(hostname --long)

    new=$(wget -qO - http://cfaj.freeshell.org/ipaddr.cgi)

    if grep -q $new /home/server/Logs/MyIP.log
    then
    echo "No change"
    else
    echo "To: YOUR@EMAIL.com" >/home/server/Logs/MyIP.log
    echo "From: YOUR@EMAIL.com" >>/home/server/Logs/MyIP.log
    echo "Subject: Change of external IP address." >>/home/server/Logs/MyIP.log
    echo "" >>/home/server/Logs/MyIP.log
    echo "" >>/home/server/Logs/MyIP.log
    echo $THISHOST "reports that it's external IP adress has changed to:" >>/home/server/Logs/MyIP.log
    echo "" >>/home/server/Logs/MyIP.log
    echo $new >>/home/server/Logs/MyIP.log
    echo "" >>/home/server/Logs/MyIP.log

    /usr/sbin/ssmtp YOUR@EMAIL.com </home/server/Logs/MyIP.log

    fi
:wq

Code: Select all

chmod a+x MyIP.sh
--------------------------------------------------------------

Automate Scripts:

To set up the scripts that were saved earlier as scheduled cron jobs through Webmin, launch Webmin then click on System and then Scheduled Cron Jobs. Then click Create a new scheduled cron job at the top of the screen that opens.

Execute cron job as: server
Command: /home/server/Scripts/StartVNC.sh >/dev/null
Description: Start VNC on Bootup.
Simple schedule: When system boots

Execute cron job as: server
Command: /home/server/Scripts/CPUTempShutdown.sh 70 90 >>/home/server/Logs/CPUTempShutdown.log
Description: Monitor CPU temperature and shutdown as necessary.
Times and dates selected below...
All...

Execute cron job as: root
Command: /home/server/Scripts/DriveTempShutdown.sh 45 55 >>/home/server/Logs/DriveTempShutdown.log
Description: Monitor drive temperatures and shutdown if neccessary.
Simple schedule: Hourly

Execute cron job as: server
Command: /home/server/Scripts/MyIP.sh >/dev/null
Description: Check to see if external IP has changed and send an e-mail when it does.
Times and dates selected below...
Minutes: 0
Hours: 7 and 19

Create blank log files for the above scripts' outputs:

Terminal:

Code: Select all

mkdir Logs
touch /home/server/Logs/CPUTempShutdown.log
touch /home/server/Logs/DriveTempShutdown.log
touch /home/server/Logs/CPUWarning.Log
touch /home/server/Logs/DriveWarning.Log
touch /home/server/Logs/MyIP.log
Rotate the log files in order prevent them growing too large:

In Webmin:

System -> Log File Rotation -> Add a new log file to rotate.

Log file paths:

/home/server/Logs/CPUTempShutdown.log
/home/server/Logs/DriveTempShutdown.log

Rotation schedule: Daily

Keep rest on defaults.

Click Create.

Then:

System -> Log File Rotation -> Add a new log file to rotate.

Log file paths:

/home/server/Logs/CPUWarning.Log
/home/server/Logs/DriveWarning.Log

Rotation schedule: Monthly

Keep rest on defaults.

Commands to run after rotation:

Code: Select all

echo 'To: YOUR@EMAIL.com ' >>/home/server/Logs/CPUWarning.Log
echo 'From: YOUR@EMAIL.com ' >>/home/server/Logs/CPUWarning.Log
echo 'Subject: CPU Overheat Alert!' >>/home/server/Logs/CPUWarning.Log
echo '' >>/home/server/Logs/CPUWarning.Log
echo 'To: YOUR@EMAIL.com ' >>/home/server/Logs/DriveWarning.Log
echo 'From: YOUR@EMAIL.com ' >>/home/server/Logs/DriveWarning.Log
echo 'Subject: HDD Overheat Alert!' >>/home/server/Logs/DriveWarning.Log
echo '' >>/home/server/Logs/DriveWarning.Log
echo ''
Only run scripts once for all files? Yes

Click Create.

Click on the job you just created.

Click Rotate Now.

This will ensure that an email header will be attached to the Warning logs so that they can be sent via SMTP.

--------------------------------------------------------------
Post Reply