Tag Archives: linux

smartd Settings on a CentOS Server

smartd is a great tool to keep track of the health status of your server disks. It tracks the S.M.A.R.T records on specified periods and warns you in case anything goes wrong. Even though it is quiet simple, people can get lost while setting up their configuration. Here I’ll explain how my generic settings go. Keep in mind that this is for CentOS servers.

To install the service, simply get the smartmontools package via yum. This will also install mailx if isn’t already installed.

yum install smartmontools -y

Now a file named /etc/smartd.conf will be created. This is where we tell smartd what to do. First, learn the names of your devices using fdisk.

root@eaVT:~# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006f1aa

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   943237119   471617536   83  Linux
/dev/sda2       943239166   976771071    16765953    5  Extended
/dev/sda5       943239168   976771071    16765952   82  Linux swap / Solaris

This output tells that I have one physical disk (/dev/sda) with three partitions (/dev/sda1, /dev/sda2, /dev/sda3). But we are only interested in the physical devices, which means smartd will only deal with /dev/sda.

Open /etc/smartd.conf using your favourite (vi?) text editor. Find the line that says
and comment it out. Then add this line
DEVICESCAN -S on -o on -a -m youremail@yourdomain.com -s (S/../.././02|L/../../0603) -M test
The result should look like this:

# The word DEVICESCAN will cause any remaining lines in this
# configuration file to be ignored: it tells smartd to scan for all
# ATA and SCSI devices.  DEVICESCAN may be followed by any of the
# Directives listed below, which will be applied to all devices that
# are found.  Most users should comment out DEVICESCAN and explicitly
# list the devices that they wish to monitor.
#DEVICESCAN -H -m root
DEVICESCAN -S on -o on -a -m youremail@yourdomain.com -s (S/../.././02|L/../../0603) -M test

Of course, don’t forget to replace it with your own email address. After this simply restart smartd service.

service smartd restart

Now wait for a while and check your email. According to my personal experience, it takes around 5-10 minutes to receive it. You will get a TEST email that says your disks have error. Now that we’ve established you can get the email when an error occurs, lets set it up to a real case.

Go back to /etc/smartd.conf and uncomment the line starting with DEVICESCAN. Don’t forget that there shouldn’t be any line starting with DEVICESCAN on this file, otherwise smartd will halt reading the conf file after it.

Now add the following lines to the /etc/smartd.conf

/dev/sda -H -C 0 -U 0 -m youremail@yourdomain.com
/dev/sda -d scsi -s L/../../1/01 -m youremail@yourdomain.com

Of course, replace the /dev/sda and email address according to yours.

The first line tells smartd to run a silence check on the /dev/sda disk and email us on any error.
The second line indicates that a long check will be made every Monday and 1 a.m. and on any error it will be mailed to us. If we wanted to make the test every Sunday at 6 p.m. the setting would have been L/../../7/18 -m youremail@yourdomain.com

If you’d like to add a new disk, (for example /dev/sdb) simply add it as a new line.

/dev/sda -H -C 0 -U 0 -m youremail@yourdomain.com
/dev/sda -d scsi -s L/../../1/01 -m youremail@yourdomain.com
/dev/sdb -H -C 0 -U 0 -m youremail@yourdomain.com
/dev/sdb -d scsi -s L/../../1/01 -m youremail@yourdomain.com

Now save the file and restart the service again.

service smartd restart

Normally, it is possible that the service won’t get started on reboot. You must add it with chkconfig in order to run it automatically in a CentOS box. To check it:

[root@emre ~]# chkconfig --list |grep smartd
smartd         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@emre ~]# chkconfig smartd on
[root@emre ~]# chkconfig --list |grep smartd
smartd             0:off    1:off    2:on    3:on    4:on    5:on    6:off

This means that it will run on user levels 2, 3, 4 and 5. What this means is a different story.

So that’s it for now.

Importing Large MySQL Files With phpMyAdmin

It may not be possible to import large SQL files using phpMyAdmin due to it’s uploading limits.
Sometimes this is related to your php.ini settings, but no always.

You can always use the old reliable method of importing sql files from the command line. Or upload to file to server and tell phpMyAdmin to look for that file specifically.

MySQL Command Line Option

Of course, we need to upload the file first. Below, the 1st line is to achieve this. After that we connect to our server via ssh, and then (on the 2nd line) import the sql file.

scp the_sql_file.sql root@myserver.com:/path/to/upload
mysql -u username -p -h localhost DATABASE-NAME < the_sql_file.sql

Here, the MySQL connection is established using a username and password. If you simple create a .my.cnf file in order to get automatic connections, you won’t need all these. Simply create a file to /root/.my.cnf (or any other user directory you want to)


From now on, you don’t need to use the -u and -p arguments when using mysql, if this file exists at the user’s home directory you’re logged on as, than it will automatically pass them. It may seem insecure, but the /root folder is only accessed by the root anyway, even though it is not a good idea to keep passwords clear text, if your /root folder is compromised, you’re in big trouble anyway. And keep in mind that we usually have to keep MySQL passwords a cleartexts in scripts all the time.

Using phpMyAdmin to Import the SQL File

You can set a default folder for phpMyAdmin to check for uploaded files. This way, if you place a file into this folder, you can easily choose to import it. Find where your config.inc.php file is. If you don’t know where, try the locate command (if it is installed). Open the file and find the $cfg[‘UploadDir’] section. Update it as below

$cfg['UploadDir'] = 'imports';

Now, phpMyAdmin will check the “imports” folder directly. So we need a folder like that. On your terminal, create the folder.

mkdir /path/to/phpmyadmin/imports

Now upload your sql files here.

scp /path/to/the_sql_file.sql root@myserver.com:/path/to/phpmyadmin/imports

Change the owner and group of the imports folder. First check who owns the phpmyadmin folder. Let’s say it is called webapp,

chown -R webapp:webapp /path/to/phpmyadmin/imports

Ok. Now use your browser and access phpmyadmin, at the import db seciton you’ll see a dropdown menu that wasn’t there before. There you’ll see the files inside the “imports” folder. Even though they are larger than the phpmyadmin upload limits, they’ll get imported.

Quota Problems With DirectAdmin

I see this is a very common problem. Sometimes people get an error on their IMAP webmail connection and checking the log files at /var/log/maillog there’s an error indicating the disk quota for that user.

Jul 2 11:08:51 mail dovecot[1227]: imap(mailaccount@somedomain.com): Error: user mailaccount@somedomain.com: Initialization failed: Initializing mail storage from mail_location setting failed: mkdir(/home/someuser/imap/somedomain.com/mailaccount/Maildir) failed: Disk quota exceeded

The generally people claim that playing around with the disk quota of the user helps it. Interestingly in my case, only setting the quota to “Unlimited” solved the problem. So keep that in mind.
It seems like the reason behind this error is that dovecot used to handle quotas using the /var directory, but now switched it to the /home directory.

Also if somehow your system starts reading quotas wrong, don’t forget to use this little tip : http://www.directadmin.com/features.php?id=529

echo “action=rewrite&value=quota” >> /usr/local/directadmin/data/task.queue

This command will go through each user, and set the quota limits in the system quotas.  Users will unlmited quotas will also have their quota limit set to 0 (unlimited).

echo “action=rewrite&value=quota&user=bob” >> /usr/local/directadmin/data/task.queue

Same thing, except it’s just sets the quota for one user.


Ubuntu 13.04 Personal Post-Installation Settings

Here’s my to-do list after installing a fresh Ubuntu 13.04. Some of them are probably very personal and you won’t need them, yet it might give an idea.


First of all I edit the settings of gedit.

Edit -> Preferences
View tab : Check “Display line numbers”, “Enable text wrapping”, “Highlight current line” and “Highlight matching brackets”
Editor tab : Set the tab width to 4 and check “Insert spaces instead of tabs” and “Enable automatic indentation”



Next, I install and personalize Geany. I’ve discussed the necessary steps before on this post.


Unfortunately the VI that is shipped with Ubuntu is buggy. I usually replace it with VIM.

$ sudo apt-get install vim

After this, I update the vimrc file to personalize. I’ve talked about it in this post.

Sublime Text Editor

This is another very well designed text editor. I like installing and personalising it. You can find methods to install it in this post. I prefer using Sublime Text 3, and then using the following settings in the configuration file.

    "tab_size": 4,
    "use_tab_stops": true,
    "detect_indentation": true,
    "auto_indent": true,
    "smart_indent": true,
    "highlight_line": false,
    "draw_white_space": "all",


First of all I install the ssh server.

$ sudo apt-get install openssh-server

After this, I simply “ssh localhost” in order to get the ~/.ssh folder created.
After this, I copy my id_rsa and id_rsa.pub files into this folder.
$ chmod 700 ~/.ssh/id_rsa
$ chmod 664 ~/.ssh/id_rsa.pub

If you want, maybe it’s a good idea to change your default ssh server port.
Edit /etc/ssh/sshd_config and change the line below

# What ports, IPs and protocols we listen for
Port 22

If you change the port, you’ll have to restart the ssh server.$ sudo /etc/init.d/ssh restart

After these, I install the PAC-Manager from it’s website : http://sourceforge.net/projects/pacmanager/

Then simply import my old PAC connections.

Browsers and Dropbox

Well, the title speaks for itself. I usually get Chrome, Opera and Dropbox right after the installation.

Aptitude Installations

Downloading GIMP, Restricted-Extras, VLC are usually critical.

$ sudo apt-get install gimp ubuntu-restricted-extras vlc

Getting ffmpeg, avconv, and java plugins is a good idea.

$ sudo apt-get install ffmpeg libav-tools libavformat-extra-53 libavcodex-extra-53 icedtea-7-plugin openjdk-7-jre

Using the right-click menu on nautilus to open a terminal in that folder is very useful.

$ sudo apt-get install nautilus-open-terminal

Below are for the fundamental tools for network geeks.

$ sudo apt-get install nmap mtr filezilla

For monitoring a lot of things, atop is very useful.

$ sudo apt-get install atop

As an astronomer, I use numpy and pyfits for scientific computing a lot.

$ sudo apt-get install python-pyfits python-numpy

If you’re using Skype, it won’t be visible in the system tray, to fix this, install the following package. (discussed here)

$ sudo apt-get install sni-qt:i386

Adjusting rc.local

In order to automatically turn on Numlock at boot, and (on my laptop) remember the brightness setting, I edit the /etc/rc.local file accordingly. The brightness thing is because, my Ubuntu boots with minimum brightness on laptop. Also to turn on automatically, you need to install the numlockx package.

$ sudo apt-get install numlockx

Add these lines to the /etc/rc.local file:

# Numlock enable
[ -x /usr/bin/numlockx ] && numlockx on

#Auto set brightness (change the value "12" for your system)
echo 12 > /sys/class/backlight/acpi_video0/brightness

exit 0

Show Date in Panel

It is good to see the date in the top right corner of the screen at all times.

Click on the clock and follow Time & Date Settings… -> Clock tab -> Check “Date and month” below the “In the clock, show” section.


Import Filters for Thunderbird

Using this addon, you can import your “exported” filters for Thunderbird.

Privacy Settings

I usually edit the privacy settings of the Unity Dash so that it won’t record activity on my multimedia files.

Just type “privacy” to the dash and run the settings. On the “Files” tab, select the type of files you don’t want to be recorded.



Install Google Calendar Indicator

This was discussed in a blog post, if you use Google Calendar, then it’s a good idea to integrate it with your Ubuntu. Check it out here.

Disabling the ALT Key for HUD

Some programs use the ALT key and since the HUDS want to access it, things can get messed up. That’s why I usually disable the hotkey. It was discussed here before. Simply click on the System Settings… Go to “Keyboard -> Shortcuts” select “Key to show the HUD and hit “Backspace” if you want it disabled.

Shortcut for minimizing Windows

While disabling the ALT key for HUD, it’s a good idea to also add the minimization shortcut. While at “Keyboard -> Shortcuts” go to “Windows” and add the key combination you like. I usually prefer “Ctrl +Alt + 0”

Disable Recursive Searching in Nautilus as you Type

For me, this is the most annoying updates of Nautilus. When I want to search for something, recursively, I can either use “find” or “locate” or simply hit “search”. Locating files easily in a folder with nautilus is something I use a lot, that’s why this patch is very handy. Follow the instructions in the link below if you don’t like that feature either.