Friday, May 18, 2018

Mounting OSFMount RAM drive on boot

Updated: 16 Apr 2020

I have used a number of RAM drives over time and more in the recent years with the increase in amount of RAM available to store user temporary files (autoclean on power down) and even projects build output directories (try and reduce some build times).

PassMark OSFMount might still be missing some features compared to other available RAM drive software out there, but it is free and it has received a number of improvements lately.

Install software

Download OSFMount (v3.0.1005, 29 Jul 2019 at the time of writing) and follow the installation instructions, nothing special there.

Create automount script

The script will mount the drive if the letter is available and it uses its internal format command which can only format FAT32 at the moment. Adjust the settings to fit depending on your needs and available free RAM (check with Task Manager > Performance > Memory). Save in a system (e.g. "%WINDIR%\Create RAM Drive + TEMP directory.cmd") or user location.
@ECHO OFF
SET RAMDISK_DRIVE=R:
SET RAMDISK_SIZE=1G
SET RAMDISK_LABEL=RAM Disk
IF NOT EXIST "%RAMDISK_DRIVE%" (
  "%PROGRAMFILES%\OSFMount\OSFMount.com" -a -t vm -s %RAMDISK_SIZE% -o format:fat32:"%RAMDISK_LABEL%" -m "%RAMDISK_DRIVE%
  MKDIR "%RAMDISK_DRIVE%\TEMP"
)
If you test run it in an elevated Command Prompt it should output like below:
"%WINDIR%\Create RAM Drive + TEMP directory.cmd"
Creating device...
Created device 0: R: -> VM image
Formatting drive with volume label RAM Disk
Notifying applications...
Done.


Task Scheduler

Create a scheduled task in Task Scheduler (taskschd.msc),  the important parts are to run At system startup and to Run whether user is logged on or not.




Finishing notes

Reboot and confirm RAM drive is there on startup.



IMPORTANT NOTE:

If you intend to change your user TEMP and TMP environment variables to point to R:\TEMP with a small RAM drive you can run into all sorts of weird issues when installing large applications or with anything that takes large amounts of temporary disk space for operating like Android sdkmanager update or anything like that.

If you still want to go this way cause you think you know what you're doing, any time something weird happens like that happens I would remember to change your TEMP and TMP environment variables back to default %USERPROFILE%\AppData\Local\Temp, logoff and try the operation again.

I have never considered changing system's TEMP or TMP environment variables, just the user ones.

14 comments :

  1. شرح مفيد جدا شكرا
    قمت باضافة متغير باسم tmp_old للمسار الأصلي
    tmp --> r: // tmp_old --> %USERPROFILE%\AppData\Local\Temp

    ReplyDelete
    Replies
    1. Thank you for your comment, I do the same to keep a copy in case I need it.

      Delete
  2. What batch file causes R:\TEMP to be created as a shared folder at Windows startup?

    ReplyDelete
    Replies
    1. It's the bactch file scheduled through Task Scheduler above. Something to keep in mind though I've seen problems with installing MSIs, you would have to copy to a HDD/SSD or even change the TEMP/TMP environment variables first for the Run As Admin console to avoid the issue.

      Delete
  3. That's not right: format:"%RAMDISK_LABEL%"
    It has to be: format:fat32:"%RAMDISK_LABEL%"
    or another fs-type.

    ReplyDelete
    Replies
    1. Thank you for your comment. You are right, the information was valid at the time as noted in the article (version, date), v3 has since introduced the parameter chane. Just updated the article, thank you!

      Delete
  4. Current version of OSFMount support NTFS and exfat as well.

    Command line parameter is,

    format:ntfs|fat32|exfat[:"Vol Label"]]

    ReplyDelete
    Replies
    1. Thank you for your comment, starting with version v3.0.1000 (5 Apr 2019) the tool offers exFAT as an option as well. (Y) https://www.osforensics.com/tools/mount-disk-images.html#Whats-new

      format:ntfs|fat32|exfat[:"Vol Label"]] Specifies that virtual disk should be formatted after it is mounted.
      The file system should be one of ntfs, fat32, or exfat.
      This option is only available for new empty RAM disk. Optionally, to
      specify a volume label, add a quoted string after appending a colon(:)
      after the file system.

      LIMITATIONS: File systems may have a minimum disk size requirement.
      For example, FAT32 requires at least 260 MB.

      Delete
  5. I have no idea what you programming language you are using. (I'm not a programmer so I don't even know how to create a script that would run via the command line.)

    Would you be interested in creating a script that would automatically load OSFMount and the RAM image at boot up. And, the script would also automatically save the image periodically and then save an image one last time during shutdown. I could pay you.

    ReplyDelete
    Replies
    1. @BroadThinker
      I think there is a way for OSFMount to create a RAM Drive from an image file, and also to persist it at shutdown (-t file -f ramdrive.img) but I'm afraid from my performance tests I've done it might save the changes as they happen which you will reduce the performance of the RAMDrive itself. I've asked the question on the OSFMount thread for confirmation. https://www.passmark.com/forum/osforensics-osfmount-osfclone/48264-how-to-automate-mounting-and-saving-image-file-of-a-ram-disk

      If that is the case you might as well just use SUBST command to assign a letter to a folder on disk and write directly into it - you will get the same performance, persistence and wear without the need for a RAMDrive. Or, if you're willing to pay you should maybe use a commercial RAM disk software like DataRam and SoftPerfect (have used they free versions before). See https://en.wikipedia.org/wiki/List_of_RAM_drive_software

      Delete
  6. Hi, Dan,

    I forgot the password to my account so it took me some time to reply to you. Sorry for the late reply.

    I read your response and I had some questions that would be ok to ask. In your 1st sentence, I really didn't understand what you were trying to say. Are you saying that if a program saves an image of the RAM drive, the RAM Drive would become slower? So, slow in fact that it would perform at the same speed as an SSD? Don't bother explaining. I really don't know much about computers.

    I've tried SoftPerfect and DataRAM and I've had problems with them. SoftPerfect glitches all the time with me and I lose everything a lot and it wastes a lot of my time. DataRAM I have also tried and things didn't turn out well either. Maybe it's because OSFMount is newly programmed vs the others that were programmed more than a decade ago. I don't know how to benchmark them but I also feel that OSFMount seems faster and more "solid" but it could all be just psychological. Yet, I would love it if someone would just create a script in a simple language that would complete what OSFMount should be able to do.

    If it can't:
    1. Automatically boot up a RAM Drive image at boot up, then
    2. Automatically save the RAM Drive image at 1 minute intervals (as well as a backup), and
    3. Automatically safely save one final image at shutdown,

    then I'm guessing the program is really useless. I would create a program to do all this in AutoHotkey (the only language I know), but it would take me literally 6 months since I barely even know how to use AutoHotkey. So, I would be willing to pay someone to do it for me. I can't see it being that hard for a programmer to have OSFMount to perform these simple tasks.

    A nice additional but difficult feature is if this program could automatically install the programs onto the RAM drive instead of having users doing it themselves. This would require terminating any running files of the Program File for the program in question, cutting (later pasting) these Program Files, creating a hard link from the Program File location to the RAM drive, and then finally pasting the previously cut Program Files onto the RAM drive. (This is the procedure I use to move programs onto my RAM drive.)

    I don't have that many programs on my RAM drive. It's just:
    1. Nuance Power PDF,
    2. Microsoft office,
    3. AutoHotkey,
    4. Directory Opus
    5. Dexpot

    For caches, I only moved the browser and Temp folder to the RAM drive.

    I think that if you program something like this in a day, you could even sell it for $10 a piece.

    What do you think?

    ReplyDelete
  7. What exactly is the format command for NTFS? My guess is

    -o format:ntfs:"RamDisk"

    but that doesnt work. Here my full command code

    @ECHO OFF
    IF NOT EXIST "R:" (
    "C:\Program Files\OSFMount\OSFMount.com" -a -t vm -m R: -o format:ntfs:"RamDisk" -s 1G
    MKDIR "R:\TEMP"
    )

    ReplyDelete
    Replies
    1. Hi, I should update the article. The newer version of OSFMount V3.1 (Build 1001) works for me with this command (run `osfmount.com` without any parameters in an admin command to see all -o parameters):

      "C:\Program Files\OSFMount\OSFMount.com" -a -t vm -o rw,hd,format:ntfs:"RAMDisk" -m R: -s 1G

      Delete
    2. I now realize that I was using an old version of OSFmount version 3.0.1006 which didn't work with this command. V3.1 now works well with included formatting. Thank you for your effort and help.

      Delete