在 CentOS 7.x 中使用 SSD

參考網頁:
RHEL7: Extend the life of a SSD. – CertDepot

1. 備份原檔
# cp /etc/fstab /etc/fstab.$(date +%F)
2. 停止每次存取檔案時寫入 timestamp
# vim  /etc/fstab

UUID=ba1f3566-d4af-4abc-93f7-2dde272f8006 /                       xfs     defaults        0 0
修改成
UUID=ba1f3566-d4af-4abc-93f7-2dde272f8006 /                       xfs     defaults,noatime        0 0[@more@]3. 在開機時執行 trim
# cp /etc/rc.d/rc.local /etc/rc.d/rc.local.$(date +%F)
# vim /etc/rc.d/rc.local
加入
# Trim the SSD at boot
/usr/sbin/fstrim /
/usr/sbin/fstrim /home
/usr/sbin/fstrim /boot

4. 修改 /etc/rc.d/rc.local 權限
# chmod 744 /etc/rc.d/rc.local

5. 設定開機時執行
# sed -i ‘$an[Install]nWantedBy=multi-user.target’ /usr/lib/systemd/system/rc-local.service
# systemctl enable rc-local
Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /usr/lib/systemd/system/rc-local.service.

6. Limit swap use
修改 /etc/sysctl.conf 加入下面二行
vm.swappiness=1
vm.vfs_cache_pressure=50
# sed -i ‘$avm.swappiness=1nvm.vfs_cache_pressure=50’ /etc/sysctl.conf

7. 讓設定生效
# sysctl -p
vm.swappiness = 1
vm.vfs_cache_pressure = 50

8. Use a SSD-friendly I/O scheduler
修改 /etc/default/grub 在 GRUB_CMDLINE_LINUX 那一行的最後面加上 elevator=deadline
# vim /etc/default/grub
GRUB_CMDLINE_LINUX=”rhgb quiet ipv6.disable=1 net.ifnames=0 biosdevname=0 elevator=deadline

9. 產生新的 grub 設定檔
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file …
Found linux image: /boot/vmlinuz-3.10.0-327.28.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.28.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.22.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.22.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-d1ae217032434f8a908229e3c9aae7ae
Found initrd image: /boot/initramfs-0-rescue-d1ae217032434f8a908229e3c9aae7ae.img
done