个人工具

“UbuntuHelp:Smartmontools”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/Smartmontools}} {{Languages|UbuntuHelp:Smartmontools}} This how to will help you to configure Smartmontools to do actions as shut down the compute...)
 
第10行: 第10行:
 
First of all, we have to install Smartmontools package. Install the <code><nowiki>smartmontools</nowiki></code> package in the Synaptic Package Manager. See [[UbuntuHelp:SynapticHowto]].
 
First of all, we have to install Smartmontools package. Install the <code><nowiki>smartmontools</nowiki></code> package in the Synaptic Package Manager. See [[UbuntuHelp:SynapticHowto]].
  
To display all the SMART information for a disk, run
+
To display all the SMART information for an IDE drive, run
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo smartctl -a /dev/hda
 
sudo smartctl -a /dev/hda
 
</nowiki></pre>
 
</nowiki></pre>
  
 +
 +
To display all the SMART information for a SATA drive, run
 +
<pre><nowiki>
 +
sudo smartctl -a -d ata /dev/sda
 +
</nowiki></pre>
 +
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 <code><nowiki>/etc/default/smartmontools</nowiki></code> with your favourite text editor, for example, vim: <code><nowiki>sudo vim /etc/default/smartmontools</nowiki></code> an uncomment the line <code><nowiki>start_smartd=yes</nowiki></code> Then, we are going to edit the daemon configuration. Again, use your favourite text editor to open the file <code><nowiki>/etc/smartd.conf</nowiki></code>. Comment out the line that contains <code><nowiki>DEVICESCAN</nowiki></code>, by adding # in the beginning of the line. Then, add this to the end of the file:
 
Now we have to edit some files. Open the file <code><nowiki>/etc/default/smartmontools</nowiki></code> with your favourite text editor, for example, vim: <code><nowiki>sudo vim /etc/default/smartmontools</nowiki></code> an uncomment the line <code><nowiki>start_smartd=yes</nowiki></code> Then, we are going to edit the daemon configuration. Again, use your favourite text editor to open the file <code><nowiki>/etc/smartd.conf</nowiki></code>. Comment out the line that contains <code><nowiki>DEVICESCAN</nowiki></code>, by adding # in the beginning of the line. Then, add this to the end of the file:
  
第43行: 第50行:
  
 
Based on [http://gentoo-wiki.com/HOWTO_Monitor_your_hard_disk(s)_with_smartmontools Gentoo Wiki: HOWTO Monitor your hard disk(s)withsmartmontools].
 
Based on [http://gentoo-wiki.com/HOWTO_Monitor_your_hard_disk(s)_with_smartmontools 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
 +
----
 +
[[category:CategoryDocumentation]] [[category:CategoryHardware]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月21日 (三) 18:03的版本


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