SSDs with Linux

Here are some good recommendations:

Recommendations:

  1. Add noatime to the fstab options (nodiratime is redundant)
  2. Have enough ram to not need a swap drive
  3. Trim (the default weekly cron job no good if computers are switched off)
    • edit /etc/rc.local and append fstrim -v / (and for any other SSD mount points except swap)
    • or fstrim -a see here
  4. Put /tmp and /var/log into RAM
    • not that the size option is to stop it taking over too much RAM and can be in Mb, e.g. 50M.
    • after adding the lines below to /etc/fstab, test with sudo mount -a
# SSD tweak : temporary directories as tmpfs
tmpfs /tmp tmpfs defaults,noatime,mode=1777,size=20% 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0

# SSD tweak : log directory as tmpfs
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /var/lock tmpfs defaults,noatime,mode=0755 0 0
tmpfs   /dev/shm        tmpfs   defaults,size=20%       0 0

Other possibilities

  • moving Firefox & Chrome cache to RAM

For situations where there is a real HD present

  • Move the folowing to the HD:
    swap
    home tmp dev/shm var/tmp var/spool var/log var/lock

Steps

  1. Install OS with no LVM, on separate partitions for /boot, /, /home and /var, with no swap
    • Make sure system boots ok
  2. Format HD with at least three partition: swap, /home and /hd (I made /hd 10GB xfs)
  3. Create mountpointa /hd & /hometmp - mkdir /hd; mkdir /hometmp
  4. Get the UUID’s with: ls -l /dev/disk/by-uuid
  5. Modify /etc/fstab
    • Add noatime to SSD entries
    • Mount /hd and activate swap
#/dev/sdb3
UUID=db9908b0-b762-43bc-bade-bff060d5d2ad  swap  swap    defaults        0 0
#/dev/sdb2
UUID=5717e073-0576-4ae6-b519-35404f16806e /hd    xfs     defaults        1 2
#sdb vg:sv7
/dev/sv7/home /hometmp    ext4     defaults        1 2
  1. Test it out:
mount -a
swapon -a
cat /proc/swaps #check swap
swapoff <if original swap>
  1. Boot from a live CD and move directories from the SSD to the HD:
mount /dev/sda2 /mnt
mkdir /ohome; mount /dev/sda3 /ohome
mkdir /nhome; mount /dev/sv7/home /nhome
cp -a /ohome/* /nhome/
  • edit /mnt/etc/fstab to disable the old home and mount the new one as /home
  • now bind specific folders to the HD
mkdir /hd; mount /dev/sdb2 /hd
dir=var/log;   mv /mnt/$dir /hd/; mkdir /mnt/$dir
dir=var/tmp;   mv /mnt/$dir /hd/; mkdir /mnt/$dir
dir=var/spool; mv /mnt/$dir /hd/; mkdir /mnt/$dir
dir=var/lock;  mv /mnt/$dir /hd/; mkdir /mnt/$dir
dir=dev/shm;   mv /mnt/$dir /hd/; mkdir /mnt/$dir
dir=tmp;       mv /mnt/$dir /hd/; mkdir /mnt/$dir
  • Now add the following to /etc/fstab
/hd/var/log   /var/log   none bind 0 0
/hd/var/tmp   /var/tmp   none bind 0 0
/hd/var/spool /var/spool none bind 0 0
/hd/var/lock  /var/lock  none bind 0 0
/hd/dev/shm   /dev/shm   none bind 0 0
/hd/tmp       /tmp       none bind 0 0
  1. Add the following cron job: vi /etc/cron.daily/trim
#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /root >> $LOG
  • Then: sudo chmod +x /etc/cron.daily/trim