An Adventure in Windows Core
So, all the FreeBSD experience in the world counts for very little when you run into that game server that just simply won’t run on anything but Windows. A while back, I followed some directions to get Windows Server 2016 on bhyve on FreeBSD-CURRENT (11). I found it very clunky to deal with - as one of the things the scripts (at least at the time) did was to install Windows Server 2016 Core. I hadn’t realized it at the time, but Windows Server 2016 TP4 Core is very stripped down. It doesn’t even support installing the GUI tools to do Remote Desktop Services. (At least not this install. Maybe there’s other install options that do.)
So I worked with it a bit, did the little process of connecting via the nmdm port to get a console, and then a command prompt on the Windows VM. I wasn’t really happy with this arrangement, it was painful, a bit slow, and the scrollback buffer on my terminal window was usually useless. I began a hunt for a new way to remote in, and eventually ran into a serverfault thread (http://serverfault.com/questions/8411/what-is-a-good-ssh-server-to-use-on-windows) where people began rattling off different SSH servers for Windows.
I eventually settled for the Bitvise SSH server (https://www.bitvise.com/ssh-server). Free for personal use, and supposedly pretty affordable for commercial use. (If you can call $100/license affordable, as your Windows Server costs just went up by 15%.)
Getting the SSHd installed.
The hard part was getting the installer on the damn server. Wait, this is Windows, we have Windows file sharing available to us.
md c:\files
net share files=c:\files
Then it’s just a matter of copying the file over to the server and installing it. Wait, most stuff in windows uses a GUI to do the installs, no? Thankfully, Bitvise’s installer actually has command-line support. BvSshServer-Inst.exe /?
gave me a bunch of options. I took the easy route:
BvSshServer-Inst.exe -defaultInstance -acceptEULA -startService
Fired up my ssh client to connect, and it just worked perfectly!
A tool for fetching files
Now, I know Windows has a tool built-in (though maybe requiring PowerShell) called BitsTransfer. Based on http://superuser.com/questions/387501/how-do-you-download-files-on-a-windows-server it should have worked just fine:
Import-Module bitstransfer
start-bitstransfer -source http://something/something.ext -destination c:\something.ext
But this kept leading me into an error:
start-bitstransfer : The operation being requested was not performed because
the user has not logged on to the network. The specified service does not
exist. (Exception from HRESULT: 0x800704DD)
So I looked around. I figured wget would be likely to have the best support for Windows, being so very popular of a tool. I’ve come to the conclusion its support on Windows is antiquated and terrible. So I looked to my next hope: cURL. I’ve used libcurl, and see its usage show up all over the place (especially in FreeBSD ports).
The hardest part here was finding which download to eventually use. I gave into something that worked (though maybe not the best solution). I used the curl Download Wizard to select curl executable
> Win64
> Generic
> Any
> x86_64
and then chose the last option, which took me to the http://www.confusedbycode.com/curl/ page. I don’t think I like their webpage, and I probably would have been just as well off with the 7z version from the curl download page, but this is what I went with. On confusedbycode’s page, I downloaded the curl-7.46.0-win64-local.msi, since I expected an MSI to have the best support.
So, MSI installs have a semi-convenient installer option from the command line.
msiexec /q /qn /l* logfile.txt /i curl-7.46.0-win64-local.msi
This installs the MSI, /q is for quiet, /qn is for quiet-no prompts, /l* logs everything to logfile.txt, and /i is to specify the installer file. There’s a whole slew of things for setting variables (that the MSI would normally ask you about), but I just needed the basic install from this package.
Now, here’s how I know I should’ve done something different - and if you’re following along, you know what’s wrong. The install is into the user’s appdata/local folder. So, all this monkeying around basically taught me how to run MSIs, but hasn’t properly installed curl for me. I didn’t want to muck around any more, but I did want curl for all users in the system. So I utilized robocopy, rmdir/rd, and wmic to adjust things:
- Copy the folder over (robocopy)
- Delete the old folder
- Adjust the global environment path - curl messes with this, so we need to clean it up. Your path my vary, so check it first!
echo %PATH%
cd /Users/TEMP.WINVM/appdata/local
robocopy /E cURL "c:\program files\cURL" /COPY:DAT
rd /s /q cURL
wmic environment where name='PATH' set VariableValue='%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%programfiles%\cURL\bin'
Now when I logged out & back in, my path was correct for the new location for cURL! Fantastic, I have cURL support!
curl http://www.google.com
(or if you’re downloading a file: curl -O http://mysite/file
)
ZIP utilities
Windows doesn’t seem to have a built-in command-line zipfile utility. And with no GUI, we don’t get a zipfile utility at all. Enter one of my favorite tools for windows: 7-zip (http://7-zip.org). Their actual download page has an MSI installer, so we can utilize that.
Of course, they use a redirect on their link, so we’ll need an extra parameter to curl:
curl -O -L http://7-zip.org/a/7z1514-x64.msi
(your link may vary, due to version updates.) The -L parameter makes curl follow redirects.
Now we just install 7zip..
msiexec /q /qn /l* 7z_log.txt /i 7z1514-x64.msi
Ok, so, the command is 7z.exe… But, this is Windows, and there’s not a standard location for programs, so everything has its own directory. Another little path update is needed, this time just appending it to the end, since we don’t need to remove any cruft:
wmic environment where name='PATH' set VariableValue='%PATH%;%programfiles%\7-zip'
Now after refreshing our path (I actually don’t know how to do this, I just logged out/in, since it was easy), we can execute 7z
.
What’s still missing?
So, this is my current state. I’d love to have a tool like tmux installed, but it seems that the users who want something like tmux on Windows largely just want some sort of multiple or tabbed terminal windows. I’m after the detach/reattach feature, but I’m not sure if Windows can even handle it correctly. The application I wanted to run was the 7 Days To Die server, which spawns itself into the background anyway, so it’s a non-issue for me at this point.
Past this, I’ve actually found the Windows Server Core experience to be pretty interesting. I like that Microsoft has gotten really close to a point where most of the stuff you do on Windows could be done on a command line. I think they sort of tried this with Server 2012, but Server 2016 has this massive push to be mostly headless. There’s rumors that MS might even include a built-in SSHd as well, but it’s obviously not part of 2016 TP4.