特殊:Badtitle/NS100:Smartmontools
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/Smartmontools }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/af | • {{#if: UbuntuHelp:Smartmontools|Afrikaans| [[::Smartmontools/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ar | • {{#if: UbuntuHelp:Smartmontools|العربية| [[::Smartmontools/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/az | • {{#if: UbuntuHelp:Smartmontools|azərbaycanca| [[::Smartmontools/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/bcc | • {{#if: UbuntuHelp:Smartmontools|جهلسری بلوچی| [[::Smartmontools/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/bg | • {{#if: UbuntuHelp:Smartmontools|български| [[::Smartmontools/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/br | • {{#if: UbuntuHelp:Smartmontools|brezhoneg| [[::Smartmontools/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ca | • {{#if: UbuntuHelp:Smartmontools|català| [[::Smartmontools/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/cs | • {{#if: UbuntuHelp:Smartmontools|čeština| [[::Smartmontools/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/de | • {{#if: UbuntuHelp:Smartmontools|Deutsch| [[::Smartmontools/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/el | • {{#if: UbuntuHelp:Smartmontools|Ελληνικά| [[::Smartmontools/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/es | • {{#if: UbuntuHelp:Smartmontools|español| [[::Smartmontools/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/fa | • {{#if: UbuntuHelp:Smartmontools|فارسی| [[::Smartmontools/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/fi | • {{#if: UbuntuHelp:Smartmontools|suomi| [[::Smartmontools/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/fr | • {{#if: UbuntuHelp:Smartmontools|français| [[::Smartmontools/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/gu | • {{#if: UbuntuHelp:Smartmontools|ગુજરાતી| [[::Smartmontools/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/he | • {{#if: UbuntuHelp:Smartmontools|עברית| [[::Smartmontools/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/hu | • {{#if: UbuntuHelp:Smartmontools|magyar| [[::Smartmontools/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/id | • {{#if: UbuntuHelp:Smartmontools|Bahasa Indonesia| [[::Smartmontools/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/it | • {{#if: UbuntuHelp:Smartmontools|italiano| [[::Smartmontools/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ja | • {{#if: UbuntuHelp:Smartmontools|日本語| [[::Smartmontools/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ko | • {{#if: UbuntuHelp:Smartmontools|한국어| [[::Smartmontools/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ksh | • {{#if: UbuntuHelp:Smartmontools|Ripoarisch| [[::Smartmontools/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/mr | • {{#if: UbuntuHelp:Smartmontools|मराठी| [[::Smartmontools/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ms | • {{#if: UbuntuHelp:Smartmontools|Bahasa Melayu| [[::Smartmontools/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/nl | • {{#if: UbuntuHelp:Smartmontools|Nederlands| [[::Smartmontools/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/no | • {{#if: UbuntuHelp:Smartmontools|norsk| [[::Smartmontools/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/oc | • {{#if: UbuntuHelp:Smartmontools|occitan| [[::Smartmontools/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/pl | • {{#if: UbuntuHelp:Smartmontools|polski| [[::Smartmontools/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/pt | • {{#if: UbuntuHelp:Smartmontools|português| [[::Smartmontools/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ro | • {{#if: UbuntuHelp:Smartmontools|română| [[::Smartmontools/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/ru | • {{#if: UbuntuHelp:Smartmontools|русский| [[::Smartmontools/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/si | • {{#if: UbuntuHelp:Smartmontools|සිංහල| [[::Smartmontools/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/sq | • {{#if: UbuntuHelp:Smartmontools|shqip| [[::Smartmontools/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/sr | • {{#if: UbuntuHelp:Smartmontools|српски / srpski| [[::Smartmontools/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/sv | • {{#if: UbuntuHelp:Smartmontools|svenska| [[::Smartmontools/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/th | • {{#if: UbuntuHelp:Smartmontools|ไทย| [[::Smartmontools/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/tr | • {{#if: UbuntuHelp:Smartmontools|Türkçe| [[::Smartmontools/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/vi | • {{#if: UbuntuHelp:Smartmontools|Tiếng Việt| [[::Smartmontools/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/yue | • {{#if: UbuntuHelp:Smartmontools|粵語| [[::Smartmontools/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/zh | • {{#if: UbuntuHelp:Smartmontools|中文| [[::Smartmontools/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/zh-hans | • {{#if: UbuntuHelp:Smartmontools|中文(简体)| [[::Smartmontools/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Smartmontools | UbuntuHelp:Smartmontools | {{#if: | :}}Smartmontools}}/zh-hant | • {{#if: UbuntuHelp:Smartmontools|中文(繁體)| [[::Smartmontools/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:Smartmontools|:Smartmontools|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Smartmontools/zh | | {{#ifexist: Smartmontools/zh | | {{#ifeq: {{#titleparts:Smartmontools|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Smartmontools|1|-1|}} | zh | | }}
This how to will help you to configure Smartmontools to do actions as shut down the computer or send an e-mail when the disk is going to fail.
Prerequisites
- A modern hard disk S.M.A.R.T. capable
Installation
First of all, we have to install Smartmontools package. Install the smartmontools
package in the Synaptic Package Manager. See UbuntuHelp:SynapticHowto.
To display all the SMART information for an IDE drive, run
sudo smartctl -a /dev/hda
To display all the SMART information for a SATA drive, run
sudo smartctl -a -d ata /dev/sda
Note: This also works for IDE drives in new kernels that are being run through the SCSI stack and show up as /dev/sdX
Now we have to edit some files. Open the file /etc/default/smartmontools
with your favourite text editor, for example, vim: sudo vim /etc/default/smartmontools
an uncomment the line start_smartd=yes
Then, we are going to edit the daemon configuration. Again, use your favourite text editor to open the file /etc/smartd.conf
. Comment out the line that contains DEVICESCAN
, by adding # in the beginning of the line. Then, add this to the end of the file:
/dev/hda \ -H \ -l error -l selftest \ -s (O/../../5/11|L/../../5/13|C/../../5/15) \ -m ThisIsNotUsed -M exec /usr/local/bin/smartd.sh
You must replace /dev/hda
with the name of the device which you'd like to be monitored.
With this, the daemon will check the disk from time to time, and will execute /usr/local/bin/smartd.sh
if any error is encountered.
Now, we are going to make the script which is going to shut down the computer. Create a text file called smartd.sh
in /usr/local/bin/
(you could use the command sudo vim /usr/local/bin/smartd.sh
to do so) and add the following to the file:
#!/bin/bash LOGFILE="/var/log/smartd.log" echo -e "$(date)\n$SMARTD_MESSAGE\n" >> "$LOGFILE" mail admin[at]alcalleop[dot]net < $LOGFILE sleep 40s shutdown -h now
This will send the log file by e-mail to admin[at]alcalleop[dot]net, wait 40 seconds and then will shut down the computer. You can customize the script to change what the computer will do in a case of disk error. For example, perhaps you do not want the computer to shut down.
Now, it is time to start the daemon: sudo /etc/init.d/smartmontools start
If you want to test all of this, add -M test
after -M exec /usr/local/bin/smartd.sh
and restart the daemon. This will force daemon to execute the script immediately. Now, every time the computer is turned on, the script will shut down the computer, so you will have to start the computer in recovery mode and remove -M test
option of /etc/smartd.conf
file.
Based on Gentoo Wiki: HOWTO Monitor your hard disk(s)withsmartmontools.
Before running this, be sure to check that you have a "mail" command, and do a test first to your address. On my default Fiesty:
jim@beorn:~$ mail
The program 'mail' can be found in the following packages:
- mailx
- mailutils
Try: sudo apt-get install <selected package>
Make sure you have the 'universe' component enabled
bash: mail: command not found