Advertisement
hjaltiatlason

WSL-Info

Apr 24th, 2023 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.54 KB | None | 0 0
  1. <#
  2. WSL 1 Architecture
  3. ┌──────────────────────────────────┐
  4. │ │
  5. │ ┌────────────────────────────┐ │
  6. │ │ │ │
  7. │ │ LINUX DISTRO │ │
  8. │ │ │ │
  9. │ └──────────────▲─────────────┘ │
  10. │ │ │
  11. │ │ │
  12. │ │ │
  13. │ │ │
  14. │ ┌──────────────▼─────────────┐ │
  15. │ │ LNUX KERNEL API │ │
  16. │ │ │ │
  17. │ │ WSL v1 │ │
  18. │ │ │ │
  19. │ │ WINDOWS NT API │ │
  20. │ └──────────────▲─────────────┘ │
  21. │ │ │
  22. │ │ │
  23. │ │ │
  24. │ │ │
  25. │ ┌──────────────▼─────────────┐ │
  26. │ │ │ │
  27. │ │ WINDOWS KERNEL │ │
  28. │ │ │ │
  29. │ └────────────────────────────┘ │
  30. │ │
  31. └──────────────────────────────────┘
  32. WINDOWS
  33. ┌──────────────────────────────────┐
  34. │ HARDWARE │
  35. └──────────────────────────────────┘
  36.  
  37.  
  38. WSL2 Architecture
  39. ┌───────────────────┐ ┌───────────────────────────────────┐
  40. │ │ │ │
  41. │ │ │ ┌──────────────┐ ┌──────────────┐ │
  42. │ │ │ │ │ │ │ │
  43. │ │ │ │ LINUX DISTRO │ │ LINUX DISTRO │ │
  44. │ │ │ │ 1 │ │ 2 │ │
  45. │ ┌──────────────┐ │ │ │ │ │ │ │
  46. │ │ ◄─┼──┼─► │ │ │ │
  47. │ │ │ │ │ │ │ │ │ │
  48. │ │ WSL v2 │ │ │ │ │ │ │ │
  49. │ │ │ │ │ │ │ │ │ │
  50. │ │ ◄─┼──┼─┼──────────────┼─► │ │
  51. │ └──────────────┘ │ │ │ │ │ │ │
  52. │ │ │ │ │ │ │ │
  53. │ │ │ └───────┬──────┘ └───────┬──────┘ │
  54. │ │ │ │ │ │
  55. │ │ │ │ │ │
  56. │ │ │ │ │ │
  57. │ │ │ │ │ │
  58. │ │ │ │ │ │
  59. │ │ │ │ │ │
  60. │ │ │ │ │ │
  61. │ ┌─────────────┐ │ │ ┌───────▼────────────────▼──────┐ │
  62. │ │ WINDOWS │ │ │ │ │ │
  63. │ │ KERNEL │ │ │ │ LINUX KERNEL │ │
  64. │ │ │ │ │ │ │ │
  65. │ └─────────────┘ │ │ └───────────────────────────────┘ │
  66. │ │ │ │
  67. └───────────────────┘ └───────────────────────────────────┘
  68. WINDOWS [VM] LINUX VM
  69.  
  70. ┌──────────────────────────────────────────────────────────┐
  71. │ HYPER-V (Type 1 Hypervisor) │
  72. └──────────────────────────────────────────────────────────┘
  73.  
  74. ┌──────────────────────────────────────────────────────────┐
  75. │ HARDWARE │
  76. └──────────────────────────────────────────────────────────┘
  77. #>
  78.  
  79. #Enable virtualization platform
  80. dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  81.  
  82. #Install WSL
  83. #Don't do this as this in the inbox and not latest
  84. #dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  85.  
  86. #INSTALL WSL FROM THE STORE FOR LATEST VERSION, i.e. v2
  87. wsl --install #will use the store version and install a default distribution
  88. wsl --install --no-distribution #no default distribution
  89. #OR
  90. https://www.microsoft.com/store/productId/9P9TQF7MRM4R
  91.  
  92. #This is the distribution architecture. Leverages virtualization for the kernel instead of a translation layer (WSL1)
  93. wsl --set-default-version 2
  94.  
  95. #What is the version of this app I'm running
  96. wsl --version #if this does not work you need to get the store version
  97. wsl --status
  98.  
  99. wsl --help #note are -<char> and --<term> for most
  100.  
  101. wsl --update #to update
  102. #Will also update from the store including the kernel
  103. #and would update from in-windows to the store version
  104.  
  105.  
  106. #Global settings such as maximum resource, customizing kernel at
  107. code %userprofile%/.wslconfig
  108.  
  109. #Can see the impact within distro
  110. #Processor
  111. lscpu
  112. nproc --all
  113. cat /proc/cpuinfo
  114.  
  115. #Memory
  116. cat /proc/meminfo
  117. free
  118. #Both
  119. top
  120.  
  121.  
  122. #View available distributions
  123. wsl --list --online
  124. wsl --install kali-linux
  125.  
  126. #View all distributions installed
  127. wsl --list --verbose
  128. #or
  129. wsl -l -v
  130.  
  131. #Check current location
  132. $DistroName = 'Ubuntu'
  133. (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq $DistroName }).GetValue("BasePath") + "\ext4.vhdx"
  134.  
  135. #To move to custom location
  136.  
  137. #Terminate specific distribution
  138. wsl -t Ubuntu
  139. #Shutdown WSL (all)
  140. wsl --shutdown
  141.  
  142. #export
  143. wsl --export Ubuntu s:\scratch\ubuntuwsl.tar
  144. #OR
  145. wsl --export Ubuntu s:\scratch\ubuntuwsl.vhdx #much faster
  146.  
  147. #Then
  148. wsl --unregister Ubuntu
  149. #Import to location of your choice
  150. wsl --import Ubuntu s:\images\Ubuntu s:\scratch\ubuntuwsl.vhdx
  151.  
  152. wsl --list --verbose
  153.  
  154. #Can change the default
  155. wsl --set-default Ubuntu
  156.  
  157. #Start and connect to distribution
  158. wsl -d Ubuntu
  159.  
  160. #To avoid entering password at every sudo
  161. sudo visudo
  162. <#
  163. Add to end of file
  164. hjalti ALL=(ALL) NOPASSWD:ALL
  165. #>
  166.  
  167. #See our processes. Note we are running in our own namespace in a shared kernel. init -> bash
  168. #We see multiple init forked processes as it has multiple functions such as actual init then interoperability services and others
  169. #Also the plan9 for file system sharing from Linux to Windows
  170. ps -ef
  171.  
  172. #Can see the full services for a distribution
  173. wsl --system -d Ubuntu ps -ef
  174.  
  175.  
  176. #File system mount of the ext4.vhdx -> /mnt/wslg
  177. Wsl --system -d ubuntu df -h /mnt/wslg/distro #Windows
  178. #Linux
  179. df -h
  180. ls /mnt/wslg/distro
  181. cat /mnt/wslg/distro/etc/os-release
  182. cat /etc/os-release
  183.  
  184.  
  185. #File systems
  186. ls /mnt/s #on Linux to view Windows
  187.  
  188. ls \\wsl.localhost\Ubuntu\proc #on Windows to view the Linux
  189. #Distro specific configurations
  190. cat \\wsl.localhost\Docker\etc\wsl.conf #note will be pause if not running as it starts it
  191. #Global settings in %userprofile%\.wslconfig
  192. #In explorer can just navigate then launch pwsh.exe to be in that folder and even view processes etc
  193.  
  194.  
  195. #Systemd support
  196. sudo -e /etc/wsl.conf
  197. <#ADD
  198. [boot]
  199. systemd=true
  200. #>
  201. cat /etc/wsl.conf
  202. wsl -t Ubuntu #from command then restart
  203.  
  204. #Graphical
  205. sudo apt install firefox #uses snap which needs systemd enabled
  206. snap install firefox
  207. firefox
  208. sudo apt install gnome-mahjongg
  209. sudo apt install x11-apps -y && xeyes
  210.  
  211.  
  212. #Network port mapping
  213. sudo apt update
  214. sudo apt install nodejs
  215. node -v
  216. hostname -I #check my IP
  217. #In my RandomStuff repo location
  218. cd /mnt/c/Users/hjalti/OneDrive/projects/GIT/RandomStuff
  219. node ./doggos/doggoecho.js 80 127.0.0.1
  220. #On Windows host
  221. netstat -ab #Note wslrelay.exe has the port mapped!
  222. #Open on my Windows box to http://127.0.0.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement