05/22/2026

A properly configured SMART monitoring system can warn about disk problems long before complete failure. This lightweight solution based on smartmontools and msmtp is especially useful for standalone servers, home labs, mini-PCs, NAS systems, and small office environments where deploying full-scale monitoring platforms like Zabbix may be unnecessary or impractical.

I documented the entire setup process, including scheduled SMART self-tests, email alerts, TEST/WORK modes, and troubleshooting steps for Ubuntu Server deployments. Short guide here.

SMART Disk Monitoring and Email Alerts with msmtp + smartd (Ubuntu Server)

This guide explains how to:

  • monitor disk SMART status,
  • run automatic SMART self-tests,
  • receive email alerts,
  • integrate smartd with msmtp,
  • use your own SMTP server.

Suitable for:

  • Ubuntu Server 22/24,
  • NAS systems,
  • home servers,
  • mini-PC,
  • KVM/Proxmox hosts.

1. Install msmtp

sudo apt update && sudo apt upgrade -y
sudo apt install msmtp -y

2. Configure SMTP (Example configuration):

sudo nano /etc/msmtprc
defaults
auth           on
tls            on
tls_starttls   on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account        external
host           mx2.itbumper.com
port           587

from           inventory@itbumper.com
user           inventory@itbumper.com
password       your_password

account default : external
sudo chmod 600 /etc/msmtprc
sudo chown root:root /etc/msmtprc

3. Test email sending

echo -e "Subject: Test\n\nHi, connection test!" | sudo msmtp --debug radik.m@itbumper.com
loaded system configuration file /etc/msmtprc
ignoring user configuration file /root/.msmtprc: No such file or directory
falling back to default account
using account default from /etc/msmtprc
host = mx2.itbumper.com
port = 587
source ip = (not set)
proxy host = (not set)
proxy port = 0
socket = (not set)
timeout = off
protocol = smtp
domain = localhost
auth = choose
user = inventory@itbumper.com
password = *
passwordeval = (not set)
ntlmdomain = (not set)
tls = on
tls_starttls = on
tls_trust_file = /etc/ssl/certs/ca-certificates.crt
tls_crl_file = (not set)
tls_fingerprint = (not set)
tls_key_file = (not set)
tls_cert_file = (not set)
tls_certcheck = on
tls_min_dh_prime_bits = (not set)
tls_priorities = (not set)
tls_host_override = (not set)
auto_from = off
maildomain = (not set)
from = inventory@itbumper.com
from_full_name = (not set)
allow_from_override = on
set_from_header = auto
set_date_header = auto
remove_bcc_headers = on
undisclosed_recipients = off
dsn_notify = (not set)
dsn_return = (not set)
logfile = (not set)
logfile_time_format = (not set)
syslog = (not set)
aliases = (not set)
reading recipients from the command line
<-- 220 mx2.itbumper.com ESMTP Postfix
--> EHLO localhost
<-- 250-mx2.itbumper.com
<-- 250-PIPELINING
<-- 250-SIZE 157286400
<-- 250-ETRN
<-- 250-STARTTLS
<-- 250-ENHANCEDSTATUSCODES
<-- 250-8BITMIME
<-- 250 DSN
--> STARTTLS
<-- 220 2.0.0 Ready to start TLS
TLS session parameters:
    (TLS1.3)-(ECDHE-SECP256R1)-(RSA-PSS-RSAE-SHA256)-(AES-256-GCM)
TLS certificate information:
    Subject:
        CN=mx2.itbumper.com
    Issuer:
        C=US,O=Let's Encrypt,CN=R13
    Validity:
        Activation time: Wed 06 May 2026 06:12:03 AM PDT
        Expiration time: Tue 04 Aug 2026 06:12:02 AM PDT
    Fingerprints:
        SHA256: DC:73:D5:D9:39:92:2D:A4:EF:E0:62:A2:91:F1:1B:5D:38:46:53:38:85:25:DE:90:7C:4F:03:96:8C:B0:6F:5B
        SHA1 (deprecated): 77:9D:65:82:C3:4A:FD:31:F2:0F:F2:E0:85:12:DC:3A:26:CB:5E:8F
--> EHLO localhost
<-- 250-mx2.itbumper.com
<-- 250-PIPELINING
<-- 250-SIZE 157286400
<-- 250-ETRN
<-- 250-AUTH PLAIN LOGIN
<-- 250-ENHANCEDSTATUSCODES
<-- 250-8BITMIME
<-- 250 DSN
--> AUTH PLAIN AGludmVudG9yeUBpdGJ1bXBlci5jb20AaXBELlIxIUhrSTY9TzJ0bndeR3I=))
<-- 235 2.7.0 Authentication successful
--> MAIL FROM:<inventory@itbumper.com>
--> RCPT TO:<radik.m@itbumper.com>
--> DATA
<-- 250 2.1.0 Ok
<-- 250 2.1.5 Ok
<-- 354 End data with <CR><LF>.<CR><LF>
--> From: inventory@itbumper.com
--> Date: Thu, 21 May 2026 23:41:58 -0700
--> Message-ID: <f64123ba223eabf36d2f4302ce54a29b.inventory@itbumper.com>
--> Subject: Test
-->
--> Hi, connection test!
--> .
<-- 250 2.0.0 Ok: queued as 4gMG0V0cnhzqXKf
--> QUIT
<-- 221 2.0.0 Bye

4. Check smartd service and enable if needed:

systemctl status smartd
sudo systemctl enable --now smartd

5. Create smartd mailer script

sudo nano /usr/local/bin/smartd-mailer
#!/bin/bash

EMAIL="radik.m@itbumper.com"

(
echo "To: $EMAIL"
echo "From: inventory@itbumper.com"
echo "Subject: ITB HOST-01 SMART Alert"
echo
cat
) | /usr/bin/msmtp "$EMAIL"
sudo chmod 755 /usr/local/bin/smartd-mailer

6. Configure smartd

sudo nano /etc/smartd.conf

only ONE configuration line should be active:

  • either TEST mode,
  • or WORK mode.

Do not leave both entries enabled at the same time.

#EXAMPLE
# WORK mode disabled during testing
#DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

# TEST mode enabled
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -M test -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

# -M test
#parameter forces smartd to immediately send a test alert after service startup.
#This validates:
#  smartd functionality,
#  mailer script execution,
#  msmtp operation,
#  SMTP authentication,
#  email delivery.

6. Schedule format:  T/MM/DD/d/HH

Where:

Field Meaning
T Test type
S Short test
L Long test
MM Month
DD Day of month
d Day of week
HH Hour

Example schedule: (S/../.././02|L/../../6/03):

  • Short test daily at 02:00
  • Long test every Saturday at 03:00

Restart services

sudo systemctl restart smartd

Expected Result If configured correctly:

  • a SMART test email should arrive,
  • no smartd errors should appear,
  • msmtp should successfully deliver the message.

After receiving the test email:

  1. Disable TEST entry
  2. Enable WORK entry
  3. Save the file
  4. Restart smartd
# TEST mode disabled
#DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -M test -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

# WORK mode enabled
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

Verify SMART Test Schedule

sudo smartd -q showtests
#Example
smartd 7.4 2023-08-01 r5530 [x86_64-linux-6.8.0-111-generic] (local build)
Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org

Opened configuration file /etc/smartd.conf
Configuration file /etc/smartd.conf was parsed, found DEVICESCAN, scanning devices
Device: /dev/sda, type changed from 'scsi' to 'sat'
Device: /dev/sda [SAT], opened
Device: /dev/sda [SAT], Samsung SSD 860 PRO 1TB, S/N:S5G8NS0NB01379X, WWN:5-002538-e30b0d388, FW:RVM02B6Q, 1.02 TB
Device: /dev/sda [SAT], found in smartd database 7.3/5528: Samsung based SSDs
Device: /dev/sda [SAT], enabled SMART Attribute Autosave.
Device: /dev/sda [SAT], can't monitor Current_Pending_Sector count - no Attribute 197
Device: /dev/sda [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198
Device: /dev/sda [SAT], enabled SMART Automatic Offline Testing.
Device: /dev/sda [SAT], is SMART capable. Adding to "monitor" list.
Device: /dev/sda [SAT], state read from /var/lib/smartmontools/smartd.Samsung_SSD_860_PRO_1TB-S5G8NS0NB01379X.ata.state
Device: /dev/sdb, type changed from 'scsi' to 'sat'
Device: /dev/sdb [SAT], opened
Device: /dev/sdb [SAT], Samsung SSD 860 PRO 1TB, S/N:S5G8NS0NB00206K, WWN:5-002538-e30b0cef3, FW:RVM02B6Q, 1.02 TB
Device: /dev/sdb [SAT], found in smartd database 7.3/5528: Samsung based SSDs
Device: /dev/sdb [SAT], enabled SMART Attribute Autosave.
Device: /dev/sdb [SAT], can't monitor Current_Pending_Sector count - no Attribute 197
Device: /dev/sdb [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198
Device: /dev/sdb [SAT], enabled SMART Automatic Offline Testing.
Device: /dev/sdb [SAT], is SMART capable. Adding to "monitor" list.
Device: /dev/sdb [SAT], state read from /var/lib/smartmontools/smartd.Samsung_SSD_860_PRO_1TB-S5G8NS0NB00206K.ata.state
Device: /dev/sdc, type changed from 'scsi' to 'sat'
Device: /dev/sdc [SAT], opened
Device: /dev/sdc [SAT], TOSHIBA HDWE140, S/N:708BK08NFBRG, WWN:5-000039-a2bc00405, FW:FP1R, 4.00 TB
Device: /dev/sdc [SAT], found in smartd database 7.3/5528: Toshiba X300
Device: /dev/sdc [SAT], enabled SMART Attribute Autosave.
Device: /dev/sdc [SAT], enabled SMART Automatic Offline Testing.
Device: /dev/sdc [SAT], is SMART capable. Adding to "monitor" list.
Device: /dev/sdc [SAT], state read from /var/lib/smartmontools/smartd.TOSHIBA_HDWE140-708BK08NFBRG.ata.state
Device: /dev/nvme0, opened
Device: /dev/nvme0, Samsung SSD 980 PRO 250GB, S/N:S5GZNG0N921943P, FW:1B2QGXA7, 250 GB
Device: /dev/nvme0, is SMART capable. Adding to "monitor" list.
Device: /dev/nvme0, state read from /var/lib/smartmontools/smartd.Samsung_SSD_980_PRO_250GB-S5GZNG0N921943P.nvme.state
Monitoring 3 ATA/SATA, 0 SCSI/SAS and 1 NVMe devices

Next scheduled self tests (at most 5 of each type per device):
Device: /dev/nvme0, will do test 1 of type S at Fri May 22 12:56:34 2026 +05
Device: /dev/sda [SAT], will do test 1 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 1 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 1 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/nvme0, will do test 2 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/nvme0, will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 2 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 2 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 2 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/nvme0, will do test 3 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 3 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 3 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 3 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/nvme0, will do test 4 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 4 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 4 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 4 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/nvme0, will do test 5 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 5 of type S at Wed May 27 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 5 of type S at Wed May 27 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 5 of type S at Wed May 27 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/nvme0, will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/nvme0, will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/nvme0, will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05
Device: /dev/nvme0, will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05

Totals [Fri May 22 12:26:34 2026 +05 - Thu Aug 20 12:26:34 2026 +05]:
Device: /dev/sda [SAT], will do  13 tests of type L
Device: /dev/sda [SAT], will do  90 tests of type S
Device: /dev/sda [SAT], will do   0 tests of type C
Device: /dev/sda [SAT], will do   0 tests of type O
Device: /dev/sdb [SAT], will do  13 tests of type L
Device: /dev/sdb [SAT], will do  90 tests of type S
Device: /dev/sdb [SAT], will do   0 tests of type C
Device: /dev/sdb [SAT], will do   0 tests of type O
Device: /dev/sdc [SAT], will do  13 tests of type L
Device: /dev/sdc [SAT], will do  90 tests of type S
Device: /dev/sdc [SAT], will do   0 tests of type C
Device: /dev/sdc [SAT], will do   0 tests of type O
Device: /dev/nvme0, will do  13 tests of type L
Device: /dev/nvme0, will do  91 tests of type S
Device: /dev/nvme0, will do   0 tests of type C
Device: /dev/nvme0, will do   0 tests of type O

The output displays:

  • scheduled SMART tests,
  • test types,
  • execution times,
  • planned runs for upcoming months.

Usually the schedule is shown approximately 3 months ahead.

Ensure:

  • Short tests run daily,
  • Long tests follow the expected schedule,
  • execution times are correct,
  • no conflicting rules exist.

0040_Linux_GRUB

grub rescue> shows if GRUB can`t find its configuration (grub.cfg) or its modules.

It happens if:

  • Move or delete the /boot partition
  • Disk`s UUID changed
  • Trouble with MBR or UFI

Common commands grub rescue>:

  • ls – shows disks and partitions (hd0) (hd0,msdos1)
  • set – shows or changes (prefix, root)
  • set root=(hd0,msdos1) – there are must be folders /var, /opt, /etc, /proc ….
  • set prefix=(hd0,msdos1)/boot/grub – grub config and modules
  • insmod normal – load a module normal
  • normal – go to the grub menu
#Example
ls
set root=(hd0,msdos1)
set prefix=(hd0,msdos1)/boot/grub
insmod normal
normal

If it’s correct, then the grub menu shows up.

grub> it is a CLI GRUB and it shows:

  • Then “c” was pressed
  • The grub menu can`t be found, but modules were loaded

Here are more commands than in the grub rescue mode. You can manually load a kernel. 

#Example
ls
set root=(hd0,msdos1)
linux /boot/vmlinuz-6.8.0 root=/dev/sda1 ro
initrd /boot/initrd.img-6.8.0
boot

GRUB: BIOS and UEFI recovery

General algorithm:

  1. Boot from LiveCD/LiveUSB Linux (Ubuntu, Debian, etc.).
  2. Determine where the system root and EFI partition are (for UEFI): lsblk,fdisk -l
  3. Mount the system.
  4. Make a chroot into the installed system.
  5. Reinstall GRUB and update the configuration.
  6. Reboot.

 

#Example for BIOS (Legacy)
# Use LiveCD/LiveUSB Linux 
# Find the "/" 
lsblk
fdisk -l
sudo mount /dev/sdXY /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

#
sudo chroot /mnt

#
grub-install /dev/sdX
update-grub

#
exit
#
sudo umount /mnt/dev /mnt/proc /mnt/sys
sudo umount /mnt
reboot
#Example for UEFI
# Use LiveCD/LiveUSB Linux 
# Find the "/" 
lsblk
fdisk -l
sudo mount /dev/sdXY /mnt

# 100–500 MB, type EFI System Partition
sudo mount /dev/sdXZ /mnt/boot/efi

#
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

#
sudo chroot /mnt

#
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
update-grub

#
exit

#
sudo umount /mnt/dev /mnt/proc /mnt/sys
sudo umount /mnt/boot/efi
sudo umount /mnt
reboot
#Auto-repair (boot-repair)

sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt update
sudo apt install -y boot-repair
boot-repair

0014_tmux

To activate the mouse support

nano ~/.tmux.conf

add:

set-option -g -q mouse on
bind-key -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind-key -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; send-keys -M"

Install. More information here

# Debian / Ubuntu Linux:
apt install tmux

# RHEL / CentOS Linux:
yum install tmux

# Fedora:
dnf install tmux

0015_progress

The progress utility for tracking command execution on Linux.

Can track process: cp, mv, dd, tar, bsdtar, cat, rsync, scp, grep, fgrep, egrep, cut, sort, md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, adb, gzip, gunzip, bzip2, bunzip2, xz, unxz, lzma, unlzma, 7z, 7za, zip, unzip, zcat, bzcat, lzcat, coreutils, split, gpg.

# Debian / Ubuntu Linux:
sudo apt install progress

# RHEL / CentOS Linux:
sudo yum install progress

# Fedora 22+:
sudo dnf install progress

# Alternative 
git clone https://github.com/Xfennec/progress.git
cd progress
make
sudo make install

Split a console using tmux or open another session. In the first console, run a command; in the second, run a command progress -w. You will see the progress of the process at the time of running the command.

If you want to see progress in real-time, add ‘& progress -mp $!‘ at the end of the command.

Example:

cp ubuntu-23.04-desktop-amd64.iso /home/user/Downloads/ & progress -mp $!

Some definitions:

& – is the character at the end of the cp command that indicates to run it in the background;
-m  – is a progress option that starts a cycle that will continue as long as the monitored processes remain active;
-p  – is an option that allows you to specify the process to be tracked;
$!  – is a special shell variable representing the PID of the last background process, in this case, the cp command.

On Linux, commands can be executed in parallel. Using the progress utility, you can track the work of all available commands at once. For example, let’s run three file copying operations and use the watch tool as an argument for which we specify the progress q command.

Example:

# update time is 2 seconds
watch progress -q
# update time is every 1 second
watch -n 1 progress -q

I prefer to split a console by using tmux. I run watch -n 1 progress -q in the bottom console and run commands at the top console by adding & at the end of each command, and processes still work in the background. Depending on permissions, you have to use sudo. 

Example:

0008_How to send a message to Telegram a user and a group

First of all, you need to get a Telegram-Bot Token. How to do it here.

It’s hot to find out Chat ID is here.

The official FAQ is here.

 

The bot`s code is below.

#!/bin/bash
# A connection configuration
SSH_KEY="YOUR-SSH-KEY"
USER="USER NAME"
SERVER=<IP ADDRESS OR FQDN OF YOUR SERVER>

# A token and a Chat ID
TOKEN="YOUR TOKEN"
CHAT_ID="YOUR CHAT ID"

# A log`s folder and a log file
LOG_DIR="$(dirname "$0")/logs"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/${DATE}_YOUR-SCRIPT-NAME.log"

# Get the date in format dd:mm:YYYY
DATE=$(date +"%d_%m_%Y")


# A message to send
MESSAGE=$(ssh -n -i "$SSH_KEY" "$USER@$SERVER" <COMMAND ON YOUR REMOTE SERVER>)

# Send a message
curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \
     -d chat_id="$CHAT_ID" \
     -d text="$MESSAGE"