Windows Server RAM Disk Setup Guide [2012 2016 2019 2022]



Windows Server RAM Disk Setup Guide [2012 2016 2019 2022]

Windows Server RAM Disk Setup Guide [2012 2016 2019 2022]

#Windows #Server #RAMDisk

Full steps can be found at https://i12bretro.github.io/tutorials/0524.html

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
 
——————————————————————–
Installing iSCSI Target Server
——————————————————————–
   01. Launch Server Manager if it does not automatically load     
      a. Click the Start button ≫ Server Manager     
   03. Click Manage ≫ Add roles and features
   04. Click Next on the Before you begin screen
   05. Select Role-based or feature-based installation ≫ Next
   06. Leave Select a server from the server pool selected and select the current server ≫ Next
   07. Expand File and Storage Services ≫ Expand File and iSCSI Services ≫ Select iSCSI Target Server
   08. A popup will appear with additional required roles and features, click the Add Features button
   09. Click Next
   10. Click Next on the Select features screen
   11. Click Install on the confirmation screen
   12. Leave the installation progress screen open until the install completes
 
——————————————————————–
Creating the RAM Disk
——————————————————————–
   01. Launch Powershell as administrator
   02. Enter the following commands to create the RAM disk, replacing the IP address with the current server’s IP address
         # allow iSCSI loopback registry setting
         Set-ItemProperty -Path ‘HKLM:SOFTWAREMicrosoftiSCSI Target’ -Name AllowLoopBack -Value 1
         # start the iscsi initiator service
         Start-Service -Name MSiSCSI
         # set the iscsi initiator service to start automatically
         Set-Service -Name MSiSCSI -StartupType Automatic
         # create the ram disk, changing size as needed
         New-IscsiVirtualDisk -Path “ramdisk:RAMDisk.vhdx” -Size 256MB
         # initialize iSCSI target
         New-IscsiServerTarget -TargetName RAMDisk -InitiatorIds @(“IPAddress:192.168.0.65”)
         # connect to the ram disk
         Add-IscsiVirtualDiskTargetMapping -TargetName RAMDisk -DevicePath “ramdisk:RAMDisk.vhdx”
   03. Back in Server Manager, select Tools ≫ iSCSI Initiator
   04. Enter the IP address in the Target field ≫ Click Quick Connect…
   05. Click Done
   06. Back in Powershell, run the following command
         # initialize the disk as NTFS
         Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -DriveLetter R -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel “RAMDisk” -Confirm:$false
   07. Open File Explorer and the new RAM disk should be listed as a usable NTFS drive
 
——————————————————————–
Re-creating the RAM Disk on Boot
——————————————————————–
After the RAM disk has been setup initially, follow the steps below to have it recreated on system boot.
 
   01. Open a text editor
   02. Paste the following Powershell commands, changing the size as needed
         New-IscsiVirtualDisk -Path “ramdisk:RAMDisk.vhdx” -Size 256MB
         Add-IscsiVirtualDiskTargetMapping -TargetName RAMDisk -DevicePath “ramdisk:RAMDisk.vhdx”
         Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -DriveLetter R -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel “RAMDisk” -Confirm:$false
   03. Save the file as ramdisk.ps1 to a safe location to run from, c:scripts for example
   04. Click on the Start Button ≫ Type task ≫ Launch Task Scheduler
   05. Right click the Task Scheduler Library folder in the left pane ≫ Create Basic Task…
   06. Set the name to RAM Disk and optionally set a Description ≫ Click Next
   07. For the Trigger, select When the computer starts ≫ Click Next
   08. For the Action, select Start a program ≫ Click Next
   09. In the Program/script field, paste the following:
         C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
   10. In the Add arguments field, paste the following, editing the path to the .ps1 file if necessary:
         “C:Scriptsramdisk.ps1”
   11. Click Next
   12. Check the Open the Properties dialog for this task when I click Finish box
   13. Click Finish
   14. In the Properties dialog, click the Change User or Group… button
   15. Type system ≫ Press Enter
   16. Check the Run with highest privileges box
   17. Click OK to create the scheduled task
   18. Reboot the server to verify the RAM disk is re-created automatically
 

### Connect with me and others ###
★ Discord: https://discord.com/invite/EzenvmSHW8
★ Reddit: https://reddit.com/r/i12bretro
★ Twitter: https://twitter.com/i12bretro