Your hard disk has tools built in which will alert you if your hard disk is about to physically fail. This has saved me exactly once, so it’s worth it in my opinion to set this up, even if the only computer that matters to you is your laptop.
Here’s how I have everything set up (in Arch)
First, I install msmtp
and set up the system-wide /etc/msmtprc
as follows
defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtprc.log
account remote
domain domain.remote.tld
host smtp.remote.tld
auth on
port 587
user awebster
from awebster@falsecolour.com
password <PASSWORD>
account default : remote
where <PASSWORD>
is your actual password. chmod 600
this file for not that much security. Might just want to use a throwaway or sandboxed email for such things anyway.
Next, install the smart tools
pacman -S smartmontools
and enable them
systemctl enable smartd
systemctl start smartd
Make sure that your drive support SMART and that SMART reporting is turned ON. See here for how to do that.
Edit /etc/smartd.conf
to report errors to you by changing the line
DEVICESCAN
to
DEVICESCAN -m awebster@falsecolour.com -M test
note the -M test
this is just to get it working, we’ll remove that at the end.
Since I use msmtp
instead of whatever, I had to edit /etc/smartd_warning.sh
so that it would use msmtp.
First, change the os_mailer
variable to
# Default mailer
os_mailer="msmtp"
Next, edit the following lines so that they look like this:
# Send mail or run command
if [ -n "$SMARTD_ADDRESS" ]; then
# Send mail, use platform mailer by default
test -n "$SMARTD_MAILER" || SMARTD_MAILER=$os_mailer
if [ -n "$dryrun" ]; then
echo "exec $SMARTD_MAILER -a default $SMARTD_ADDRESS <<EOF
To: $SMARTD_ADDRESS
From: $(whoami)@$HOSTNAME
Subject: $SMARTD_SUBJECT
$fullmessage
EOF"
else
exec $SMARTD_MAILER -a default $SMARTD_ADDRESS <<EOF
To: $SMARTD_ADDRESS
From: $(whoami)@$HOSTNAME
Subject: $SMARTD_SUBJECT
$fullmessage
EOF
fi
The modification here is basically that msmtp
(as far as I know, anyways) wants a nicely formatted message.
Test that everything is working by restarting the daemon
systemctl restart smartd
You should receive an email. If not, figure out what went wrong and fix it. If everything looks good you can remove the -M
test dingle from /etc/smartd.conf
and you should be good to go.
Quick note: You should always have a valid .forward
file in both your own home directory and root’s home directory. Make sure there are multiple entries in this in case you need it one day.