Menu

Imdisk command line option to configure it as RamDiskUI

Erotavlas
2017-02-21
2017-02-21
  • Erotavlas

    Erotavlas - 2017-02-21

    Hi,
    I saw that you removed your software from SourceForge for "precaution" purpose.
    I searched on the web about command line options of imdisk however I did not find any detailed guide only imdisk help.
    I imagine that your RamDiskUI execute imdisk with specific options in order to create virtual drive.
    I wonder to know if you can point out how to achieve something like this.
    I think that the following is enough to create ramdisk however I do not know how to make symbolic link of user and system default temp folders.
    imdisk -a -o awe -s 512M -m R: -p "/fs:ntfs /q /y"
    Thank you in advance

     

    Last edit: Erotavlas 2017-02-21
  • v77

    v77 - 2017-02-21

    If you need to download the Toolkit, see the main thread about ImDisk Toolkit on reboot.pro. The last message and my signature contain links to tinyupload.com (of course, for now, I prefer not to give them here).

    In command line, the Temp folder of the ramdisk requires a separate command to be created.

    RamDiskUI doesn't make symbolic links for the Temp folders. It changes the environment variables, directly in the registry. The keys are:
    HKEY_CURRENT_USER\Environment
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    with the values "TEMP" and "TMP".
    In command line, they can be changed with the "reg" command (see "reg add /?").

     
  • Erotavlas

    Erotavlas - 2017-02-22

    Thank you for your fast reply and for the link.
    Is there any documentation about creating a ramdisk and pointing a folder to it all via command line?
    I'm interested about creating a powershell script that install imdisk and imdisk toolkit via chocolatey package manager (already done) and create a ramdisk.
    Thank you again.

     
  • v77

    v77 - 2017-02-22

    "Pointing a folder to it"? If you mean creating a drive letter to a ramdisk and then a folder that redirect to the drive letter, you should check the "mklink" command.
    I know nothing about powershell, but you can directly create a ramdisk in a folder. Instead of using "-m R:", use for instance "-m C:\MyFolder". C:\MyFolder must be an empty directory located in a NTFS volume.

    Checking the (very long) syntax help of imdisk.exe will give you a lot of informations about the possibilities of the driver (and you can consider it as the main documentation of the imdisk driver).
    But with the Toolkit, if the speed of the ramdisk is not an issue and you want to use dynamic allocation of memory, you also can take a look at the syntax help of RamDyn.exe, in the installation folder of ImDisk Toolkit. It too is usable in command line (but all the arguments must be given).

     
  • Erotavlas

    Erotavlas - 2017-02-23

    Ok thank you. I will report my progress here.
    The following is a working script for powershell that works both on windows 7 and windows 10.
    It installs chocolatey package manager together with imdisk and imdisk-toolkit.

    $ChocolateyPath="$env:ProgramData\chocolatey"
    if (-Not (Test-Path $ChocolateyPath))
    {
        echo "Installing chocolatey packages manager"
        iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
        refreshenv
    }
    
    $RAMDiskDrive="R:"
    if(-Not (Test-Path $RAMDiskDrive))
    {
        echo "Setup RAMdisk via imdisk"
        choco install -y imdisk imdisk-toolkit
        imdisk -a -o awe -s 512M -m $RAMDiskDrive -p "/fs:ntfs /q /y"
    
        # setup windows temp folder to RAMdisk
        $TempFolder="$RAMDiskDrive\Temp"
        $RegKey="HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
        Set-ItemProperty -path $RegKey -name "TEMP" -value $TempFolder
        Set-ItemProperty -path $RegKey -name "TMP" -value $TempFolder
        # setup user temp folder to RAMdisk
        $RegKey ="HKCU:\Environment"
        Set-ItemProperty -path $RegKey -name "TEMP" -value "R:\Temp"
        Set-ItemProperty -path $RegKey -name "TMP" -value "R:\Temp"
    }
    

    I followed your suggestion about TEMP and TMP folders. Now, I do not know in simple way (avoiding script with Schtasks) how to add automatic creation and mounting of RAMdisk at boot.
    I saw that there is an option in your imdisk-toolkit, however I did not find how it works.
    Can you suggest me how to do?
    Thank you

     

    Last edit: Erotavlas 2017-02-25
  • Kim

    Kim - 2017-02-25

    You can try to do the following:
    1. Create an empty .img file with desired size end filesystem;
    2. Mount .img with "-o awe" and "-P" options,
    eg.: imdisk -a -t file -f $RAMfile -m $RAMDiskDrive -o awe -P

    If use NTFS-compression, actual size on disk of empty .img file will be about 0 KB.

     
  • Erotavlas

    Erotavlas - 2017-02-26

    Thank your for your suggestion.
    I tried to create an empty image with the command:
    imdisk -a -s 512M -f $RAMDiskFile -p "/fs:ntfs /q /y" and then to create a RAMDisk with the command
    imdisk -a -t file -f $RAMDiskFile -m $RAMDiskDrive -o awe -P.
    The latter works only if I restart the OS otherwise imdisk is unable to access the file that is busy.
    I get this output by using this script
    System pid: 4 \<unable to open process> - 11C0: File (R-D) C:\ProgramData\RAMDiskFile.img
    Since I'm writing a script, it would not be very useful to restart the OS and run again the script.

     

    Last edit: Erotavlas 2017-02-26
  • v77

    v77 - 2017-02-26

    You don't need to install the driver separately, ImDisk Toolkit already does that.

    When you check "Launch at Windows Startup", RamDiskUI creates a service. It's this service that creates the ramdisk.

    If the proper registry values are present, the installer of ImDisk Toolkit is able to recreate the required services, depending of these values. So, you can simply use "Save Parameters" in the General Settings to create a reg file. Then, in a machine where it is not installed, use this reg file with a command such as "reg import imdisk.reg" or "regedit imdisk.reg", and then use the installer.

     
  • Erotavlas

    Erotavlas - 2017-02-26

    Ok, now I understand better how RamDiskUI works. So it is mandatory to first create the image file and then to create the corrisponding drive after reboot. Also RamDiskUI should behave in this way.
    By using a script, I prefer to use the driver directly even if I have to re run the script twice.
    So my final powershell script that does all the work is this.
    It also install RamDiskUI in the case that the user want to manage RAMdisk via GUI.

    $ScriptHome="$env:ProgramData"
    $ChocolateyPath="$ScriptHome\chocolatey"
    if (-Not (Test-Path $ChocolateyPath))
    {
        echo "Installing chocolatey packages manager"
        iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
        refreshenv
    }
    
    $RAMDiskDrive="R:"
    $RAMDiskFile="$ScriptHome\RAMDiskFile.img"
    if(-Not (Test-Path $RAMDiskFile))
    {   
        echo "Setup RAMdisk file image via imdisk"
        choco install -y imdisk imdisk-toolkit
        imdisk -a -s 512M -f $RAMDiskFile -p "/fs:ntfs /q /y"
    }
    elseif(-Not (Test-Path $RAMDiskDrive)) 
    {
        echo "Setup RAMdisk drive via imdisk"
        imdisk -a -t file -f $RAMDiskFile -m $RAMDiskDrive -P
    
        # setup windows temp folder to RAMdisk
        $TempFolder="$RAMDiskDrive\Temp"
        $RegKey="HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
        Set-ItemProperty -path $RegKey -name "TEMP" -value $TempFolder
        Set-ItemProperty -path $RegKey -name "TMP" -value $TempFolder
    
        # setup user temp folder to RAMdisk
        $RegKey ="HKCU:\Environment"
        Set-ItemProperty -path $RegKey -name "TEMP" -value $TempFolder
        Set-ItemProperty -path $RegKey -name "TMP" -value $TempFolder
    }
    

    Thank you for the support.

     

    Last edit: Erotavlas 2017-02-26
  • Kim

    Kim - 2017-02-26

    No need to reboot. I just tryed.
    To create .img and mount RAMdisk, and save its state after reboot, only one command is enough:

    imdisk -a -s $Size -f $RAMDiskFile -p "/fs:ntfs /q /y" -m $RAMDiskDrive -P
    

    In first post, you mentioned option -o ave, so i thought that you want to create a RAMdisk, wich is empty after each reboot; not saving its state.
    In that case, to avoid locking of $RAMDiskFile, it's possible to:
    1. Create and mount .img
    2. Unmount .img
    3. Mount img with options -o awe and -P

    imdisk -a -s $Size -f $RAMDiskFile -p "/fs:ntfs /q /y" -m $RAMDiskDrive    
    imdisk -d -m $RAMDiskDrive
    imdisk -a -f $RAMDiskFile -m $RAMDiskDrive -o awe -P
    

    As .img file is actually empty, it is wise to compress it to save disk space.

    Imdisk will not create file without -a option, and I don't know another way to create .img in command line.

    I also tryed:

    imdisk -a -s $Size -p "/fs:ntfs /q /y" -m M: -P`
    
    imdisk -a -s $Size -f $RAMDiskFile -p "/fs:ntfs /q /y" -m M: -o awe -P
    

    In both cases no img file created and RAMdisk was mounted, but unformatted after reboot.

     

    Last edit: Kim 2017-02-26
    • Erotavlas

      Erotavlas - 2017-02-27

      imdisk -a -s $Size -f $RAMDiskFile -p "/fs:ntfs /q /y" -m $RAMDiskDrive -P
      Yes, I need the option -o awe since it is the only one that mount the RAMDisk directly into the physical memory (correct me if I'm wrong).
      In both cases no img file created and RAMdisk was mounted, but unformatted after reboot.
      Yes, I can confirm this behaviour.
      Thank you for your suggestion with three steps, I'm going to use it.

      $RAMDiskDrive="R:"
      if(-Not (Test-Path $RAMDiskDrive))
      {   
          echo "Setup RAMdisk via imdisk"
          choco install -y imdisk imdisk-toolkit
      
          $SystemRAM=[Math]::Round(((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory/1GB),2)
          if($SystemRAM -gt 8)
          {
              $RAMDiskSize="1G"
          }
          else
          {
              $RAMDiskSize=[String]($SystemRAM/8*1000)+"M"
          }
          $RAMDiskFile="$ScriptHome\RAMDiskFile.img"  
          imdisk -a -s $RAMDiskSize -f $RAMDiskFile -m $RAMDiskDrive -p "/fs:ntfs /q /y" 
          imdisk -D -m $RAMDiskDrive
          imdisk -a -t file -f $RAMDiskFile -m $RAMDiskDrive -o awe -P
      
          # setup windows temp folder to RAMdisk
          $TempFolder="$RAMDiskDrive\Temp"
          $RegKey="HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
          Set-ItemProperty -path $RegKey -name "TEMP" -value $TempFolder
          Set-ItemProperty -path $RegKey -name "TMP" -value $TempFolder
      
          # setup user temp folder to RAMdisk
          $RegKey ="HKCU:\Environment"
          Set-ItemProperty -path $RegKey -name "TEMP" -value $TempFolder
          Set-ItemProperty -path $RegKey -name "TMP" -value $TempFolder
      }
      
       

      Last edit: Erotavlas 2017-02-27
      • Kim

        Kim - 2017-02-27

        The option to mount RAMdisk directly into the physical memory is -a

        -a       Attach a virtual disk ... to the system.
        

        Options -o awe and -P:

        -o awe   No changes are written to image file.
        
        -P       Persistent... saves registry settings for re-creating the same virtual disk automatically ... during system startup.
        

        Thus, in "three steps", an image file is only used during each startup to read partition table from.

        I still can't understand, do you want that content of RAMdisk was flushed on each reboot or not?

         
        • Erotavlas

          Erotavlas - 2017-02-27

          I want to have a RAMDisk in the linux style (shm or tmpfs).
          What is the fastest and open source way on windows? I found imdisk and with your help, I created a script that automatically install imdisk via chocolatey and setup a RAMDisk.
          For what I understand, without using the -o awe option, the virtual disk is not written directly into the RAM, but into the mass storage.
          This is not so fast.

           
  • Kim

    Kim - 2017-02-27
     

    Last edit: Kim 2017-02-27

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.