0524.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Windows Server 2012 2016 2019 2022 RAM Disk Setup Guide</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Windows,RAM Disk,Microsoft,iSCSI,PowerShell,Windows Server,Windows Server 2012,Windows Server 2016,Windows Server 2019,Windows Server 2022,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Windows Server 2012 2016 2019 2022 RAM Disk Setup Guide">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  12. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  13. <script type="text/javascript" src="includes/js/steps.js"></script>
  14. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  15. </head>
  16. <body>
  17. <div id="gridContainer">
  18. <div class="topMargin"></div>
  19. <div id="listName" class="topMargin">
  20. <h1>Windows Server 2012 2016 2019 2022 RAM Disk Setup Guide</h1>
  21. </div>
  22. <div></div>
  23. <div id="content">
  24. <p><em>NOTE: RAM disks by their very nature are cleared on reboot. Do not use them to store any data that cannot be lost. A suitable use case would be temporary session files for a web server</em></p>
  25. <h2>Installing iSCSI Target Server</h2>
  26. <ol>
  27. <li>Launch Server Manager if it does not automatically load
  28. <ol>
  29. <li>Click the Start button &gt; Server Manager</li>
  30. </ol>
  31. </li>
  32. <li>Click Manage &gt; Add roles and features</li>
  33. <li>Click Next on the Before you begin screen</li>
  34. <li>Select Role-based or feature-based installation &gt; Next</li>
  35. <li>Leave Select a server from the server pool selected and select the current server &gt; Next</li>
  36. <li>Expand File and Storage Services &gt; Expand File and iSCSI Services &gt; Select iSCSI Target Server</li>
  37. <li>A popup will appear with additional required roles and features, click the Add Features button</li>
  38. <li>Click Next</li>
  39. <li>Click Next on the Select features screen</li>
  40. <li>Click Install on the confirmation screen</li>
  41. <li>Leave the installation progress screen open until the install completes</li>
  42. </ol>
  43. <h2>Creating the RAM Disk</h2>
  44. <ol>
  45. <li>Launch Powershell as administrator</li>
  46. <li>Enter the following commands to create the RAM disk, replacing the IP address with the current server&#39;s IP address
  47. <div class="codeBlock PS"># allow iSCSI loopback registry setting<br />
  48. Set-ItemProperty -Path &#39;HKLM:\SOFTWARE\Microsoft\iSCSI Target&#39; -Name AllowLoopBack -Value 1<br />
  49. # start the iscsi initiator service<br />
  50. Start-Service -Name MSiSCSI<br />
  51. # set the iscsi initiator service to start automatically<br />
  52. Set-Service -Name MSiSCSI -StartupType Automatic<br />
  53. # create the ram disk, changing size as needed<br />
  54. New-IscsiVirtualDisk -Path &quot;ramdisk:RAMDisk.vhdx&quot; -Size 256MB<br />
  55. # initialize iSCSI target<br />
  56. New-IscsiServerTarget -TargetName RAMDisk -InitiatorIds @(&quot;IPAddress:192.168.0.65&quot;)<br />
  57. # connect to the ram disk<br />
  58. Add-IscsiVirtualDiskTargetMapping -TargetName RAMDisk -DevicePath &quot;ramdisk:RAMDisk.vhdx&quot;</div>
  59. </li>
  60. <li>Back in Server Manager, select Tools &gt; iSCSI Initiator</li>
  61. <li>Enter the IP address in the Target field &gt; Click Quick Connect...</li>
  62. <li>Click Done</li>
  63. <li>Back in Powershell, run the following command
  64. <div class="codeBlock PS"># initialize the disk as NTFS<br />
  65. Get-Disk | Where partitionstyle -eq &#39;raw&#39; | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -DriveLetter R -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel &quot;RAMDisk&quot; -Confirm:$false</div>
  66. </li>
  67. <li>Open File Explorer and the new RAM disk should be listed as a usable NTFS drive</li>
  68. </ol>
  69. <h2>Re-creating the RAM Disk on Boot</h2>
  70. <p><em>After the RAM disk has been setup initially, follow the steps below to have it recreated on system boot.</em></p>
  71. <ol>
  72. <li>Open a text editor</li>
  73. <li>Paste the following Powershell commands, changing the size as needed
  74. <p>New-IscsiVirtualDisk -Path &quot;ramdisk:RAMDisk.vhdx&quot; -Size 256MB<br />
  75. Add-IscsiVirtualDiskTargetMapping -TargetName RAMDisk -DevicePath &quot;ramdisk:RAMDisk.vhdx&quot;<br />
  76. Get-Disk | Where partitionstyle -eq &#39;raw&#39; | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -DriveLetter R -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel &quot;RAMDisk&quot; -Confirm:$false</p>
  77. </li>
  78. <li>Save the file as ramdisk.ps1 to a safe location to run from, c:\scripts for example</li>
  79. <li>Click on the Start Button &gt; Type task &gt; Launch Task Scheduler</li>
  80. <li>Right click the Task Scheduler Library folder in the left pane &gt; Create Basic Task...</li>
  81. <li>Set the name to RAM Disk and optionally set a Description &gt; Click Next</li>
  82. <li>For the Trigger, select When the computer starts &gt; Click Next</li>
  83. <li>For the Action, select Start a program &gt; Click Next</li>
  84. <li>In the Program/script field, paste the following:
  85. <p>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</p>
  86. </li>
  87. <li>In the Add arguments field, paste the following, editing the path to the .ps1 file if necessary:
  88. <p>&quot;C:\Scripts\ramdisk.ps1&quot;</p>
  89. </li>
  90. <li>Click Next</li>
  91. <li>Check the Open the Properties dialog for this task when I click Finish box</li>
  92. <li>Click Finish</li>
  93. <li>In the Properties dialog, click the Change User or Group... button</li>
  94. <li>Type system &gt; Press Enter</li>
  95. <li>Check the Run with highest privileges box</li>
  96. <li>Click OK to create the scheduled task</li>
  97. <li>Reboot the server to verify the RAM disk is re-created automatically</li>
  98. </ol>
  99. </div>
  100. </div>
  101. </body>
  102. </html>