[ Prev ] [ Index ] [ Next ]

SSD

Created søndag 23 oktober 2016


Some tools and configuration for Disk optimization.



I/O Top

# Follow what, and how often, an application writes to the disk.
$ pacman -S iotop


# invoke it with
$ iotop -boqqq



Smartmontools

# smartmontools can be used to monitor disk health state through the S.M.A.R.T monitoring
$ pacman -S smartmontools


# The SMART monitoring is probably already running,
# but we wan't to exclude SCSI commands since we are on a ATA device
$ smartctl --smart=on --device=ata /dev/sda


Usage

# You can get the devices connected with; lsblk
# Get some device information - change X accordingly throughout
$ smartctl -i /dev/sdX


Daemon

# smartd can automatically run test and notify is issues is reported
# This requires you to have setup Dunst (notifications) and the SSMTP (mail)
# Enable the Daemon service file
$ systemctl enable smartd.service


# The configuration file is stored in /etc/smartd.conf
# Only 1 line will be outcommented - comment this line and define this line instead

/dev/sda -a -n standby,q -W 4,35,45 -s (S/../.././02|L/../../6/03) -m jeppesen@tutanota.com -M /usr/local/bin/smartnotify

# The above line will monitor on sda (change accordingly)

-a = all errors
-n = disable checking if disk is in standby
-W = alert on temperature too.
It will log on 4degree change and 35degree hit, and alert at 45degree
-s = scheduled self test, each day between 2-3am, and Saturdays between 3-4am
-m = send mail to this address - change accordingly
-M = execute this script (notification and mail content)


# Copy this script to /usr/local/bin/smartnotify
# Change the user and userId (stick and 1000) accordingly. You can get userId with; id

#! /bin/sh

# Send mail      
echo "$SMARTD_MESSAGE" | mail -s "$SMARTD_FAILTYPE" "$SMARTD_ADDRESS"

# Notify user                                                        
wall "$SMARTD_MESSAGE"

# Desktop notification
sudo -u stick DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "S.M.A.R.T Error ($SMARTD_FAILTYPE)" "$SMARTD_MESSAGE" -u critical --icon=dialog-warning


# And make it executable
$ chmod +x /usr/local/bin/smartnotify


Test the disk (safe)

# You can see what tests your disk is capable to run
$ smartctl -c /dev/sdX


# The above (in my case) might produce something like

Short self-test routine
recommended polling time: ( 2) minutes.
Extended self-test routine
recommended polling time: ( 10) minutes.


# So here we are able to test with Short and Extended - it also shows how long the test will take^
# The Short test should catch most error
$ smartctl -t short /dev/sdX


# This will start the test in the background.
# You'll have to wait x-minutes (2min ex, will be posted) to see the result.
# Once time has elapsed, you can view the health result with
$ smartctl -H /dev/sdX


# To view recent reports
$ smartctl -l selftest /dev/sdX


# Or a more verbose report
$ smartctl -a /dev/sdX


# If the report show Failing Health Status, it has already failed or predicted within 24hours
# Make a backup asap^



TRIM

# Trim is used for sustained long term performance and wear-leveling.
# Your SSD supports TRIM. To verify TRIM support for a SSD
$ hdparm -I /dev/sda | grep TRIM


# Enable the fstrim.timer service for TRIM to take place once a week
$ systemctl enable fstrim.timer


# Change value in LVM;
# Edit /etc/lvm/lvm.conf and change the value of issue_discards from 0 to 1



Fstab atime options

# Edit the /etc/fstab to change the atime options - which writes time to a file every time it's read.
# Change the <option> line for each of the partitions. A <option> field may look like the following

rw,realtime,discard,data=ordered


# atime options :

realtime = Writes changes depending on previous access time was earlier than last modify time.
noatime = Do not allow time writes to a file.



Reduce swap writes

# Swappiness determines how happy you are with writing from the RAM to swap partition.
# Default is 60.
# To see current swappiness value
$ cat /proc/sys/vm/swappiness


# Add a sysctl configuration file
# Add and edit a file, /etc/sysctl.d/99-sysctl.conf and add the following

vm.swappiness=10



Kernel Parameters

# To add kernel parameters, edit /etc/default/grub and add to the GRUB_CMDLINE_LINUX_DEFAULT=
# Ex. GRUB_CMDLINE_LINUX_DEFAULT="quiet splash parameter1 parameter2"


# Grub needs to generate a new configuration file afterwords
$ grub-mkconfig -o /boot/grub/grub.cfg


Enable zswap

# Compresses and stores swap cache in RAM, instead of writing it to the disk.

GRUB_CMDLINE_LINUX_DEFAULT="zswap.enabled=1"