Mount disk from start daemon on Mac OS X Yosemite

I am trying to set / private / tmp as a ramdisk. I have this "ramfs.sh" script 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 works fine if I run it manually from the terminal. However, I am having trouble starting LaunchDemon. I have this content 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 the system boots up, I have:

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

      

But "mount" does not show / private / tmp as mounted on disk1. The logs only show the following: "Initialized / dev / rdisk1 as at least 1024MB HFS Plus volume."

So the script is definitely executed during system startup, but it looks like the mount command is not working. Any ideas? Thank.

EDIT

I have added some "echo" to the script and will "mount" verbose. Here's the 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...

      

It looks like the script is working fine and is even mounted to disk. But it looks like the folder gets overwritten while loading "tmp"?

EDIT2

It looks like everything is fine, except that something disconnects my mapped drive on system startup. Also someone noticed this link behavior .

+3


source to share


2 answers


I solved my problem by executing the 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>

      



It looks like "RunAtLoad" is not enough or it doesn't work, I don't know. But with "KeepAlive" it works fine.

0


source


Updated answer

I note that you are trying to connect the RAMdisk to /private/tmp

. I can't point to any specific evidence, but it's just not a good idea as it /tmp

is a system directory. I would make a directory under /tmp

, for example, /tmp/RAMdisk

or even in the root directory of the filesystem in /RAMDisk

.

Original Answer



I think the problem is that /sbin

it is not in your PATH, so the script cannot find it mount

. Try adding this as the second line of your script:

export PATH="/sbin:$PATH"

      

Also missing TYPE

, which indicates that no filesystem has been created on your disk, i.e. failed news_hfs

and this is also in /sbin

.

+1


source







All Articles