Solid State Drive SSD Write Minimization
I built mine to run off Compact Flash:
(These are my ideas - they are not exact steps to follow!)
=========================
1. Stop writing to the disk for every read: Edit your fstab to mount the partitions with "noatime" (add noatime to /etc/fstab). You can also change the journal flush interval time by using the mount option "commit=xx", for example, to change it from the default 5 seconds to 60 seconds. In CentOS the initrd mounts your root filesystem, not the kernel. So, the steps to enable ext3's writeback on CentOS mode are:
a. Add "noatime,data=writeback,commit=90" to /etc/fstab;
b. Run mkinitrd; and
c. update grub.conf to point to the new initrd image if you changed the name.
nano -w /etc/fstab
fstab should look like this:
LABEL=/ / ext3 defaults,noatime,data=writeback,commit=90 1 1
LABEL=/boot /boot ext3 defaults,noatime,data=writeback,commit=90 1 2
tmpfs /dev/shm tmpfs defaults 0 0
tmpfs /var/log tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
Then run mkinitrd. If you do keep the same name you can skip the grub step below because we recreate the same .img file:
# mv /boot/initrd-2.6.18-53.1.4.el5.img /boot/initrd-2.6.18-53.1.4.el5.img.old
# mkinitrd initrd-2.6.18-53.1.4.el5.img 2.6.18-53.1.4.el5
-----------
If you changed the initrd file name then change grub.conf
nano -w /etc/grub.conf
Change the initrd img file to match like this:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
title trixbox (2.6.18-53.1.4.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-53.1.4.el5 ro root=LABEL=/
initrd /initrd-“what you named it”.img
2. Run dmesg to see if it worked. You should see:
…
EXT3 FS on sda2, internal journal
kjournald starting. Commit interval 90 seconds
EXT3 FS on sda1, internal journal
EXT3-fs: mounted filesystem with writeback data mode.
…
3. Don't use a swap partition. I have 2gb of RAM which should be enough # swapoff –a
4. Don’t use a journaling file system on the SSD partitions. Ext2 would be recommended in this situation. I blew this off because I felt I could optimize Ext3 well enough.
5. Try a USB drive. Create 2 partitions on it. Format one as swap and one as ext2 add the appropriate lines to fstab. Such as:
/dev/sda1 swap defaults 0 0
/dev/sda2 /var/log ext2 defaults 0 0
If it wears out just get another!
6. Don’t log to the SSD. Mounting /var/log/ as a tmpfs will reduce the amount of writes used by logging, however it is highly advised that you modify the shutdown scripts to copy the logs to a safe before turning off, so you don't lose them permanently (they are useful!). There is no generic way to do this as different systems use different init daemons... but it would be best to start looking at /etc/inittab and see what script is called for shutdown. That gives you an idea of where to put the extra commands.
Code:
mkdir /backup_logs
7. Create the startup/shutdown script for backing up the logs (create a new file using
nano /etc/init.d/logbak
Code:
#!/bin/bash
#
# chkconfig: 2345 9 92
# description: Backup the log files and restore them
#
initdir=/etc/init.d
RETVAL=0
LOCKFILE=/var/lock/subsys/logbak
case "$1" in
stop)
echo "Called with $1"
echo "Copying log files to /backup_logs"
cp -Rpfu /var/log/* /backup_logs/
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
;;
start)
echo "Called with $1"
echo "Copying log files to /var/log"
cp -Rpfu /backup_logs/* /var/log/
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCKFILE
;;
*)
echo 'Usage: /etc/init.d/logbak {start||stop}'
exit 1
;;
esac
exit $RETVAL
Change the permissions and run it:
Code:
chmod 775 /etc/init.d/logbak
/etc/init.d/logbak stop
Now install it with:
cd /etc/init.d
chkconfig -–add logbak