Created
February 19, 2013 08:26
-
-
Save hqman/4984018 to your computer and use it in GitHub Desktop.
opt ssd shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# SSD 优化脚本. | |
# | |
# 用法: | |
# 保存该脚本为 ssd.sh | |
# 在终端里运行 sudo ssh.sh | |
# 关闭 Sudden motion sensor | |
# SMS 用于笔记本在突然移动时通知硬盘碰头复位, 以保护机械硬盘不受损伤, 对于固态硬盘没有用处. | |
pmset -a sms 0 | |
# 删除 Hibernate | |
# 当电池耗尽时, 系统会将内存中的数据写入硬盘, 把固态硬盘安装在光驱位的必须关闭深度睡眠, 放在硬盘位的取消这个功能也可以节省与内存大小相同的硬盘空间. | |
# 如果想保留深度睡眠, 请删除下面这一节代码. | |
f=/var/vm/sleepimage | |
if [[ -e $f ]]; then | |
pmset -a hibernatemode 0 | |
rm $f | |
fi | |
# 取消 atime | |
# Mac 系统有个文件最后访问时间, 当你查看文件时, 会将当前时间写到 atime 里, 取消这个功能可以减少硬盘写入的次数. | |
f=/Library/LaunchDaemons/com.apple.hfs.noatime.plist | |
if [[ ! -e $f ]]; then | |
echo '<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" | |
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.apple.hfs.noatime</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>mount</string> | |
<string>-vuwo</string> | |
<string>noatime</string> | |
<string>/</string> | |
</array> | |
<key>RunAtLoad</key> | |
<true /> | |
</dict> | |
</plist>' > $f | |
fi | |
# 打开 TRIM | |
# 从 Lion 开始, 系统已经支持 SSD TRIM 指令, 但只对 Apple SSD 生效, 下面这段代码会对驱动打补丁, 将 "Apple SSD" 替换为空白, 借此激活 TRIM 功能. | |
f=/System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage | |
if [[ ! -e $f.original ]]; then | |
cp $f $f.original | |
perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x51)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' $f | |
kextcache -system-prelinked-kernel | |
kextcache -system-caches | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from http://vitarn.com/2012/03/20/macbook-466-467-ssd.html
http://www.guomii.com/posts/27398