Ok? Do I have a choice??
Living with the Evil Empire :)
Windows Services for Linux aka Ubuntu on Win10
wsl --user root # launch a root session, no need to remember password :P
wsl -d Ubuntu-22.04 --user root # specify a distribution to use
wsl --list # list installed distributions
wsl --set-default Ubuntu-22.04 # set which distro get run for
wsl --update # update wsl... (does this NOT get done as part of windows update?)
WSL is official in Fail Creator Edition of Windows 10 (2017?), avail in Windoze App Store.
It is a Comptatibility Layer, no VM (hardware emulation), no recompilation.
It is like reverse of WINE.
Linux ELF binary is run directly on windows. WSL handles what would normally be linux kernel API calls.
It allows for userland process like bash.
Graphics mode stuff is not stable at this time (2017).
DBUS-X11, the interprocess messaging system in X11, is not avail in WSL at this time.
c:\windows\system32\bash.exe is a PE32+ executable. source code compiled to work on windows.
/bin/bash is ELF LSB executable.
VM is Hardware emulation.
ParaVirtualization is Hardware Emulation, but has extra API calls that allows for Guest OS to interact with paravirtual
layer to run hard-to-execute code directly on host domain env.
Can be better in performance, less translation, but require guest to be ported to utilize the ParaVirtualization API cal
ls (drivers from the ParaVM). eg: Xen hypervisor for Winwdows VM. pv-ops.
ls can behave very differently between wsl/bash vs cygwin, especially for drive mapped by tools like Google Streamd Drive.
old beta:
Ubuntu root "visible" on windows under c:\users\$USERNAME\AppData\Local\lxss\
But changing open files with windows tool would cause permanent data corruption, get file in locked state, and may require reinstall.
This maybe why in fall creator edition, the unix fs portion became an independent sub-system and not visible in windows. (this folder path isn't there anymore, even after unhiding system files).
The bads:
- Terminal is based on the DOS prompt window, cut and paste is tedious :(. ^C/^V may be helpful but not inside vim (2018.8)
- No tab support in terminal.
- ConEMU provides multiple tabs. But its far-manager heritage takes getting-used to. Behavior/config maybe changing over time too?
- No way to access linux subsystem files from Windows. I am putting all files on the windows side in /mnt/c/Users.
The meh:
- create sym links in WSL-bash ("ubuntu shell") (not cygwin or mobaXterm)
- wsl bash create symlinks as unix symlinks. cygwin can understand these.
- cygwin create symlink as NFS link? wsl-bash don't understand these, treat it as a file.
-
The decent:
- git works for files written to the windows side. file downloaded with Unix LF format remains so. vim will preserve this. Did not invoke UNIX2DOS conversion. Did not need git-for-windows :)
but git commit/push is having typechange problem, maybe permission... This could be real problem :(
for now, need to use git from WSL/bash.
- Ansible can be installed and it will work as ansible client/target. Well, for now, I am using it with "localhost", so it is not ssh in from some central server. But the Ubuntu is similar enough to say a VM running inside VirtualBox that largely the same playbook can be used in WSL instance.
The good:
- MS seems to have the heart in a good place (did i really think this??!! :P).
- if the comptability layer keeps up, WSL would actually provide the closest Linux environment short of running a VM. Better than Cygwin, probably better than macOS.
Ref:
- cepa article has a very extensive review of WSL.
- apt install xfce4-terminal should hopefully be enough and light to add a real linux terminal.
- hyper is a native windows app, maybe look into.
- Cmder vs ConEmu
unixy tool comparison in the wsl world
app: wsl/ubuntu cygwin mobaxterm ConEmu/bash
subsystem: wsl/bash cygwin bash.exe wsl/bash ?
------------- -------------------- ------------------- -------------- -------------------
/bin /bin in wsl fs subsys c:\cygwin\bin C:\Users\....AppData\Local\...\bin
bash /bin/bash, elf64 /usr/bin/bash, PE32 same as wsl/ubuntu
ls /bin/ls, elf64 /usr/bin/ls, PE32 same as wsl/ubuntu
$HOME /home/t (lxfs subsys) C:\cygwin\home\t C\tmp, C\cyg... /home/t || /mnt/c/Users/t [WinHome]
C:\ /mnt/c /cygdrive/c /drvies/c /mnt/c
C:\tin
G:\ /mnt/g, no ls /cygdrive/g /drives/g /mnt/g, no ls (invoked bash from wsl?)
nfs-links NOPE default for ln -s def for ln -s NOPE
unix-links default can handle can handle default
terminal "ubuntu" cygwin-term mobaXterm ConEmu
cut-n-paste ^C/^V ? could be boxy linux-style linux-style far-style?
$TERM xterm-256color xterm xterm xterm-256color
TERM=cygwin needed for arrow keys to work in vi
preference low mostly for config 1st (1st if configured on x1carb)
sudo use win password
pkg apt-get cygwin setup.exe build-in apt-get from wsl
git setup apt-get install git (using wsl) (use wsl)
git config not saved to ~/.git ?? :(
git /usr/bin/git, elf64 /usr/bin/git n/a /usr/bin/git
octave apt-get ins octave, didn't work
Notes
- cygwin without WSL may behave differently. cygwin has its own set of tools downloadable from the setup.exe tool
- ConEmu should be just using bash from wsl, thus should behave exactly the same as the ubuntu bash, except for the terminal emulation part.
- apt-get install octave in wsl didn't work. (there is a octave for windows, gui works, the .bat not yet). On mac, "brew install octave" worked very well. plots can launch GUI windows (cocoa? did not need to run X server).
-
Cygwin tweaks
Expect default home dir to be c:\cygwin\home\$USERNAME
export CygBaseDir="/cygdrive/c"
## $USER expect to be defined automagically, eg "t"
export CygUserBaseDir=${CygBaseDir}/Users/${USER}
ln -s ${CygBaseDir}/tin ./C_tin
ln -s ${CygUserBaseDir} ./WinHOME
ln -s ${CygUserBaseDir}/Desktop .
ln -s ${CygUserBaseDir}/Downloads .
# will run git clone in wsl , files in C:\tin, with sym links in there, no need for action here
ln -s /cygdrive/g ./Gdrv
ln -s /cygdrive/g/My\ Drive/class/MLcoursera .
ln -s /cygdrive/g/My\ Drive/class/MLcoursera_go1 .
MobaXterm tweaks
Expect home dir default to C:\temp or some transient location that is lost when program closes.
Manually change settings to put home dir to be same as cygwin, since it can access /cygdrive/c etc and thus share the sym links...
Then don't need to crate any symlinks under Moba settings. Only need to change its home dir.
Ubuntu bash (WSL) tweaks
Expect default home dir to be some obscure/inaccessible place mounted as /home/$USERNAME
export WslBaseDir="/mnt/c"
export UserBaseDir=${WslBaseDir}/Users/t
ln -s ${WslBaseDir}/tin ./C_tin
ln -s ${UserBaseDir} ./WinHome
ln -s ${UserBaseDir}/Desktop .
ln -s ${UserBaseDir}/Downloads .
# git repo is setup here, run psg/git.setup.gh.sh in wsl/ubuntu bash prompt
# stored in C:\tin
# with unix links here (cygwin generate ntfs-based links not usable here)
[[ -e tin-gh ]] || ln -s ${WslBaseDir}/tin/tin-gh ./tin-gh # git.setup.gh.sh may have set this up already
ConEmu tweaks
- Expect default home dir to be /mnt/c/Users/$USER # ie Windows Home dir for active user
- Import .xml config file with desired copy-n-paste, space, multiline dealing, etc (eg store in SkyDrive)
ln -s /mnt/c/tin ./C_tin
"Single User" recovery mode for WSL
stop all user level instance of wsl (ie, stop all bash process).
Preview/Beta C:\> lxrun /setdefaultuser root
Fall Creator C:\> ubuntu.exe config --default-user root
bash # this will get into elevated mode, but only after all user-level process have stoped
ubuntu run vi /etc/passwd
ubuntu run id
ubuntu /?
To return back to normal user mode:
ubuntu config --default-user jane
ref: ms doc.
Xserver
WSL doesn't provide an X-server. So, like the old days, a windows based X server software is needed.
Have not tried to run vncserver, but DBUS isn't avail, gnome-session has been reported not to work. Maybe some old school Desktop Env that does not use DBUS may work. Not sure if LXDE uses DBUS. twm should not :)
QMonkey at github has instructions to use xfce, even have way to fix DBUS error. Will also need to fix fonts (including unicode and chinese), but implies it has gotten to work.
Fenton's article reports x11-apps (xeyes), blockout2, works. firefox works but no a/v. vlc complains, but may have hacks.
- vcXsrv - small package. Compiled by VC++. Referred by QMonkey and other.
- Xming - Latest version is not entirely free anymore. maybe a tad slower than vcXsrv.
- Cygwin X - may come with the full Cygwin env, which maybe big for system using WSL or Git-for-windows.
-
- Exceed (moneyware)
See also vnc.html
Unix-fying Windows/DOS, from Windows 7 days
- Cygwin add a lot of standard unix tools, libraries, etc. Includes a bash shell and X Window Manager for running X-based (GUI) apps. It even has GNOME, KDE, keepassx (Qt), tetris!
add this to PATH system variable
c:\cygwin\bin;c:\cygwin\sbin;c:\cygwin\usr\bin;c:\cygwin\usr\sbin;
modern cygwin creates .bashrc in user's home dir and source that, so PATH can be setup there.
A somewhat yum-like feature to add new packages, eg python:
setup-x86_64.exe -P python
it still run the GUI, but then the python package is selected,
so can just click next/next/next to complete.
setup-x86_64.exe -M -P wget,curl,dog,openssh,ctorrent,openldap,nc,rsync
-M will skip many GUI prompt and go right into the package selection window.
openssh is for both client and server?
openldap is for the client portion only
apt-cyg (not fully stable) may provide an apt-get like command interface to install packages, one at a time.
wget http://raw.github.com/transcode-open/apt-cyg/master/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin
apt-cyg install nano
apt-cyg install git
apt-cyg install ca-certificates
- MKS Toolkit. This actually pre-date cygwin, but this is moneyware.
- SFU Microsoft Services for Unix. Add NFS client and server, telnet server, and other tools to bridge Unix and Windows machines. In the same manner that Samba teaches Unix to talk Windows, SFU teaches Windows to talk Unix.
Windows/DOS commands
Key bindings I like
Linux adopted most of them, wish the two were even more similar :)
shift win s = screen clipping, copy to clipboard [OneNote config?]
shift alt t = screen clipping, with additional markup tool [win 10 thing?]
PrtScr = Print Screen. But many program now tries to hijack it, so no consistent behavior
- Win 10 default: capture whole screen to clipboard ?
- OneDrive hijack: save to File in OneDrive ?
DOS/CLI commands
xcopy d:\ z: /s /e /c /f /z /h # xcopy from d: to z: , include sub dir, hidden file, etc.
robocopy s:\source\folder1 d:\destination\folder2 /e /move /copyall /tee /log+:robo.log /w:1 /r:2
# Robust copy, lot of options, separate tool from MS?
# /move = move files and dirs (hopefully not copy and delete if on same FS)
# /copyall = copy NTFS ACL, owner, and audit info also (these are not included by default)
# but if ACL cannot be copied, copy will fail (reported)
# /e = include sub dirs, even if empty
# /tee /log+:robo.log will do a "T" and append to log file
# /w:1 /r:2 = wait 1 sec before retry, max 2 retries
# (good if know waiting won't help unlock file, or will do multi-scan)
#
#
# Note that folder1 itself won't be moved, it is the content inside the folder
# It is more like folder1\* to folder2.
# But folder1 itself will be deleted if /MOVE is used.
# Don't think too much like Unix!
# Additional notes:
# File that cannot be moved (cuz it is locked)
# is not reported as error in summary (but as skipped?).
# But instead of whining and stopping if using the Win Explorer GUI,
# Robocopy will continue to move the next file.
#
# Files created after Robocopy completes its indexing are not touched.
#
# Redirecting output to a log file is good, as it is quite verbose.
# \\unc\path can be used.
#
# files that already exist in the destination are reported as EXTRA
# can be /purge if desired.
cacls = change acl's. NT cli version of solaris setfacl.
compact = file compression util (list, maybe set?)
type file | find /i "string"
# equiv to unix cat file | grep -i string
# the quotes MUST be used or
# find will complain with weired error message!
# /i = case Insensitive grep.
type file | findstr /i "string"
# similar to find above, but different binary...
rdisk = nt4 create emergency recovery disks (erd)
regback = registry backup (add on?)
title any text string desired
Set the DOS CLI window to have the desired title
bgjob prog arg
run bg job inside a telnet session
so that even if telnet goes away, job remains.
There is still probably a nohup.
---
BATCH script
Sample .bat file:
@echo off
CLS
assoc .dxp=dxpfile >NULL
REM ftype dxpfile="C:\winnt\system32\notepad.exe" "%%1"
echo.
echo.
echo.
echo.
if exist "C:\Program Files\TIBCO\Spotfire\3.0\Spotfire.Dxp.exe" (
ftype dxpfile="C:\Program Files\TIBCO\Spotfire\3.0\Spotfire.Dxp.exe" "%%1" >NULL
echo "Updated dxp extension for SpotFire 3.0
goto theend
)
if exist "C:\Program Files\TIBCO\Spotfire\2.1\Spotfire.Dxp.exe" (
ftype dxpfile="C:\Program Files\TIBCO\Spotfire\2.1\Spotfire.Dxp.exe" "%%1" >NULL
echo "Updated dxp extension for SpotFire 2.1
goto theend
)
echo "No SpotFire found in standard directory locations, no changes made."
:theend
echo.
echo.
pause
exit 0
variables:
set foo=bar
echo %foo%
:: may need the /A flag to indicate numeric content?
set /A num=123
:: this is a comment
REM this is another comment
eg beauti.bat script.
:: this batch script successfully run beauti java gui on wombat. run from dos prompt
:: (but untested whether windows version of java can correctly save xml file yet)
:: 2022.0803
::
:: BEAST_LIB="$BEAST/lib"
:: #java -Xms64m -Xmx1024m -Djava.library.path="$BEAST_LIB" -jar "$BEAST_LIB/beauti.jar" $*
set BEAST_LIB="C:\Users\tin61\tin-gh-inet-class-only\inet-dev-class\epi_info\BEASTv1.10.5pre_thorney_0.1.0\lib"
:: set BEAST_LIB="BEASTv1.10.5pre_thorney_0.1.0\lib"
java -Xms64m -Xmx1024m -Djava.library.path="%BEAST_LIB%" -jar "%BEAST_LIB%/beauti.jar"
:: # batch file, hopefully run windows java, and don't get problem with beauti not being able to save xml at the end...
Alternate Data Stream
echo "main stream" > stream.txt
echo "alternate stream" > stream.txt:ads
not supported in NFS.
Similar stuff on Apple's HFS?
windows network stuff
net use R: \\host\share password /user:DOMAIN\USERNAME
map network drive; funky session weireness, watch out use in script
net view
net user USERNAME PASSWORD /add
add user
net statistics server # info about uptime, etc
tracert
nbtstat -n = list all comp (NetBIOS name, WINS)
nbtstat -c = clear the cache
nbtstat -RR = Release and Reregister NetBIOS name with WINS
NetBIOS names can only be 15 chars long. The 16th char encode the NetBIOS Suffix.
A list (albeit not comprehensive, at least 4F is not listed) can be found at
http://support.microsoft.com/kb/163409
All code in hex
00 = Workstation Service
03 = Manager Service (allow MMC to connect to it?)
1B = Domain Master Browser, defined for a domain rather than a computer
1C = Domain Controllers, defined for a domain
20 = File Server Service
netsh (shell for config of dhcp, ras, wins, routing) [w2k]
runas # kind of like sudo
runas /user:domain\adminUser c:\winnt\system32\cmd.exe # create a dos prompt with admin credentials
c:\"Program Files\Internet Explorer\iexplore.exe" # start IE using the credential of the DOS session (ie admin acc).
set # display system environment
# LOGONSERVER is the Domain Controller the machine is currently talking to
# Other interesting variables displayed by set:
# USERNAME, USERDOMAIN
# PROCESSOR_ARCHITECTURE
----
network browser cmd (some gui stuff) in Resource or Supplement kit.
net config rdr, see network device info, eg NetBT_E100B1
then,
browstat gb NetBT_E100B1
tell which one is the master browser in the network.
browmon
GUI browser monitor. similar to above
browstat status
browstat view NetBT_E100B1 NTDOM1
browstat getpdc NetBT_E100B1 NTDOM1
other obscure stuff, w2k only?
browstat dumpnet
netusers \\computername /history
# see who has logged in to a given machine
mmc # win magement console,
# many plugin, eg computer mgnt
# customizable and store them as .msc file
http://www.windowsnetworking.com/kbase/WindowsTips/Windows2003/AdminTips/Admin/LaunchAdminToolsfromtheCommandLine.html
nt4 / w2k reousrce pack
shutdown
\\computer : remote computer to shutdown (local if omitted)
/A : abort shutdown
/R : reboot
/T:xx : wait xx secs (def=30)
msg : message to user of shutdown
/C : force running app to close
Windows Registry
reg query HKCR\dxpfile
reg add
reg delete
reg export ROOTKEY/subkey regdump.reg
Did not find command line equivalent of doing find on all fields and repeat using regedit and F3 ...
can't export and do grep either :(
accepted abbreviations (likely in order of decreasing priority):
HKCR HKEY_Classes_ROOT
HKCU HKEY_CURRENT_USER (take precedence over local_machine if there are duplicates)
HKLM HKEY_LOCAL_MACHINE
HKU? HKEY_USERS
HKCC? HKEY_CURRENT_CONFIG
Windows Startup
windows program auto load, from registry instead of Startup folder:
regedit
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
TLA (likely in order of decreasing priority):
HKCU HKEY_CURRENT_USER (take precedence over local_machine if there are duplicates)
HKLM HKEY_LOCAL_MACHINE
each program has an entry with full path as value, delete individually as needed.
XP has a System Configuration Utility under control panel | help support
section, so that all current startup places are listed and can be turned off via uncheck.
Many of these can be recognized as normal software, but just always run
at startup, which becomes anoying.
Some spyware may also add hooks here, but if they are really good,
spyware may replace legit system file and it will need a tool to check
if it is really spyware or the legit file!
Probably legit programs (could still be replaced by spyware!):
HKLM...Run mobsync.exe /logon. Sync Manager
KHCU...Run ctfmon. Office2003 text2speech [potentially key logger]
Additional crap that is loaded somehow...
C:\Program Files\Common Files\Real\Update_OB\
apperently lot of .dll and .exe which somehow get executed
rnms3270.dll is the realone messanger center crap that do lot of pop up messageging ads. Delete or rename them!
---
Internet MIME programs (may load all the time)
C:\winnt\Downloaded Program Files\
Each control has its own entry, right click and then choose remove
(eg, will see DBFullInst Control for the stupid SpyWare program).
---
SpyBot AntiSpyware program has tool that list all program that will be
loaded up at boot time and allow single click disactivation.
Hackish way to reset password
At least for Win 7.
Idea is to replace the sethc.exe program, which is what accessibility invokes, and replace it with cmd.exe
then during login, press shift 5 times or alt sh prtSc to invoke the accessibilty program, get dos prompt instead, and
issue command
net user geek newPassword
detailed steps are listed in
http://www.howtogeek.com/96630/how-to-reset-your-forgotten-windows-password-the-easy-way/
(replace sethc.exe when done. or maybe not... nice quick shortcut to cmd, but perpetual back door...)
Cool SA tools
WinDirStat
Get it from sourceforge.net, a program that will collect disk stat usage (network share ok),
keep track of subfolder disk usage, and also give aggregate of files type usage
(eg mp3, m4a, avi, pst, zip, etc).
PDF Forge A freeware to generate PDF for windows (freeware version of Acrobat Writer).
hoti1
bofh1