Packetwatch.net

Smartmontools in OpenBSD



Last modified: Jan. 30, 2010

Contents
1 - Summary
2 - Dependencies
3 - Smartmontools installation
4 - Service configuration
5 - Smartctl examples
6 - Service check


1 - Summary

This guide will show how to install smartmontools in OpenBSD. Smartmontools can
run tests to monitor the SMART of hard disks. This has been tested in OpenBSD
4.3, 4.4 and 4.6.


2 - Dependencies

Install the msmtp package. Msmtp is an SMTP client used to send email. We will
use it to send email notifications.
# pkg_find msmtp
clamsmtp-*.tgz
msmtp-*.tgz
# sudo pkg_add msmtp-*.tgz
Password:

The pkg_find utility used above is a shell script I've created that can search
the list of available packages.

#!/bin/sh
# This script will look for packages with the search term.

echo=/bin/echo
lynx=/usr/bin/lynx
pkg_path=ftp://ftp.openbsd.org/pub/OpenBSD/$rel/packages/$arch/index.txt
tr=/usr/bin/tr
cut=/usr/bin/cut
grep=/usr/bin/grep

if [ $# -ne 1 ]
    then
        exit 0
    else
        # check if a valid parameter
        if [ "$1" == "-help" ]
            then
                $echo Usage: pkg_find [string]
            else
                $lynx -dump $pkg_path | $tr -s " " | $cut -d " " -f 10 | $grep -i $1
        fi
fi
exit 0

# cd ~
# vi pkg_find
# sudo chown root:bin pkg_find
Password:
# sudo chmod 555 pkg_find
Password:
# sudo mv pkg_find /usr/sbin/
Password:

Find where the msmtp binary was installed to.
# pkg_info -L msmtp-* | grep bin 
/usr/local/bin/msmtp

Run ldd to display the shared objects (.so) needed to run the msmtp binary. If
there are any shared objects in /usr/local you will need to run ldconfig.
# ldd /usr/local/bin/msmtp
/usr/local/bin/msmtp:
        Start    End      Type Open Ref GrpRef Name
        1c000000 3c008000 exe  1    0   0      /usr/local/bin/msmtp
        085b3000 285b7000 rlib 0    2   0      /usr/local/lib/libintl.so.4.0
        09ec3000 29fa2000 rlib 0    2   0      /usr/local/lib/libiconv.so.6.0
        0b847000 2b854000 rlib 0    1   0      /usr/lib/libssl.so.15.0
        03c39000 23c79000 rlib 0    1   0      /usr/lib/libcrypto.so.18.0
        0cb58000 2cb84000 rlib 0    1   0      /usr/local/lib/libidn.so.16.30
        0ed02000 2ede1000 rlib 0    1   0      /usr/local/lib/libiconv.so.6.0
        0433c000 24340000 rlib 0    1   0      /usr/local/lib/libintl.so.4.0
        0141c000 21455000 rlib 0    1   0      /usr/lib/libc.so.51.0
        08b4d000 08b4d000 rtld 0    1   0      /usr/libexec/ld.so
# sudo ldconfig /usr/lib /usr/local/lib
Password:

It's helpful to know what type of hard disks the computer has. You can find this
out by typing the following.
# sysctl hw.disknames
hw.disknames=wd0,cd0,fd0

In this case the hard drive is wd0, the CD/DVD drive is cd0 and the floppy
drive is fd0. Get more information about the hard disk by typing the following.
# dmesg | grep "^\wd0" | uniq 
wd0 at pciide0 channel 0 drive 0: 
wd0: 16-sector PIO, LBA48, 76293MB, 156250000 sectors
wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 5

Now, with the model of the hard drives find out if it's ATA, SCSI or SAT.


3 - Smartmontools installation

Install the smartmontools package.
# pkg_find smartmontools
smartmontools-*.tgz
# sudo pkg_add smartmontools-*.tgz
Password:


4 - Service configuration

Find where the smartmontools daemon was installed to.
# pkg_info -L smartmontools-* | grep sbin 
/usr/local/sbin/smartctl
/usr/local/sbin/smartd

Run ldd to display the shared objects (.so) needed to run the smartmontools
daemon. If there are any shared objects in /usr/local you will need to run
ldconfig.
# ldd /usr/local/sbin/smartd
/usr/local/sbin/smartd:
        Start    End      Type Open Ref GrpRef Name
        1c000000 3c036000 exe  1    0   0      /usr/local/sbin/smartd
        03a3d000 23a41000 rlib 0    1   0      /usr/lib/libutil.so.11.0
        0f4ec000 2f512000 rlib 0    1   0      /usr/lib/libstdc++.so.47.0
        01d47000 21d51000 rlib 0    1   0      /usr/lib/libm.so.5.0
        056bb000 256f4000 rlib 0    1   0      /usr/lib/libc.so.51.0
        0b809000 0b809000 rtld 0    1   0      /usr/libexec/ld.so

Edit /etc/rc.conf.local so that the smartmontools service will start when the
system starts up. Somewhere in the file add the following.
  smartd_flags="-p /var/run/smartd.pid"
# sudo vi /etc/rc.conf.local
Password:

Configure /etc/rc.local, so the smartmontools service will start at boot time.
Modify to have the following.
  if [ X"${smartd_flags}" != X"NO" ]; then
          echo -n ' smartd';      /usr/local/sbin/smartd ${smartd_flags}
  fi
# sudo vi /etc/rc.local
Password:

Find where the configuration file should be put.
# strings /usr/local/sbin/smartd | grep smartd.conf
Device: %s, no SMART Error log; remove -l error Directive from smartd.conf
Device: %s, no SMART Self-Test log; remove -l selftest Directive from smartd.conf
/etc/smartd.conf

You can create your own configuration file. Here is a simple example. This
will disable Autosave and will schedule a short self-test between 8-9 PM every
night and send warnings or errors to the email address provided. Scheduled
tests are run after the default scheduled device polling, which by default
is every thirty minutes after the smartmontools service is started.
  /dev/wd0c -d ata -S off -s S/../.././20 -m notifications@test.com -a
# pkg_info -L smartmontools-* | grep smartd.conf
/usr/local/man/man5/smartd.conf.5
/usr/local/share/doc/smartmontools/smartd.conf
# sudo cp /usr/local/share/doc/smartmontools/smartd.conf /etc/smartd.conf
Password:
# sudo cp /etc/smartd.conf /etc/smartd.conf.example
Password:
# sudo vi /etc/smartd.conf
Password:

Start the smartmontools service.
# sudo /usr/local/sbin/smartd -p /var/run/smartd.pid
Password:
# sudo cat /var/run/smartd.pid
Password:
27483


5 - Smartctl examples

Here are some basic examples of things you can find with smartctl. This
command enables SMART on the hard disks.
# sudo smartctl -d ata /dev/wd0c -s on
Password:
smartctl version 5.38 [x86_64-unknown-openbsd4.6] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Enabled.

This command prints the device model number, serial number, firmware version,
and ATA Standard version/revision information.
# sudo smartctl -d ata /dev/wd0c -i
Password:
smartctl version 5.38 [x86_64-unknown-openbsd4.6] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Barracuda 7200.9 family
Device Model:     ST3808110AS
Serial Number:    9LR47NFF
Firmware Version: 3.ADJ
User Capacity:    80,000,000,000 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   7
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Thu Jan 28 22:19:24 2010 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

This command prints the SMART health status.
# sudo smartctl -d ata /dev/wd0c -H
Password:
smartctl version 5.38 [x86_64-unknown-openbsd4.6] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

This command runs a SMART short self test.
# sudo smartctl -d ata /dev/wd0c -t short 
Password:
smartctl version 5.38 [x86_64-unknown-openbsd4.6] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Short self-test routine immediately in off-line mode".
Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 2 minutes for test to complete.
Test will complete after Thu Jan 28 22:23:49 2010

Use smartctl -X to abort test.

This command lists the log of selftest results.
# sudo smartctl -d ata /dev/wd0c -l selftest
Password:
smartctl version 5.38 [x86_64-unknown-openbsd4.6] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%     21123         -


6 - Service check

Reboot your computer. Log in like normal and check to see that the
smartmontools service is running. That's is, now you smartmontools running in
OpenBSD.
# sudo shutdown -r now
Password:
# sudo cat /var/run/smartd.pid
Password:
9749


Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2017.