Starbeamrainbowlabs

Stardust
Blog

Creating new Ramdisks Programatically with Imdisk

For a while now I have used Imdisk to create ramdisks to store data temporarily while I experiment with it. Imdisk is a driver for windows systems that allows you to create virtual drives that are stored either in memory, or in a file on your hard drive. It also allows you to mount existing images stored in iso or img files to let you explore their contents, for example.

Mounting a new ramdisk with Imdisk

Since I use ramdisks so often, I have written a batch script that automates the process of creating a ramdisk, and I thought that I would share it here:

@echo off

:: BatchGotAdmin7
:: From http://stackoverflow.com/a/10052222/1460422
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B

:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------

echo Ramdisk creation script

title Ramdisk Creation

set /p drive_letter=Enter Drive Letter:

if "%drive_letter%"=="" ( set drive_letter=R )

if exist %drive_letter%: (
echo A disk already exists with the letter %drive_letter%:.
echo Please unmount it before using this script.
)

set /p size=Enter Size: 

imdisk -a -s %size% -m %drive_letter%: -p "/fs:fat32 /q /y"

pause

( Pastebin, Raw, Size: 1.16KB )

To use it, first enter the driver letter that you want to assign to the new ramdisk, and then type in the size of ramdisk you want it to create, for example 512M, or 1G. Make sure you don't pick a number that is close to or above the total amount of ram you have in your system! Imdisk grabs all the RAM it will need for the ramdisk in advance!

Tag Cloud

3d account algorithms android announcement architecture archives arduino artificial intelligence artix assembly async audio bash batch blog bookmarklet booting c sharp c++ challenge chrome os code codepen coding conundrums coding conundrums evolved command line compilers compiling compression css dailyprogrammer debugging demystification distributed computing documentation downtime electronics email embedded systems encryption es6 features event experiment external first impressions future game github github gist gitlab graphics hardware hardware meetup holiday holidays html html5 html5 canvas infrastructure interfaces internet io.js jabber jam javascript js bin labs learning library linux lora low level lua maintenance manjaro network networking nibriboard node.js operating systems performance photos php pixelbot portable privacy problem solving programming problems projects prolog protocol protocols pseudo 3d python reddit redis reference release releases resource review rust searching secrets security series list server software sorting source code control statistics storage svg technical terminal textures three thing game three.js tool tutorial tutorials twitter ubuntu university update updates upgrade version control virtual reality virtualisation visual web website windows windows 10 xmpp xslt

Archive

Art by Mythdael