1

I have a Macbook pro with 2 internal HD (stock HD for data and data doubler + SSD in place of the optical drive, hosting the OS). I'm now trying to optimize this setup to take into account the presence of the SSD, and I want to move the temporary folder from the SSD (/private/tmp) to the secondary drive (/Volume/MacintoshHD/private/tmp).

Following this (http://blog.alutam.com/2012/04/01/optimizing-macos-x-lion-for-ssd/comment-page-1/#ramdisk), here's what I did :

sudo ditto /private/tmp /Volumes/MacintoshHD/private/tmp
sudo rm -rf /private/tmp
sudo ln -s /Volumes/MacintoshHD/private/tmp /private/tmp

Everything is fine, but when I reboot, I expect the folder to be emptied as usual. However, I found out that whatever files that were present on the previous OS execution are still present.

My guess is that whatever script emptying the /private/tmp folder executes before the magnetic HD gets mounted, which means that the link pointing to the tmp folder does not point anywhere then, and hence the failed deletion.

Any idea how to fix this? Any other suggestion to move the /private/tmp folder to another drive and still preserve automatic deletion?

  • 1
    I would have thought that /private/tmp is probably the best folder to have on the SSD – Mark Dec 20 '14 at 15:45
  • Have you tried running the periodic script once for each time period once the system is mounted? It might also do the cleanup. – bmike Dec 20 '14 at 16:10
  • @Mark The reason I want to put the tmp folder on the HDD is because that I also use this folder as the download folder for both email attachments and safari. I'd rather not waste my SSD on temporary stuff, especially since this SSD is third party and TRIM is support is far from great in Yosemite. – Samric Dec 20 '14 at 17:27
  • @bmike I haven't tried running the periodic script yet, will surely try that. However, the daily script runs at 3am by default, meaning it might never run if I turn my laptop off at night. As a result, there's a possibility of that tmp folder never getting emptied up. – Samric Dec 20 '14 at 17:29
  • I would use another directory for downloads for those reasons – Mark Dec 20 '14 at 19:50
1

After doing some research, I ended up writing a shell script and using launchd to have it execute at boot time.

The script I use (/usr/local/bin/empty-tmp.sh) :

#!/bin/bash

# Delete files (other than directories) that haven't been modified in more than 1 day
find /Volumes/MacintosHD/private/tmp -not -type d -ctime +1d -delete

# Delete empty directores that have been created more than 1 day ago
find /Volumes/MacintoshHD/private/tmp -d -type d -empty -mindepth 1 -Btime +1d -delete

and the property list (in /Library/LaunchDeamons) :

<?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.samric.emptytmp</string>

  <key>ProgramArguments</key>
  <array>
    <string>/bin/bash</string>
    <string>-c</string>
    <string>/bin/wait4path /Volumes/MacintoshHD/private/tmp/ && /usr/local/bin/empty-tmp.sh</string>
  </array>

  <key>RunAtLoad</key>
  <true/>

  <key>LaunchOnlyOnce</key>
  <true/>
  </dict>
</plist>

Now the key is using wait4path to make sure the secondary HD (MacintoshHD) is properly mounted before invoking the script. Failing to do so will result is the script not deleting any files since they won't be accessible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .