Jump to content

Smartmontools: Difference between revisions

From Official NixOS Wiki
Ardenet (talk | contribs)
mNo edit summary
added "Detecting devices automatically" section
 
Line 33: Line 33:
}
}
</nowiki>}}
</nowiki>}}
<translate>
== Detecting devices automatically ==
Instead of listing every device explicitly, smartd can be configured to automatically look for and monitor all detected disks by enabling {{Nixos:option|services.smartd.autodetect}}. This is equivalent to adding a <code>DEVICESCAN</code> entry to a <code>smartd.conf</code> file.
Options applied to devices found this way can be adjusted with {{Nixos:option|services.smartd.defaults.autodetected}}. '''Most of the time you do not need to change this''' because the default option already checks every attribute on the disk.
</translate>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>{
  services.smartd = {
    enable = true;
    autodetect = true;
  };
}
</nowiki>}}


<translate>
<translate>

Latest revision as of 10:32, 21 September 2026

smartmontools is a package which provides tools for monitoring drives which support the S.M.A.R.T. system for monitoring hard drive health.

It includes the smartd and smartctl programs. smartd can be enabled on NixOS systems with the services.smartd module.

Locating devices

It is important to use persistent methods of identification for disks, as device nodes are arbitrary and subject to change. The following command will print a list of storage devices, as well as partitions contained on them. When configuring smartd, you should use entries that are not suffixed with "-partX", as they refer to whole disks.

ls /dev/disk/by-id/

Example

❄︎ /etc/nixos/configuration.nix
{
  services.smartd = {
    enable = true;
    devices = [
      {
        device = "/dev/disk/by-id/ata-WDC-XXXXXX-XXXXXX"; # FIXME: Change this to your actual disk
      }
    ];
  };
}

Detecting devices automatically

Instead of listing every device explicitly, smartd can be configured to automatically look for and monitor all detected disks by enabling services.smartd.autodetect. This is equivalent to adding a DEVICESCAN entry to a smartd.conf file.

Options applied to devices found this way can be adjusted with services.smartd.defaults.autodetected. Most of the time you do not need to change this because the default option already checks every attribute on the disk.

❄︎ /etc/nixos/configuration.nix
{
  services.smartd = {
    enable = true;
    autodetect = true;
  };
}