MBP加到16GB之後的第一件事, 加RamDisk筆記
MBP加到16GB之後的第一件事, 加RamDisk筆記
原本是要用Esperance DV來做RamDisk的,
但在我的MBA 2012 搭 OS X 10.8竟然顯示-2048MB(沒錯,就是負2048MB)
但其它App都要費用,所以自已加了script來做
步驟:
//1. Create 2GB RamDISK
// 2GB/512= 4000000 (至少512MB,如果太小請先確認你目前的Safari的cache size)
計算此值給diskutil建立Ramdisk之用,加在wakeup.sh中diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://4000000`
//2. Install the "sleep watcher" from macports
port install sleepwatcher
//2.1. Start/Stop the "sleep watcher" Service
port unload sleepwatcher
port load sleepwatcher
//2.2 Create the sleep and wakeup script
//sleep script
//sleep script
vi /etc/sleepwatcher/sleep.sh
#!/bin/sh
rsync -av --delete /Volumes/ramdisk/ /var/spool/rdimage/
diskutil unmount /dev/disk1
diskutil eject /dev/disk1
rsync -av --delete /Volumes/ramdisk/ /var/spool/rdimage/
diskutil unmount /dev/disk1
diskutil eject /dev/disk1
//wakeup script
vi /etc/sleepwatcher/wakeup.sh
#!/bin/bash
# Create a 2048MB ramdisk, mount on /Volumes/ramdisk
ramDisk=`diskutil list | awk '/ramdisk/{print $5}'`
if [ ! -e "/dev/$ramDisk" ];then
echo "Not exist"
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://4000000`
diskutil enableOwnership /Volumes/ramdisk
#restore ramdisk image from disk
rsync -a /var/spool/rdimage/ /Volumes/ramdisk/
fi
//2.3 Attched to "sleep watcher"
echo "/etc/sleepwatcher/sleep.sh" >> /opt/local/etc/rc.sleep
echo "/etc/sleepwatcher/wake.sh" >> /opt/local/etc/rc.wake
//3. Change the Safari cache folder to RamDisk
//3.1 Find your Safari cache folder
//3.1.1 Cache Folder:1
#find /var/folders/ -name com.apple.Safari
ex:/var/folders//xx/xxxx/C/com.apple.Safari
//3.1.2 Cache Folder:2
#~/Library/Caches/com.apple.Safari
//3.2 Close your Safari then to do flow command.
//4 Setup RamDisk path
//4.1 Move the Cache folder to RamDisk
#mv /var/folders//xx/xxxx/C/com.apple.Safari /Volumes/ramdisk
#mv ~/Library/Caches/com.apple.Safari /Volumes/ramdisk/user/
//4.2 Create the Link path form RamDISK to Safari
#ln -s /Volumes/ramdisk/com.apple.Safari /var/folders//xx/xxxx/C/com.apple.Safari
#ln -s /Volumes/ramdisk/user/com.apple.Safari ~/Library/Caches/
//5. Launch your Safari
以上,如果MAC遇到沒有的目錄,可用mkdir建立
(MAC都一定要將參數加在前面嗎?,用慣Linux的我很不習慣說)
例:mkdir -p /etc/sleepwatcher
mkdir -p /Volumes/ramdisk/ /var/spool/rdimage
註1.如果不想安裝macport的話,可以直接安裝sleepwatcher
在安裝完sleepwatcher後將以下command加到daemon
/opt/local/sbin/sleepwatcher --verbose --sleep /etc/sleepwatcher/sleep.sh --wakeup /etc/sleepwatcher/wakeup.sh
再做上列的Step 2.2, 3.*,4.*及5就可以啦.
註2.OS X 10.4及之前的版本
hdid -nomount ram://4000000
newfs_hfs /dev/disk1
mkdir /tmp/ramdisk1
mount -t hfs /dev/disk1 /var/spool/rdimage
註3. Chrome的cache在此
~/Library/Caches/Google/Chrome
Labels: OS X