3

i am trying to mount /private/tmp as ram disk. I have this "ramfs.sh" script, which i found from the internet:

#!/bin/bash
ramfs_size_mb=1024
mount_point=/private/tmp

ramfs_size_sectors=$((${ramfs_size_mb}*1024*1024/512))
ramdisk_dev=`hdid -nomount ram://${ramfs_size_sectors}`
newfs_hfs -v 'Volatile HD' ${ramdisk_dev}
mkdir -p ${mount_point}
mount -o noatime -t hfs ${ramdisk_dev} ${mount_point}
chown root:wheel ${mount_point}
chmod 1777 ${mount_point}

It is working fine, if i run it manually from terminal. However i have problem running it from LaunchDemon. I have this contents in the file "/Library/LaunchDaemons/com.kalugin.ramfs-for-db.plist":

<?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.kalugin.ramfs-for-db</string>
        <key>Program</key>
        <string>/var/root/ramfs.sh</string>
        <key>RunAtLoad</key>
        <true/>
        <key>StandardOutPath</key>
        <string>/var/log/ramfs_for_db.log</string>
        <key>StandardErrorPath</key>
        <string>/var/log/ramfs_for_db_error.log</string>
        <key>Debug</key>
        <true/>
    </dict>
</plist>

After system load i have:

/dev/disk1
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:                            Volatile HD            *1.1 GB     disk1 

But "mount" doesn't show /private/tmp as mounted on disk1. Logs show only this: "Initialized /dev/rdisk1 as a 1024 MB case-insensitive HFS Plus volume".

So definitely script is executed during system start up, but looks like mount command does not work. Any ideas? Thank you.

EDIT

I added some "echo" in script and make "mount" verbose. Here is output:

Creating ram disk...
Initialized /dev/rdisk1 as a 1024 MB case-insensitive HFS Plus volume
Mounting ram disk...
/dev/disk1 on /private/tmp (hfs, local, noatime)
Setting permissions...

So looks like script is doing fine, and even mounted disk. But looks like during boot "tmp" folder is overwritten?

EDIT2

Looks like everything is fine, except something unmounts my mounted disk on system start up. Also someone noticed this behavior too link.

Clickbeetle
  • 629
  • 4
  • 13

2 Answers2

1

Updated Answer

I note you are trying to mount your RAMdisk at /private/tmp. I can't point to any concrete evidence, but that is just not a good idea as /tmp is a system directory. I would make a directory under /tmp, like /tmp/RAMdisk or even at the filesystem root in /RAMDisk.

Original Answer

I think the problem is that /sbin is not in your PATH, so the script can't find mount. Try adding this as the second line of your script:

export PATH="/sbin:$PATH"

Likewise the TYPE is missing, which indicates that no filesystem was created on your disk, i.e. that news_hfs failed to run, and that too, is located in /sbin.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • That helps! Thank you. Does "PATH" differ during system startup and when user is logged in? I mean that "sbin" is already in my "PATH", when i am logged in, and i don't type it in .bash_profile. – Clickbeetle Jun 16 '15 at 11:59
  • 1
    Yes, typically the PATH differs for each and every user, and often also for interactive vs non-interactive shells. Remember also that launch daemons from `/Library` run as *system* services not as your user so they don't execute your profile. – Mark Setchell Jun 16 '15 at 12:13
  • Thanks, but for me it strange, that "sbin" (that must be system binaries) not in $PATH for launchd proccess. – Clickbeetle Jun 16 '15 at 12:20
  • `sbin` is for *statically linked binaries* that are needed during system startup before dynamic libraries on other, as yet unmounted, filesystems are available. I don't know why `/sbin` is not in the PATH for `launchd` - I guess it is because you are at liberty to add them yourself if required. – Mark Setchell Jun 16 '15 at 12:33
  • Strange, but it doesn't work anymore. I don't change anything, but now it stopped working. – Clickbeetle Jun 17 '15 at 07:13
  • I will try to do it. I know that it is system, but is just a directory with temporary files. – Clickbeetle Jun 18 '15 at 09:33
  • So i mounted it in "/private/tmp/ramfs" and still the same. When i boot up my computer, inside "/private/tmp" there was my folder "ramfs", but "mount" command don't show this folder as ram disk, it is just usual folder. So looks like mount command not working. It is working, but result of it is blocked? – Clickbeetle Jun 19 '15 at 07:35
  • Try adding `echo $? >> yourLogFile` after each of the commands to get the exit status logged - zero means success. – Mark Setchell Jun 19 '15 at 07:57
0

I solved my problem by following plist file:

<?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.local.ramdisk</string>
                <key>Program</key>
                <string>/usr/libexec/ramdisk.sh</string>
                <key>RunAtLoad</key>
                <true/>
                 <key>KeepAlive</key>
                <dict>
                        <key>PathState</key>
                        <dict>
                                <key>/private/tmp/ram</key>
                                <false/>
                        </dict>
                </dict>
                <key>StandardOutPath</key>
                <string>/var/log/ramdisk.log</string>
        </dict>
</plist>

Looks like "RunAtLoad" is not enough or it doesn't work, i don't know. But with "KeepAlive" it is working fine.

Clickbeetle
  • 629
  • 4
  • 13