tmcdos / ramdisk

Replacement (GUI + windows service) for ImDisk Toolkit - by using Arsenal Image Mounter as a driver for RAM-disks.
MIT License
40 stars 7 forks source link

Automated service install #6

Open Paruccone opened 1 month ago

Paruccone commented 1 month ago

I'd like to integrated this solution in my NTlite image to install and configure a 16GB ramdisk at system install but I see no doc on how to do that. NTlite can install drivers (easy part), copy files, run commands/scripts, add registry entries. So it's easy to add the driver but howto configure the service?

I tried both ramdiskui.exe /? and eamservice.exe /? and they produce no output :(

Thx!

tmcdos commented 1 month ago

You are right - there is no built-in help information at the moment. I will add such information in the next days. If you have not looked at the source code yet, here is some information about the registry values:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\ArsenalRamDisk]
"DiskSize"="17179869184"
"DriveLetter"="Z"
"LoadContent"="D:\\Setup\\RAM_disk"
"ExcludeFolders"="chrome
opera
phpstorm
stoplight
_
0
1
2
3
4
5
6
7
8
9"
"UseTempFolder"=dword:00000001
"SyncContent"=dword:00000001
"DeleteOld"=dword:00000001
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"ImagePath"=hex(2):44,00,3a,00,5c,00,53,00,4f,00,55,00,52,00,43,00,45,00,5c,00,\
  44,00,45,00,4c,00,46,00,49,00,5c,00,52,00,41,00,4d,00,64,00,69,00,73,00,6b,\
  00,5c,00,52,00,61,00,6d,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,2e,00,\
  65,00,78,00,65,00,00,00
"DisplayName"="Arsenal RAM-disk"
"WOW64"=dword:00000001
"ObjectName"="LocalSystem"
"Description"="Arsenal RAM-disk"

DiskSize is the size in bytes DriveLetter is obvious LoadContent is path to a folder whose contents will be pre-loaded in the RAM-disk at startup ExcludeFolders is StringList (lines delimited with CRLF) which specifies which folder names from the RAM-disk won't be saved on shutdown in the folder specified by LoadContent. I usually create numeric folders in my RAM-disk for my daily projects - but I don't want them to be persisted on disk because I can pull them with Git every morning. UseTempFolder - whether to create TEMP folder on RAM-disk and point the OS to this temp folder SyncContent - whether to save RAM-disk content on shutdown to the folder specified by LoadContent DeleteOld - whether to delete those files and folders from LoadContent which are not present on the RAM-disk on shutdown (meaningful only when SyncContent is TRUE)

The remaining values are created when the service is installed by RamService.exe /install - e.g. ImagePath points to the full path of RamService.exe. I don't know how NTlite pre-installs services but I hope this information will help you.

Paruccone commented 1 month ago

Hi! Thank for your quick and in-depth answer. As I wasn't expecting such a quick one, and as I have few and old reminiscences of C/Pascal development back in the 90''s not allowing me to go through the source code, I tried to manually install the bundle and see what was done. RAMDISKUI.exe seems to work fine: I can mount/unmont/install/uninstall service. Problem being that the service won't work: it appears as started but no RAMDISK created and I wasn't able to find any relevant output in event viewer. I hoped for some permission issues and tried to install both the EXEs elsewhere but nothing.

But I was indeed able to identify the generated output: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ArsenalRamDisk] "Type"=dword:00000010 "Start"=dword:00000002 "ErrorControl"=dword:00000001 "ImagePath"=hex(2):43,00,3a,00,5c,00,41,00,72,00,73,00,65,00,6e,00,61,00,6c,00,\ 5c,00,52,00,61,00,6d,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,2e,00,65,\ 00,78,00,65,00,00,00 "DisplayName"="Arsenal RAM-disk" "WOW64"=dword:0000014c "ObjectName"="LocalSystem" "Description"="Arsenal RAM-disk"

Which, when I understand and fix why the drive isn't being created, I could integrate in NTLite: 1) Arsenal driver (done) 2) .reg file with the registry branch for the service 3) File copy 4) Service install

to have the ramdisk transparently integrated; more than glad to document the process in here.

Speaking of which, I think there's a mistake in the instructions provided here: there's a "cd xxxx\file.exe" and we all know we can't cd into a file ;) thx again!

tmcdos commented 1 month ago

I assume you're referring to this shot-1 You are correct - it was a copy/paste from the report of another user. Should be fixed now. Can you use https://learn.microsoft.com/en-us/sysinternals/downloads/debugview (start it before the RamDisk UI) to see if there are any errors output by the program? If you see no errors there - I can make a special build for you with run-time exceptions capturing to see if you can catch the reason for this tool not working on your machine. If you are trying it on Hyper-V - it may fail but I have no idea why. Please make sure that you're trying on a real Windows OS. Can you also confirm that the driver is installed? You should see it in the DeviceManager, like this: shot-2

Paruccone commented 1 month ago

1) reference is correct. 2) I will setup and run sysinternals in the weekend and report back 3) Yes, driver is installed: if I apply now, the ramdisk gets creating, env variables are created, etc. everything is fine (but not persistent) 4) no, physical environment, but truth be said I'm using a slightly stripped down environment (tiny11, but I would expect missing dependencies to prevent the ramdisk to mount, not the service to work).

tmcdos commented 1 month ago
  1. There is no need for setup - you just need to extract the portable EXE from the ZIP and run it.
  2. By "not persistent" you mean that the service does not autostart on boot, right ? This does not sound so severe as I thought initially. If the RAM-disk actually mounts and you can read and write files from it - then we only need to discover why the service does not start on boot.
  3. If the driver is installed - the most practical reason for the RAM-disk not to mount is if the buffer size for QueryDosDevice in Definitions.pas is insufficient. But if I understood correctly - you are able to mount and use the RAM-disk.
Paruccone commented 1 month ago
  1. not persistent: the service starts (looks as running in MMC) but the ramdrive doesn't get created/show up
  2. I can open the GUI, save&apply now and everything works. I can unmount/remount. I can also uninstall/install the service but the service itself does literally show no effect (correctly responds to start, stop, restart)
tmcdos commented 1 month ago

Okay, so it is confirmed that the RAM-disk works - i.e. you can copy files to it and then delete them. I will then add more logging to the debug output that you can inspect through the above utility DbgView64 by SysInternals. There will be a new release in a few days, when I get some free time :)

Paruccone commented 1 month ago

when I open RamdiskUI debugview populates with: [8072] The system cannot find the file specified

Then I create (save&apply now) a 32GB ramdisk on T with the option to set temp variables and the debug gets populated with: [8072] The operation completed successfully [8072] The operation completed successfully

The ramdisk gets up&running, light in UI goes green. Then I click on Install service and I get the "Service installed succesfully" message. If I try to start the service at this moment I get a popup with "The Arsenal RAM-disk service on Local Computer started then stopped. Some services stop automatically [...]". Which I guess is normal as I didn't restart.

In the meanwhile 2 additional entries appeared in the debug: [14304] Suspending [14304] Suspending

Going to restart my PC and write the rest ;)

Paruccone commented 1 month ago

so, the service didn't start at reboot. If I open event viewer and click on details, I get "MMC has detected an error in a snap-in and will unload it". This doesn't happen if I click on Details for other events (warning/info).

All of this having everything under C:\Arsenal

Weird as this wasn't the case before. Going to restart again. Does it matter in order to install service if we save&apply now or save and apply after reboot? what about removing and reinstalling service?

Tried on same HW, different OS system part (a complete one) and same issue except for the fact that event viewer works fine and the details say the command ran succesfully :) I think we need some more in depth tracing starting from that missing file...

tmcdos commented 1 month ago

The difference between Apply now and Apply later is that the latter simply writes the values in the registry and nothing more, while the former first saves the settings in the registry, then unmounts the RAM-disk (if it is currently mounted) and then creates and mounts the RAM-disk with the new values. I will add more logging tomorrow. Stay tuned.

tmcdos commented 1 month ago

Can you uninstall the old service and install this one? It has more logging but not 100% coverage. And if possible, can you post screenshots from DbgView64 ? RamService.zip

Paruccone commented 1 month ago

same identical behavior: Screenshot 2024-07-28 112650

Screenshot 2024-07-28 112905

I guess the error about the file could come from having temp variables set to T:\ which at time of launch of ramdiskUI is non-existing which seems to be confirmed because if I run the UI while T exists I don't get the error.

But after restarting now it works (RAMDISK is created and available)! :)

tmcdos commented 1 month ago

To disprove this hypothesis - you can configure the RAM disk to not change the TEMP folder/variables. These variables are set only after the RAM-disk is successfully mounted and formatted with a filesystem. If you do not see RamDisk service was started in DebugView - this means that the service has not been properly started because it is the first statement

procedure TArsenalRamDisk.ServiceStart(Sender: TService; var Started: Boolean);
begin
  OutputDebugString('RamDisk service was started');
  LoadSettings;
  if (config.size<>0) then
  try
    if CreateRamDisk(config,False) Then Started:=True;
  except
    On E:ERamDiskError do decodeException(E.ArsenalCode);
    On E:Exception do OutputDebugString(PAnsiChar(E.Message));
  End;
end;

Can you also make sure that you are running DebugView as Administrator and that there is a checkmark at Capture global Win32 in the Capture menu ? You can restart (or stop + start) the service to see if there are debug messages.

Paruccone commented 1 month ago

"capture global": Wasn't checked by default :)

I guess temp variables were permanently modified by Primo, will fresh reinstall the system (running various tests to get my "ultimate" image) and retry. Can you please confirm the following unattended procedure on a new system should work to have the service installed?

1) install arsenal driver 2) add registry branch/keys 3) run RamService.exe /install

Thx!

tmcdos commented 1 month ago

What is Primo? It is not advisable to point TEMP variables to a non-existent drive/folder. I think that you should swap points (2) and (3) and only include in the REG file the custom variables - i.e. exclude things like ImagePath, description, WOW64, etc. I will replace OutputDebugString with events for EventViewer and publish a new version of the service.