1

Is it possible to create RAID 1 with RAMDisk and SSD in OSX?

Something like: Boot Mac, OSX-Partition will be loaded from SSD in RAMDisk. Boot to RAMDisk and use it like any other system-drive. Because of RAID 1 (--write-mostly/write-behind) anything done on RAMDisk will be persisted to SSD. So if I power off the Mac everything will be persisted on SSD and can loaded again during next start...

For better experience the most used applications could be installed to that OSX-System-Partition (SSD) which will also be available in the RAMDisk.

Of course there will be a second "data" partition on the SSD for all the other stuff.

How can I achieve the described setup - is it even possible with OSX? Which Bootloader can I use (Grub?)?

7
  • Er.. how big do you plan to have the Ramdisk? Ramdisk is only as big as your RAM. Mac SSD smallest size is 128GB, unless you plan to have 128GB of RAM? I doubt what you want is even possible.. and if you think about it, RAID1 on RAMDISK and SSD, means the RAID set can only work as fast as the slowest component, which is the SSD. You won't get any performance gain, even assuming it is even possible.
    – Darius
    Mar 3, 2016 at 11:38
  • Thought I can use a software raid (do not know if I am able to use only certain partitions in a hardware raid) to use only one partition with osx installed + some apps (ca. 30GB?). I have 64GB Ram and would use 30GB for RAMDisk (in a RAID 1 with SSD-Partition of equal size). Another possibility could be to buy a small 32GB SSD for that. Thought with "--write-mostly / --write-behind" it is possible to delay the data replication a bit (to buy the ssd some time to cope with the ramdisk). Mar 3, 2016 at 11:45
  • 1
    Technically this might be possible. If you have two 'drives' (one th ramdisk and one a partition on the SSD - no need to use all of the SSDs space). But it might be more useful to use the standard trick for persistent ramdisks. Akak boot, (automatically) copy data to ramdisk. And on shutdown have a copy back to permanent storage.
    – Hennes
    Mar 3, 2016 at 11:49
  • @Hennes - that's how I deal with a rather thrashy cache for one application I use. Create RAMDisk & copy out at launch, launch app. At quit, write back to a duplicate cache folder, then after safely copied, swap folders & erase the older one.
    – Tetsujin
    Mar 3, 2016 at 11:58
  • @Hennes - But then I am not able to speed up OSX environment... Ok its fast enough already but would be still nice to have things opened instantly. But maybe I am able to load a ramdisk after boot and then copy most used apps in there and create a symlink to their pendants in the ramdisk to get them fast started? But then spotlight needs to reindex to let me open the "right" safari (in ram and not the one on my ssd)... mhm... any tricks how this could be an automatic workflow? Should I put the ssd-safari in a non-compressing zip so it is no longer visible to spotlight (so only ram-version is?) Mar 3, 2016 at 12:01

1 Answer 1

0

From comments, here's the bones of how I do a RAMDisk setup & copy back.

It's not the complete structure, so won't compile as it stands [there will be many missing declarations, as I have a whole set of other structures before I get to this bit, that aren't generic enough to be worth copying in], but gives the routines for creation, copy out & copy back. Save it as an application & launch this instead of your app.

There's also no provision in it for telling your app to use it - that, for me, is a separate structure just using the app's prefs & some —settings instructions at launch.

It's also set to cover if a mismatch occurs - that's because I have several versions of that particular app, & caches should not be mixed. You can probably leave that section out.

-- RAM Disk setup
        set copying to 0
        if not {exists disk RAMDisk} then
            set VolumeName to RAMDisk
            set SizeInMB to 1024
            -- can choose size using this dialog
            --display dialog "RAM Disk Size:" default answer SizeInMB buttons {"OK", "Cancel"}      
            set NumSectors to ((2 * 1024 * SizeInMB))
            set DeviceName to do shell script "hdid -nomount ram://" & NumSectors
            tell current application to do shell script "diskutil eraseVolume 'HFS+' '" & VolumeName & "' " & DeviceName        
            set foundDisk to false
            repeat until (foundDisk = true)
                if exists disk RAMDisk then
                    foundDisk = true
                    delay 1
                    -- do copy...   
                    duplicate full_path to disk RAMDisk
                    exit repeat
                else
                    delay 1 -- waiting for RAM disk to appear, if it's slow
                end if
            end repeat -- end disk wait
        else -- if RAMDisk exists already           
            set p to (folders of disk RAMDisk)
            if (exists folder cache_name of disk RAMDisk) then
                if p is {} then -- disk's empty
                    duplicate full_path to disk RAMDisk
                end if
            else -- if not (exists folder cache_name of disk RAMDisk) then
                display alert "RAM Disk contents are from a different version.\nErasing first..." giving up after 4
                try --deletes entire contents of RAMDisk, doesn't throw to Trash
                    --Folder in Trash can still cause "disk full" error.
                    --'quoted form' in shell scripts (unix) enables spaces in file names (ie RAMDisk name)
                    tell current application to do shell script "rm -rf Volumes/" & quoted form of RAMDisk & "/"
                end try
                duplicate full_path to disk RAMDisk
                delay 2
            end if -- end cache name check
        end if -- end RAMDisk check

(*at this point, launch your app, the script will sit & wait for it to quit*)

-- after app quits, copy back & tidy up
        display dialog "Quitting or just restarting 'app'?" buttons {"Quitting", "restarting"} ¬
            default button "Quitting" giving up after 30
        set thebutton to button returned of result as string
        if thebutton is "Quitting" then

            set toCopy to true -- to test for copyback
            if folder backup_location exists then
                display dialog "Safety folder already exists\nDelete & continue copy-back or just quit?" buttons {"Delete", "Just Quit"} default button "Delete" giving up after 30
                set thebutton to button returned of result as string
                if thebutton is "Delete" then
                    delete folder backup_location
                else
                    set toCopy to false -- will bypass copyback
                end if
            end if
            if toCopy is true then
                -- set a backup folder name before copying
                set name of folder full_path to cache_name & " - old"
                delay 1
                duplicate contents of folder cache_name of disk RAMDisk to folder custom_caches_base_path
                delay 1
                delete folder backup_location
            end if
        end if -- end quit sequence
0

You must log in to answer this question.

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