安装Windows Server 2012 2016 2019 2022 RAM Disk Setup Guide
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
Click Manage > Add roles and features
Click Next on the Before you begin screen
Select Role-based or feature-based installation > Next
Leave Select a server from the server pool selected and select the current server > Next
Expand File and Storage Services > Expand File and iSCSI Services > Select iSCSI Target Server
A popup will appear with additional required roles and features, click the Add Features button
Click Next
Click Next on the Select features screen
Click Install on the confirmation screen
Leave the installation progress screen open until the install completes
Creating the RAM Disk
Launch Powershell as administrator
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:\SOFTWARE\Microsoft\iSCSI 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"
Back in Server Manager, select Tools > iSCSI Initiator
Enter the IP address in the Target field > Click Quick Connect...
Click Done
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
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.
Open a text editor
Paste the following Powershell commands, changing the size as needed