mirror of
https://github.com/systemd/systemd.git
synced 2026-11-06 05:17:24 +00:00
This adds systemd-report-diskhealth, which reports the key health parameters of NVMe and ATA disks, plus basic identity information about all disks. For all hardware backed disks (including USB ones) size, logical and physical sector size are reported from sysfs, and model, vendor and serial from the udev database, preferring hwdb data, and falling back to the PCI or USB device if the block device itself carries no model/vendor information. For NVMe disks the SMART / Health Information log page is read via the NVMe admin command ioctl, and the critical warning bitmask, available spare, percentage used and media error counter are reported. For ATA disks with SMART enabled the overall SMART status is read via SG_IO ATA pass-through, and for rotating ones also the reallocated, pending and offline uncorrectable sector counts (SMART attributes 5, 197, 198), since various SSD vendors reused these attributes with incompatible semantics. Power-on hours and power cycle counts are reported for both under a common metric name, for ATA disks taken from the standardized Device Statistics log rather than from the vendor specific SMART attributes. ATA disks in standby are not queried, in order not to spin them up, and neither are ATA disks behind USB bridges. The temperature is deliberately not reported, since systemd-report-hwmon covers that already.
48 lines
1.5 KiB
Plaintext
48 lines
1.5 KiB
Plaintext
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
#
|
|
# This file is part of systemd.
|
|
#
|
|
# systemd is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU Lesser General Public License as published by
|
|
# the Free Software Foundation; either version 2.1 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
[Unit]
|
|
Description=Disk Health Report Service
|
|
Documentation=man:systemd-report-diskhealth@.service(8)
|
|
DefaultDependencies=no
|
|
Conflicts=shutdown.target
|
|
Before=shutdown.target
|
|
|
|
[Service]
|
|
# Note that the service needs to run as root, and needs access to the disk device nodes, hence DynamicUser=
|
|
# and PrivateDevices= are not used here. The kernel requires CAP_SYS_ADMIN for the NVMe Get Log Page admin
|
|
# command, and CAP_SYS_RAWIO for ATA pass-through via SG_IO. (PrivateDevices= would drop the latter.)
|
|
CapabilityBoundingSet=CAP_SYS_ADMIN CAP_SYS_RAWIO
|
|
DeviceAllow=block-blkext r
|
|
DeviceAllow=block-sd r
|
|
DevicePolicy=closed
|
|
IPAddressDeny=any
|
|
LockPersonality=yes
|
|
MemoryDenyWriteExecute=yes
|
|
NoNewPrivileges=yes
|
|
PrivateIPC=yes
|
|
PrivateNetwork=yes
|
|
PrivateTmp=disconnected
|
|
ProtectControlGroups=yes
|
|
ProtectHome=yes
|
|
ProtectHostname=yes
|
|
ProtectKernelLogs=yes
|
|
ProtectKernelModules=yes
|
|
ProtectKernelTunables=yes
|
|
ProtectSystem=strict
|
|
RestrictAddressFamilies=AF_UNIX
|
|
RestrictNamespaces=yes
|
|
RestrictRealtime=yes
|
|
RestrictSUIDSGID=yes
|
|
RuntimeMaxSec=1min
|
|
SystemCallArchitectures=native
|
|
SystemCallErrorNumber=EPERM
|
|
SystemCallFilter=@system-service
|
|
ExecStart={{LIBEXECDIR}}/systemd-report-diskhealth
|