Mounting ISO images with powershell inside windowsservercore fails - powershell

I am trying to perform an unattended install of SQL Server on Windows Server Core in Docker. But it throws this error: A virtual disk support provider for the specified file was not found.
Does anybody know how to make Mount-DiskImage work on Windows Server Core?
RUN #echo off && `
aws s3 cp s3://mybucket/en_sql_server_2016_developer_with_service_pack_1_x64_dvd_9548071.iso C:\en_sql_server_2016_developer_with_service_pack_1_x64_dvd_9548071.iso && `
for /f "delims=" %%A in ('#powershell -NoProfile -ExecutionPolicy Bypass -Command "(Mount-DiskImage -ImagePath C:\en_sql_server_2016_developer_with_service_pack_1_x64_dvd_9548071.iso -PassThru | Get-Volume).DriveLetter"') do set "ISO_DRIVE_LETTER=%%A" && `
echo Mounted SQL install image to drive %ISO_DRIVE_LETTER% && `
echo Setting up SQL Server.. && `
%ISO_DRIVE_LETTER%:\Setup /ConfigurationFile=SQLInstallConfig.ini
P.S.: I have tried to copy the ISO image directly onto the docker container and got the same result. So it doesn't seem to be a corrupted image.

As of August 2021 this is still not possible to mount disk images within a Windows Docker container. I've tried resolving this myself enough times, the furthest I've gotten is a vague mention of a "missing virtual DVD feature", though I can't find any features mentioning "virtual DVDs" or mentioning mounting images.
As a workaround, you can either extract the disk image/ISO to a folder or mount the image within the host. Then expose the directory path to the container.
Neither of these are perfect solutions when scripts or packages you don't maintain might attempt to download and mount a disk image/ISO as part of its own setup process. However, software installers or packages which do want a disk image as an external source oftentimes provide a parameter to specify an alternative installation source location so you may be able to find a suitable workaround in these scenarios.

Related

Taking ownership of remote registry keys in PowerShell

I need to take ownership of a remote registry key across the network in order to delete it but I'm struggling to work out how. PSRemoting is turned off and needing to download additional software etc to do so is untenable (this is part of a toolset script that is used by multiple teams).
Thus far I've tried doing it using REGINI but always get the same error
REGINI: CreateKey (\\computername\HKU\SID\software\microsoft\windows NT\currentversion\windows) relative to handle (000000000) failed - 161
REGINI: Failed to load from file 'acl.txt' (161)
Has anyone else had the need to do this and found a good solution?
Thank you.
Have you tried psexec in conjunction with the regini command?
psexec -s \\computername regini c:\temp\acl.txt
Don't forget to copy the acl.txt to target computer's c:\temp folder.

Docker build for Matlab Compiler Runtime on Windows (non-interactive installation)

I notice that some steps in the Docker build takes more time than manually executing the same command in the container. To provide some context, the process of installing Matlab Compiler Runtime (MCR) is as follows:
Download MCR installer from MathWorks website
Unpack installation files
Run /bin/win64/setup.exe -mode silent -agreeToLicense yes (non-interactive install)
I created the following Dockerfile to set up MCR on a Microsoft windowsservercore image including dotnet-framework.
# Line 1: Use dotnet-framework base image
FROM microsoft/dotnet-framework
# Line 2: Download MCR installer (self-extracting executable) and save as ZIP file
ADD https://www.mathworks.com/supportfiles/downloads/R2014b/deployment_files/R2014b/installers/win64/MCR_R2014b_win64_installer.exe C:\\MCR_R2014b_win64_installer.zip
# Line 3: Use PowerShell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Line 4: Unpack ZIP contents to installation folder
RUN Expand-Archive C:\\MCR_R2014b_win64_installer.zip -DestinationPath C:\\MCR_INSTALLER
# Line 5: Run the setup command for a non-interactive installation of MCR
RUN Start-Process C:\MCR_INSTALLER\bin\win64\setup.exe -ArgumentList '-mode silent', '-agreeToLicense yes' -Wait
# Line 6: Remove ZIP and installation folder after setup is complete
RUN Remove-Item -Force -Recurse C:\\MCR_INSTALLER, C:\\MCR_R2014b_win64_installer.zip
I build a new image using the command:
docker build -t analytics/dotnet-mcr --no-cache --force-rm .
The installation of MCR is very slow, when compared to stopping at Line 4 and then manually running the MCR setup from a container based on the ensuing image (using the exact same PowerShell command)... any reason why needs an extra 3-4 minutes when performing the same step via the Dockerfile based build?
Note: Best practices suggest using a download utility versus using ADD, but I don't have any constraints related to image size since I am removing intermediate images as well as deleting the downloaded installer and unpacked installation folder. Plus, I like seeing the cleaner download progress bar of the ADD command.
I appreciate any improvements/optimizations that may be suggested.
Docker uses layers. According to it documentation each RUN command will create a layer. In your scenario, each layer will store the data related to the RUN command, so removing MCR_R2014b_win64_installer.zip as separate step will cause extra space in previous layers. I would recommend reducing RUN commands where it is possible.
Please check repo for more help.

How can I make a SSH tunnel command into a service on Windows 10?

I have a very simple command in powershell to start SSH tunnels:
ssh -N -L 28777:localhost:28778 myapp-db
What's the simplest way to make this a service, so I can run:
start-service db-tunnel
etc on Windows 10? I've read an old article on doing this and it involves using C#, which seems way too complex for such a simple task.
PowerShell is not necessary. Here's one way:
Install the Windows Server 2003 Resource Kit Tools package somewhere and get the files instsrv.exe and srvany.exe.
Use srvany.exe to create the service using the ssh.exe program and its parameters using the information in Microsoft help article 137890.
For example:
instsrv "SSH Server" "C:\Program Files (x86)\Resource Kit Tools\srvany.exe"
Of course, specify whatever service name you want and the path and filename of srvany.exe.
Next, use the registry editor to go to HKLM\SYSTEM\CurrentControlSet\Services\SSH Tunnel (or whatever you named the service) in the registry and create a Parameters subkey. In the Parameters subkey create an Application value (REG_SZ type):
C:\Program Files (x86)\ssh\ssh.exe
(or whatever - the path and filename to your ssh executable).
You can also create the values AppDirectory (REG_SZ) to specify the starting directory for the executable, and AppParameters (REG_SZ) to specify the parameters to the executable; e.g.:
-N -L 28777:localhost:28778 myapp-db
You can substitute the use of the NSSM tool mentioned by BenH in his comment if you prefer that tool and are allowed to use third-party software.
To make something into a service, you would need to compile your script into an executable. This can be done via PS2EXE.
What may work just as well for you is making a function in powershell, Start-DbTunnel, and making that import into your powershell session on start. You can do this by loading functions in the foloowing path:
$PSprofilePath\Microsoft.PowerShell_profile.ps1
or for the ISE
$PSprofilePath\Microsoft.PowerShellISE_profile.ps1
Inside those files, I have
$PSprofilePath = "C:\Users\cknutson\Documents\WindowsPowershell"
$items = Get-ChildItem "$PSprofilePath\functions"
#Set-Location "$PSprofilePath\functions"
$items | ForEach-Object {
. $_.FullName
}
Set-Location C:\
Any scripts containing functions, or otherwise will be run each time you open a powershell host.

How to use Volume Shadows Copy and Robocopy on Win7?

I’d like to backup my system with Robocopy and Powersell but Robocopy is not able to copy opened files.
Volume Shadows Copy seems a solution but I don’t find any clear and simple explanation how to use it.
Do you have any idea?
I’m running on Windows 7 x64 Enterprise.
Thanks for your help.
Franck
In order to perform a VSS snapshot on Windows 7, you can simply do a "System Restore". After, open an administrator console, type vssadmin list shadows. You are looking for the "Shadow Copy Volume" line in the most recent snapshot. Copy this, and do mountvol X: YOUR_VSS_PATH, and your VSS snap will be mounted on X:. After that, run robocopy on X: and you should be good to go.
You can mount the VSS shadow using mklink command. This Works in Servers and Workstations.
mklink is a native tool.
For example:
mklink /D C:\shadow_volume_1 \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\
More information can be found here: http://forensicswiki.org/wiki/Mount_shadow_volumes_on_disk_images

Unable to run PostgreSQL as Windows service

I had this in my Windows services:
C:/Program Files/PostgreSQL/8.4/bin/pg_ctl.exe runservice -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w
It never finishes executing. But if I did this on the dos shell:
C:/Program Files/PostgreSQL/8.4/bin/pg_ctl.exe start -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w
Notice that I only changed the "runservice" to "start" and it works just fine.
Any idea?
The command runservice can only be executed by the service manager
in order to fix my localhost windows 7 to start postgres as a service
i used the following command to start the data
pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" start
Then checked the status for errors
pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" status
if you get error 1063 , its more than likely permissions, i executed the following command
cacls "C:\Program Files\PostgreSQL\9.1\data" /E /T /C /G postgres:F
then reran the start/status, it showed everything fine, but still service manager would not start the service
So, in Services->postgresql->options->logon i set the log on as the Local system account instead of the postgres user, and voila it worked
this happened to me because i set my data directory to be somewhere the postgres windows user account didn't have access to.
I had this problem in Windows after a system crash. Running the first command showed invalid data in C:\Program Files\PostgreSQL\9.1\data\postmaster.pid. Deleting that file did the trick. Reference.
I faced the same issue after moving manually the database data files (PG_DATA directory) without recreating all the necessary permissions.
Here is how I solved my issue:
1. Check permissions on old PG_DATA directory:
cacls "c:\path\to\old\pgdata\dir"
2. Check permissions on new PG_DATA directory:
cacls "d:\path\to\NEW\pgdata\dir"
3. Compare outputs from 1. and 2.
Find the differences between users and/or permissions then synchronize them.
Nota: I found it easier to use explorer for the synchronization step rather than using cacls directly from the command line.
If you changed pg_hba.conf , maybe you missed somewhere in file. For example there must be CIDR after IP in that file. It must be like 192.168.1.100/32
If you forgot to put 32, then server doesnt restart.
Investigation of startup logs could be a clue. For the case problem is in the pg_hba.conf you could see something like this:
2018-11-13 00:39:34.841 PST [8284] FATAL: could not load pg_hba.conf
2018-11-13 00:39:34.842 PST [8284] LOG: database system is shut down
You need to check your logfiles and the windows eventlog for some hint of what the problem is. If there is nothing at all there, you need to break out something like Process Monitor and get a stacktrace of where it's hung.
I have had this issue in the past, and it was that the installer did not set up the permissions correctly for the user that the service was to run as.
I've also ran into this problem with postgresql throwing and error after trying to initialize the database cluster. After analyzing the log files and running command line scripts for 4 hours I've got the solution to anyone running into this problem for Windows Versions.
This is not a detailed description as to why its happening. I've installed odoo 10, 11, 12 and 13 numerous times on countless client servers and windows systems and this is the first time I've ever ran into this problem. I cant say if its because I have MS VS Enterprise installed and Android Studio on this machine or what. But Below is the easy answer on how to fix it and initialize the cluster and create the database files in the data folder.
Open the data folder for postgresql. - For Odoo installs it will normally be "C:\Program Files (x86)\Odoo 13.0\PostgreSQL" Unless you chose another location when installing.
Remove any or all files from this folder - If not you will get an error when running initdb.exe
Right click the data folder and open up the properties for it. Click on the Security tab and then click the advanced button on the bottom.
You need to change the owner of this folder to openpgsvc. Click Change and type in openpgsvc and click ok. Once done click the check box below saying that you want this change to affect containers with this container as well.
Then on the Permissions tab click the add button on the bottom. You need to add openpgsvc as a user and give this user full rights. Click apply and and ok to close out of all the folder properties.
Now you need to open cmd.exe - Once open we are going to call initdb.exe and pass some values to it as well.
First run chdir and change the working directory to the location of initdb.exe. For me, running odoo 13 on a windows 10 machine the location is this..
"C:\Program Files (x86)\Odoo 13.0\PostgreSQL\bin"
There is one variable that need to be passed as well to make this work here is the list. NEEDS TO BE INCLUDED IN THE CALL TO initdb.exe
Postgres Data Dir: "C:\Program Files (x86)\Odoo 13.0\PostgreSQL\data"
The End Result with the parameter would look like this for my installation:
"C:\Program Files (x86)\Odoo 13.0\PostgreSQL\bin\initdb.exe" -D "C:\Program Files (x86)\Odoo 13.0\PostgreSQL\data"
Hit Enter and let it rip. The output of this command should look like this below.
Cmd.exe running initdb.exe script
Make sure there is no buggy empty file Program at C:\ like C:\Program
In this case, explorer will warn whenever you log on into Windows.
File Name Warning
-----------------
There is a file or folder on your computer called "C:\Program" which
could cause certain applications to not function correctly. Renaming it
to "C:\Program1" would solve this problem. Would you like to rename
it now?
Installing PostgreSQL 10 On Windows 7 (yes the clock is ticking...). I first tried the latest version 11 which completely failed to install... not a good sign for Windows users. Anyway.
Quick answer: Change the account in the Windows Services panel from Network to Local.
Details of my case
During installation I created/selected a data folder in the user profile folder, because obviously the folder suggested by default, within the program folder, wouldn't work, and if it worked it would be a very idea to put data here (I don't know whether it's usual to do that on Unix/Linux, but for Windows it's it's not allowed for a long time).
At the end (when populating the data cluster) I received an error:
Failed to load SQL Modules into database Cluster
but the installation was able to complete. I found two pages about previous error, here and here, but they didn't seem relevant to my case, so I just started pgAdmin and, on the left "browser", saw the server wasn't active.
I tried to start it from here (had to type the main password), but it went inactive immediately again. So I tried to use the Windows services panel to start "postgresql-x64-10", no joy. I copied the command from this panel and pasted it into a Windows console (cmd.exe) where I finally received this
error 1063.
Searching I found this related question, and was convinced the problem was about permissions.
Solution working for my case
In the services panel I changed the account used to start the service from Network Service to Local System as suggested in a comment by #AlexanderRios.
sc create "postgresql-9.2" binPath= "\"C:/Program Files (x86)/PostgreSQL/9.2/bin/pg_ctl.exe\" runservice -N \"postgresql-9.2\" -D \"C:/Program Files (x86)/PostgreSQL/9.2/data\" -w" DisplayName= "postgresql-9.2" start= auto
Try this on CMD run as Administrator
(Add your parameters depend on your version)
Stop all postgres processes
Go to the postgres data folder (C:\Program Files\PostgreSQL\9.6\data)
Delete the postmaster.opts and postmaster.pid files
From the control panel, in administrative
tools and the services console start the postgres service
open pgAdmin III and then in right pane find server then just right click and connect, enter the password. after connected go to the browser and refresh ODOO. Problem solved.
See image to get better understanding