Using Windows Subsystem for Linux v2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video I wanted to talk about the windows subsystem for Linux if we think about it today Linux is everywhere even Microsoft cloud services like Azure there's more Linux than Windows and so more and more we need to understand Linux we need to develop with Linux but we use Windows for our day-to-day productivity maybe we develop in both of them and so I could absolutely run Linux in a virtual machine I could create a hyper-v virtual machine on my windows box and run Linux then it's this very isolated separate environment that's really not seamless with the rest of my Windows desktop experience that's what we want to use is the windows subsystem for Linux which is going to fix this and the whole goal of the windows subsystem for Linux is to think about as a developer I can run all my regular familiar tools I love in Linux but at the same time they're just going to seamlessly integrate with Windows and this has millions of users today and so how does this actually work so I want to take a step back so if we go and look at the architecture of actually What's Happening Here what I've I decided to use ASCII lineup for a little bit of fun so if we zoom in actually for a second we can go and look at this if we think this was the V1 and from a V1 perspective obviously you have the regular Hardware that you ran your machine on you had windows installed Windows has hits kernel which are the core apis that go and interact with all of the other system components the hardware then I want to run a Linux distribution and obviously think of the Linux distributions that user mode space they all have this common Linux kernel they all talk to different Linux distributions is really that user space that all use a common Linux kernel so I've got my Linux distribution where one of our my Linux applications my Linux tools but it's running on Windows and so what they had in the windows subsystem for Linux version one they created this layer that implemented the Linux kernel API calls so the Linux distribution would talk to those API calls then it would translate them as a layer to Windows NT API so that was the architecture of the V1 so it would let me run Linux distributions on Windows because it was essentially creating its own Linux kernel abstraction layer that would accept Linux kernel calls and convert them to Windows NT kernel calls and that's how that functioned but as you can imagine there's a lot of challenges with that I mean a the Linux kernel updates pretty frequently and so they would have to constantly update their layer looking at what's the new things that happened but fundamentally Windows is very different from Linux in some ways which means some things are maybe very difficult to do some things are just impossible to do a very basic example could be in Windows if I have a handle open to a file I can't move that file in Linux you can and so there'd be really no way to translate that behavior so the windows subsystem for the next version 2 completely changed the architecture to this so this is the V2 and as you can see it's it's very different if we go and zoom in one of the key things straight away you'll see is now this this idea of the hyper-v That Type 1 hypervisor is running directly on the hardware and it is a type 1 hypervisor so people often think that hyper-v is running on Windows that is not the case when I install hyper-v it actually injects the hyper-v hypervisor directly running on the hardware which is why really that Windows installation you have really is kind of a VM now it's a management partition it runs certain key services to facilitate the other virtual machines but it is running on top of that hypervisor if we were to jump out and just open up a terminal if in this terminal and it is elevated if I do BCD edit Dash enumerate we will see so This Is My Windows desktop machine the hypervisor launch type is set to Auto so it is loading hyper-v on the hardware and I am running on top of that hypervisor so that's really a key Point here but remember one of the challenges we had was well it's this very disjointed separate ugly experience if I just run Linux in a regular virtual machine and so yes the Linux distribution will be running in a VM but it's not a regular virtual machine if I go and look at hyper-v I would not see anything I don't even have hyper-v installed on this what we have installed on this is a virtualization platform it's actually used by a number of other features as well which we'll talk about for a second but it's this managed virtual machine a lightweight user utility virtual machine that's been powered by the host compute system so there is the same technology that powers things like Windows Defender application guard when I want to run Windows sandbox applications I I need to run something in a bubble so we can't interact with other components and the way it does this is it creates this managed VM that I don't really see and it's super lightweight but it is a virtual machine and if we actually go and look for a second if I jump over here and if I was to run um so HC s diag list okay so let me run that actually in my terminal so I need to run that elevated so HCA diode list we can see sure enough yes I have one of these managed VMS running and it's being used by that windows subsystem for Linux so that's how it's being powered behind the scenes yes it is a managed virtual machine but because it's managed I don't see it as any kind of regular VM now if I poked around the process tree of the system for a second we can see we have this VM compute service then we have this VM worker process and then underneath that you have this VM mem WSL service and that is what is actually consuming a huge chunk of the memory it is that particular service let me just scroll this down to get better view of that so here we can absolutely see this one service is what consumes the memory there is no vmss service like I would regularly get on hyper-v I just get this VM worker process that's been neutralized as part of VM compute that has this memory component that handles all of the memory elements of this and I only have one of these no matter how many distributions of Linux I have running on a machine there's only one and to prove that I have two right now so I actually have two different distributions so if I jump over here at the bottom I can do a PS Dash EF so this is kind of one of my distributions and then if I jump over to this other one this is a completely different distribution so I have two running but I only have one of those managed virtual machines because what it's leveraging is yes it creates one of those managed virtual machines and in that managed virtual machines that's where it runs this Linux kernel and that's that single instance providing therefore true all of the different apis Linux then each distribution I want to run is using a similar technology to Containers it's using Linux namespaces so they each get partitioned into their own namespace on that shared kernel they each get mapped to their own file system they check their own vhdx file that contains the file system of their distribution but they're using that same shared kernel so no matter how many WSL instances of different distributions are used as one of those managed virtual machines and then the key point is we have this windows subsystem for Linux component running on Windows that has these various channels talking to each of the different distros and that's powering a number of services that's gonna to make that seamlessly function and I'll come back to that and talk about that in a little bit more detail later on this is the architecture it's a managed VM but you never see it you never have to worry about it it is completely seamless for what we actually want to do now the amount of memory it's going to consume does vary the base bash will be about maybe 500 Megs there's different types of memories there's the in process memory used by applications and then there's obviously caching and Linux doesn't like to give the caching back unless you kind of force it to but the memory can grow and Shrink but I guess before we go any further um how do you get it that's probably a good thing to focus on so the key Point here is it is relying on the Windows virtualization platform so the very first thing you have to do is enable that so you can see here this one command this dism online enable feature and then that virtual machine platform oh that I need to install I don't need to install the hyper-v or the hyper-v tooling or any of that but I have to get that virtualization machine platform now there is also then windows subsystem for Linux built into windows and you could think okay well I'll enable that feature as well don't we don't want to use the inbox feature it's it was added there for some reasons to hey make it easily available but the challenge with many things that are built into Windows is well then how do you update them your Falls to a certain Cadence of the windows platform it limits you and so what they've actually done is they've broken WSL out into a Windows store application and that's the version we want to use now if you run the WSL install command it will go and use the store version so I can do WSL Dash install and it will go and fetch the version from the store and use that and it will install a default Ubuntu distribution for you now if you don't want the Ubuntu you can just add dash dash no dash distribution and then it won't install that default at all or you could just navigate to the store so you could absolutely just jump over to the store and just bring that window over here and this is what you want this windows subsystem for Linux you would install this and then okay great I'm running Linux on my machine and again by default this will put the Ubuntu in as well so it's now decoupled from the underlying OS which means they can update it by the store whenever you want and they update it pretty frequently it was actually interesting this morning I went and did a quick update and sure enough there was a Windows subsystem for the next update now it will terminate any running instances you have so it can perform the update okay so now I've got windows subsystem for Linux installed on my machine and there could be some confusion here about WSL version one WSL version 2. which was the architecture of WSL so V1 remember was where it was this kind of translation layer V2 is where it moved to this managed lightweight VMS it's running a true Microsoft created kernel then there's also you have different versions of the feature the app that the app itself and so one of the things we have here is we want to set the version to the V2 of the architecture so we want to set that default version here and this is going to leverage that virtualization instead of doing that translations they are stuff so we always want that V2 951 WSL dash dash version if this doesn't work then it means you're running the inbox version of WSL so you don't want to use that you want to move to the Windows store version if it does work now it's going to show you information about your WSL instance so the actual version of the command I'm using this is where it gets confusing is 1.2.5 but it's using that V2 model it shows me the kernel version then there's some other things here so you have this wslg that's because it can handle graphical Linux apps which I'll show you later on how does it get the pixels for those graphical applications to your windows when it's using the remote desktop client to power that and it can use GPU acceleration and then show me information about Windows and other components and again if that doesn't work it means if you use the inbox windows and I don't want to be using that so go and move I can always go and check the status and you can see again my default distribution and I'm running my version two down here which is what I want to see help is really good if I do dash dash help it will show me all the different commands I can run and again if you think Linux world for most things there's two options you can run this idea of for example Dash Dash and then a word or a single Dash and then just the letter they're doing the same thing it's just how do I want to use that interaction most of the time I'll do the dash dash just so it's more clear what it's actually doing at any time I can run WSL dash dash update and that will go and check hey are there updates available I'm already running the newest one if I was running the inbox version and I run this command it will go to the store and move me to the store version so that's a really useful command to go and Leverage now I guess one of the things I will point out is when I showed you that store and I said there's different distributions I can use well notice it also kind of showed me hey there was an update to Ubuntu what would that do if I update the Ubuntu distribution and I already have it running does it go and upgrade my current version running no it will not that would be a bad thing because obviously if it just went and updated it I'd lose any of the customization I had already done so when I update a distribution what it's really doing behind the scenes is it updates the template file it has ready to be used if I was to create it again so for example this is me looking inside you normally can't do this I'm changing permissions this is what that banter installs on my file system and the key thing you're really looking at here is this install.tar.gz this is the base vhdx file that it would go and create a distribution from but the audience now done is position that on my machine for if I was to delete my existing one and recreate it it does not in any way upgrade one I've already deployed so when you update a distribution in the store all it's doing is hey if you were to deploy a new one I'll use this newer version it is not going to mess with anything you've already done if I wanted to upgrade my existing one then I have to do regular Linux things so for example regular Linux things would be hey I do things like sudo apt update it will go and check what's available for me and I would do my pseudo apt upright so once I've created the distribution it's essentially unlinked from the store to updating it from the store it is not going to patch your existing deployments you will need to go and still do that so that's a really key Point around all those different elements so just to understand once I've created it hey I'm I'm good to go I can do anything I want but before we go any further I guess let's think about the resource distribution because it is a virtual machine so what does that mean in terms of what it can actually go and use now it's using virtually addressed memory so what this means is it's not some fixed amount it can go and get more memory from Windows and it can actually give it back and that's one of the really nice things it can actually remove memory from that um virtualized environment and give it back to the Windows operating system now again as I mentioned if it's process application memory it's just going to free it up with applications free up the memory if it's the caching for Linux it typically doesn't give it up very often you can force it to give up the cash information but it's only when the next cash would give out the memory it will go and give it back to Windows Now by default it can use up to 50 of Windows memory and it can use all of the processors but I can change this so there is in my user profile I can create a file it probably won't be there by default but I can create it and it's the base of my profile dot WSL config and this is a global file so this applies because remember there's only one of these managed VMS this applies to that managed VM for any distribution that runs as my account on this machine and if I was to look at that file oh so that's the interesting what this just did so notice what it actually did is it install code on my Linux because I click this in the wrong window but notice I've got this this graphical app so that's kind of interesting but I didn't actually mean to do that I'll run that in my windows environment that was pretty cool just just word but notice I've got some configurations so I'm limiting it to eight gigabytes of memory and I'm limiting it to four processors now there are other configurations I can do here but you have complete control so I'm limiting what's actually available to it by creating that file and putting those values in so if I was now actually to go to my Linux as I meant to do and let's actually clear this for a second if I was to go and look at let's say the processors first if I was to run the ls CPU this gives me detail about all the processors but if we notice that online is looking at cpu4 but if I look the online CPU is zero to three so it's showing I have three of them if I just go and get account sure enough I see there's four so although I have way more processes than that in my machine I'm not even sure how many I have at this moment if I bring up task manager locally and we look at performance and we look at CPU yeah there's a whole bunch so I've got a lot of different logical processes on the box what's actually being exposed is only four because that's what I configured and I can even look at the pro info and again it gives me detail on each of the processes that is available same for the Memories remember I limited the amount of memory that's available so if we go and see I'm really restricted to that eight gigabytes and I can go and look at how much free memory I have to see the detail and top kind of gives me an overview of of both of those things together but the key Point here is I have limited the sum of what's available to all the distributions I'm running on this box so I have complete control to manage that however I want to do now there is also an additional per distribution file so here actually in the distribution if I was to cat Dash Etc WSL Dash conf I have this file in each distribution so this is where I can add certain customizations the specific to its namespace and in this case I wanted system D to be enabled that's really useful if I want to run things like docker but even services like Snap if I want to do some other types of applications in this case I want to demo Firefox later on I needed system D running for it to work in a seamless manner so I can do other customizations now there are other processes on my windows box I showed you the idea of obviously the core process is running the VM and handling that memory but if you look down just a little bit you also see the core WSL service which then spawns off a whole bunch of other processes so we have the LX lxs manager that's the Management Services related to the windows substance the Linux then it has a relay service this is all about Port mappings which again I'll show later on and then we have these host processes for the different distributions running and handling the i o there's a whole bunch of other things happening behind the scenes you don't need to know any of this this I think is just cool to understand how things work so it's clearer to to get that idea of that seamless interaction and obviously I'm doing this from vs code I don't have to do this for vs code at all I can just run WSL in a and it's command prompt and go and launch and connect to one of these particular distributions now that manage VM as I've mentioned is running a Microsoft built Linux kernel all Linux distributions are using a shed Linux kernel well that core code goes into um I can go and see this so Microsoft make it available on GitHub so if I go and look at GitHub I can actually see the wsl2 Linux kernel and they build this obviously off of the core Linux kernel that's maintained they obviously add their own customizations for things that are specific to Windows subsystem for Linux and they have their own init process that has some multi-function capabilities to spawn off the different things it needs but it is running a Linux kernel it's just a Microsoft built Linux kernel just like many other distributions will build their own kernel and that kernel is in that windows subsystem for Linux store package it's nothing I have to manually do anything with now I've mentioned distributions a few times and so we can go and see what's available to me make sure everyone is in the right environment so here are some of the core distributions that I can leverage obviously there's Ubuntu is the default one that you're going to get if I just run the Windows system for Linux install but hey Debbie Anne Cali Linux different versions of Ubuntu but there's also things like Alpine obviously there's Marino you know if you're part of developing and partnered with that this is just some of the core ones available um in there but again it's not showing everyone again I've used Alpine quite a lot as well as Rocky Linux there's different ones available for you and you can just go and select so if I just do WSL dash dash install Ubuntu it will go and install that particular distribution or I could say hey I want Alpine or whatever I want to use if you go and look at the Windows store it will show you some of the distributions if I search for WSL subsystem Linux over here it's got some ideas of what's available here it's got things that other people might view so there's other distributions down here see if I search for Alpine I've actually tried to do it in the store itself oh there's Alpine Ubuntu different things available to me so I can go and get additional distributions I can see what I've installed so I can do WSL Dash list for both or just wsl-l-b I have three so I've got obviously my default it's got the little uh asterisk next to it little version two I've got my own custom one where I installed Docker into Ubuntu and then I'm playing my Mariner as well so I mean internal fun stuff there I can see two of them are running one of them is stopped obviously so I can't interact with that right now one of the challenges is where they install so let's pick Ubuntu for example by default it will install it under your user profile app data local packages and the package name which I don't really like you can always go and check where it is so if I go and look at my Ubuntu mine is actually installed in this far nicer location s colon image is Ubuntu then it's hard drive it's vhdx is always ext4 so remember the architecture they're running one kernel each distribution runs in its own namespace and each distribution maps to its own view of its file system so it uses a vhdx file for each of those if I was to open up Explorer so we jump back over here for a second in my case so my Ubuntu has its hard disk and it's pretty big so I've installed a bunch of stuff on it it wouldn't normally be that big if I was to look at my Docker one or it's got its own file my Mariner one it's got its own file so it's that vhdx is mapped to its view of the file system for that particular distribution again similar to Containers which get their own view so containers use the union file system and have lots of layers here each distribution just maps to its own vhdx file began running on the same shared kernel but by default this file would not be in this nice file structure I've created and I cannot change the default location so what I always do is after I install a distribution I stop it if it was running now we'll talk about this in a little bit more detail later on but a key Point here is there's only one while I'm interacting they're not designed to run as a background service so it's only running while I'm using it but if for some reason maybe I've just been using it remember I can go and check well okay is it running right now okay yeah it's running so if I want to do export it which is how I can move it I'd well I could even just close my session or I can terminate a specific instance this would just kill my Ubuntu instance or I can say shut down the entire managed VM so that would be WSL dash dash shutdown which would then obviously stop any distribution all distributions that I currently have running I can then export it so it export out the particular distribution to a location now if I'm conscious of space I can export it to a tar file but that's going to be slower the quicker way is to export it to a vhdx file which is much much faster but obviously it's not compressing it it will take a bit longer as it has to go through those CPU Cycles but it will use less space once I've exported it I basically will go and delete it so I'll do this unregister so I'll unregister that Ubuntu instance which will delete that vhdx file in its current part of my profile location and then I'm going to import in to this location the file I exported either the vhd x or the tar file then I'd be able to do a list and if it wasn't the default anymore because I deleted it and brought it back in I can set hey I want this to be my default again and then it would just show up in my little list and I'd see that star as my default version and at that point I could just connect to it and the way you connect is just wsl--d and then the distribution name and it will take you in there now again I'm using vs code which completely integrates with WSL and so I can just launch any of them just as part of my regular terminal now because I've stopped and started this a bunch of times it's not showing it here because I did that Windows store while I was running vs code I guess if I close vs code quickly and just reopen it again now you can see I've got all my options back so actually my just get my my pictures in the way so let me just get this just to the screen so here my drop down I can just select them but notice what it did it still has given me my nice connections and remember even though I closed and reopened it my sessions are all here and it's kind of remembered where I was so it's it's really neat and of course there's my Powershell session up here so it's fully nicely integrates with everything I'm doing as I'm leveraging this now when you install it at first it will make you set up a username and a password that's just for when you sudo things and so anytime I run sudo it will prompt you for that password you configure as part of that initial setup if you don't want to run sudo and enter the password every single time you type in a command you can always do the old um sudo by sudo and what this lets you do is you can add your details to the end of that file so in my case if I scroll all the way down to the bottom you just add one line that so all I've added in is John all it was all no password at all so now if I run the sudo command this is nothing WSL specific this is just Linux it's just a handy thing if maybe you're not a Linux person then I don't have to type in my password every single time I do that maybe I should just add in that little command so again it's just sudo and then by sudo in there and then all you're going to do again is just at the end of the file add in whatever name you put in there so that's an easy way to avoid having to enter your password so I'll put that in there if you place your plan with it again this file that I'm using here is in the description of the video and you can go and try all these things out now again the key Point here now is that if I was to run in this Ubuntu my psef these are just the processes that are part of mine now I have quite a lot because I installed a bunch of stuff for some of the demos that we're doing later on I installed node.js I installed snap I installed Firefox normally it would be a lot Slimmer than this you would not see all of these things so let's look again at what the options are the way we let's try Holly sometimes they Adam and move them let's install a Kali Linux quickly and you can actually go and see through the process so this is where it's actually going is installing it it's pulling it down that's going to put it in that unfortunate folder I don't really want um and but this will actually let you see that D4 and how it's doing it but what we'll see is a lot less processes because by default you're just gonna see a few now it's asking me for my username so I'll say hey John it's going to ask me for a password that's it so I'm now running inside there and if I was to do a psef though it says not many processes at all now I have these same processes in my Ubuntu if I was to look around and I found them well enough you can see them all at the start you have kind of its main in it it but it then spawns off a bunch of others um from there because the init here is doing multiple different functions um it helps with some of that interaction and some of the redirection capabilities we'll see this plan nine in all of them so the 9p is a service used for the file access so again if we jump over here we can see there's multiple of these in IT services that ultimately spawn our bash which is what we're interacting with and then when we run a command it's running inside the bash The Bash runs inside the init and it's got that hierarchy because they're in it is performing those multiple different functions and so it spawns off a few instances itself if I exit that if we now want to look to all of them now because you've got our Kali Linux running as well but because we've exited I think it's about eight seconds and within about eight seconds I would expect to see it actually go to stopped so now we can see it stopped because it's only running while we've interacted with it and again if I didn't want that remember I could export it and I could do all the different things but if I don't want it and I don't want this one I can just do and register and then I would just type in the name and now it will be gone it would have deleted the file it's completely removed from my system um I didn't mention Alpine earlier so when I went to tried it it had gone so maybe there's some things adding and removed don't quite know what's going on there um but that that's how easy it is but you get these core processes but they are unique to each distribution it is using that namespace so I will only see the components the services that I am using so in my Ubuntu for example I'm seeing all of these different Services if I looked at my Mariner for example I'll see different services for the things that it's running for example I can see it's running Docker d so this is ready for containers I can see it's using the container D container runtime there so there's different things but they can't see each other's they're isolated by the namespace for that user mode but obviously they are using the same shed kernel so these are trusted I'm running them on the same box technically saying could break out and do things by that kernel they have their own view of the process base I can always go and see the full Services by running the dash dash system with WSL I can go and connect to it or I can run particular um commands nope each one of my windows but here I can then see the pair and init process that spawns off child in it process that spawns off all those other fault things essentially enable me to use that all of this is the architecture to actually use it I do not need to understand this this will all take care of it behind the scenes it will clean up its memory I'm limiting the processes it can use the amount of resource what about the actual interaction so the actual interaction you've already seen is very seamless just as I use various tools hey and vs code it just works but what's one of the most common things I'm going to want to actually do it's probably going to be interacting with files and file systems and it works bi-directionally remember we saw that process when I do my psef one of the core processes that you always have is this plan nine and it's actually running on both sides so this is running on the Linux distributions each then that's distribution is running one of these so there's my Ubuntu my Mariner is running it as well its version of it there's an equivalent running on the Windows side so from Linux I can get to Windows files from Windows I can get to Linux files it's going to work in both of the directions now the actual distribution let's say Ubuntu in this case we can see it's mapped to that it's vhdx file if I was to go I keep running in the wrong window here we can see that it's actually got this Mount wslg distro So that's its view of its vhdx file its file system if I was to actually run inside the Ubuntu if I do DF h this is where I can see all those different connections but notice some interesting ones Mount C and mount S I have a c and an S Drive locally on my machine so slash m n t Dash C and MNT s gives me access to my local CNS drive on my windows box I can also see I have um that mount the WSL G and if we look at that for a second if we look inside the distro there's the complete file system of that Ubuntu distribution I can look at the OS release file the EDC OS release and sure enough it it's Ubuntu if I run that same thing on Mariner I see the Mariner content of that so if on the Linux side I look at slash MNT C that's my C Windows all right my my folder I could look at the S drive as well and that's the content of my S drive on my local machine and I can interact with any of the files if you actually look at what is my default location I'm actually in a folder that's local on my computer in part my John's profile that is my git repo for my random stuff which is where I've got the demos for this but likewise on my windows terminal clear this for a second actually even before we go and look at command line if I just go to Explorer over here when I have Windows subsystem for Linux installed notice I have the little Linux and I can see my distributions and I can just select one of them and I can see the information I can start looking around and I can see all of the files on that machine I can just interact with it now it does have to use that 9p service running on the distro so these I can just go and review because they're running if I try and interact with one that's not running yet notice there's a pause it's a pausing on the docker because it had to start it but like it was like what a second if I now went and checked my list notice Docker is now running so when I try to interact with it using Explorer it had to quickly spin up that particular namespace map to its vhdx file so it could start the Plan 9 server to offer file services to Windows so that's what it's doing behind the scenes again it's all seamless but that's why you'll see a little bit of a delay when I'm interacting with one that's not running because it has to quickly just go and fire that up so it can get that service running that plan nine that's what's providing the windows to Linux services so I can go and interact with those file systems um so that's that's really powerful so we carry on but I could also do exactly the same thing from the command line so here are my windows if I just look at my WSL localhost Ubuntu proc so remember this is running inside windows command notice I'm actually looking now at a virtual file system from Linux in Windows because that slash proc is a virtual file system that is exposing hey all of the processes running on that Linux distribution so that's an interesting capability that I can do I could just as easily dump out regular files and notice it's saying hey a note there will be a pause that Docker would have had the eight seconds I stopped looking at it it would have timed out but now I'm looking at a file on my Docker distribution that is slash Etc WSL config and for Docker hey I had to also add that system D equals true so I wanted to be able to use system d so I have this full interaction both directions and it's completely seamless um for all of those and I guess talking of system D we have system D support that really is critical for things like docker and as I've already shown you just add the enablement to its boots as part of the ETC WSL config I just go in and add hey a boot system D equals true and pretty much all of the core Linux apis and hooks will now work because we're running Linux distribution it's completely seamless with our Windows environment but again that architecture is running a true Linux kernel and a utility managed VM that we don't see but it's seamlessly handling all of the i o through those other services um that we're seeing in our environment so regular i o works you can see me here just from the terminal I'm interacting and it's working all the different ways I can run all the different commands it just works graphical apps work as well so in this example I used sudo apt install Firefox now I didn't have systemd enabled at first so it failed so then manually run the snap install Firefox but if I now run Firefox there it is so there's Firefox and this is just completely seamless in my windows environment I can resize it so how is that working how can I have graphical applications running on my Windows machine and we can get a hint if we actually run process Explorer and I hold down my little Target of a process and the process it targeted is Ms RDC it's the remote desktop client so what it's doing here and notice what this is a child of it's a child of WSL host so when I run a graphical application in WSL behind those scenes it's spinning it up with the MS remote desktop client and that's how it gets the pixels from the Linux process to show up on my Windows machine so this is a command any Linux graphical application I want it's completely seamless but it's rendering the pixels just completely interactively with my windows other desktop applications because it's firing it through that Remote Desktop Client and the interaction it seems like around any of those graphical applications I've got some other examples here I'm not going to go through them all but it's just going to work it's really powerful there's even ways I can run Android apps there's other subsystems for Android that let me run Android apps on my Windows machine as well and likewise networking is going to work so I've already run these commands which again is why my Ubuntu installation is fairly heavy there's lots of different processes but if I go and check for example I've already installed node so we can say I've got a version running down here and all I'm going to do is I'm going to run a node very basic application in my Linux environment so I'm in Linux right here I'm going to run this JavaScript node.js application that listens on Port 80 on my loopback address so it's a it's the same application I demoed in my container demo so my app proxy demo I'm getting my demos mixed up so it's listening on Port 80 on 127's loopback address if I execute this so it's running on Linux but as running remembering that managed VM how's that actually going to work if I jump back to Windows I look at netstat oh not in here let's run it in here instead this is my elevated terminal and let's look for Port 80. somewhere equal 80. it's owned by WSL relay which remember we saw earlier support 80 I've offered up through my Linux automatically the WSL relay service running on Windows has grabbed the port and will now send anything I try and talk to through to that Linux environment and that particular distribution and its namespace there's offering port 80. so let's test that see if we just fire up our browser and go with the http127.0.0.1 there it is there's that very basic little website that I'm running inside that environment you can see here it's got my user agent so I'm running it from my windows but that just works because it's doing that mapping for me seamlessly once I exit it so that's now gone if I go back to my terminal over here and we scroll up way up is it now I've just got this time weight but this is just gonna go it's not listening anymore it's gone because I've terminated that process there's now just a timeout happening on now so I can run those different Services even if they're Network orientated they're just going to still seamlessly function so networking just works if I have GPU I can do GPU acceleration I can map to USB devices all of that is just going to work now one of the things you may be asking and you've noticed is whenever I'm running these kind of list commands if I run in the right window so that's the list of what's available I meant to run my verbose so they stop after a period of time they're running while I have an active window as soon as I kill it says kill this terminal so now I've just got Ubuntu running if I keep running this Mario is still running for right now but within about eight seconds so it has an eight second rule we'll see Mariner will stop so the question may come up well how do I keep things running and that's really not the point of this remember the goal of this is for developers it's for interactions when I want to develop on it I want to create things on it then we can see it stopped because I terminated whatever handles and connections I had to that distribution so it's now stopped it is not designed to run long-running processes yes there are ways that I can make a process run inside that would keep it active I can make that happen if I can keep a file locked to it it would keep it running but it's designed to be very lightweight it's designed to free up the resources as soon as I stop needing them so it's going to stop as soon as I stop interacting it will stop the instance if I need to run some long-running process um service some Daemon you're probably reusing a regular VM or using a container to run that that's not its goal so yes I I can force it yes I can make it stay alive if I really want to that's really not its point the point is for it to be very very lightweight and stop as soon as it's not used anymore to free up the resources that can be used for other things um as I did mention it does integrate very nicely with vs code I mean we've seen it a bunch of times already here without doing anything else it will just show me all of the WSLS that I have available and again I know I kept mentioning Alpine I think I'm getting confused in my brain with containers um but we can see there's lots of those different ones it would just show up but there is also an extension for WSL and what this extension does is as I'm let's say developing and troubleshooting in vs code it will give me a completely seamless experience so this is where hey I could be editing the code within vs code but the actual process is running inside WSL the debugging is running in WSL but I'll be able to do break points and steps through it in vs code so although vs code is running as a Windows process everything else the actual app I'm debugging the intellisense will be running from WSL but it's going to be completely seamless so it's the extension again if I'm developing in Linux I'm using WSL this extension is really powerful to give me the best possible experience for all of that and that was really it I mean that was my uh goal for Huawei to cover as part of this I want to just go over very high level what the architecture was and to just talk about how powerful this is and how seamless it is so whether you're a Linux developer whether you're trying to be trying to learn Linux because hey use Linux is in more and more places now and I want to get some understanding of it this is a really nice way that I get the best of both worlds I'm using my windows environment and my productivity apps but then I can fully develop on Linux without having to have a segregated environment that some Linux VM over here is fully integrated to all of my various tools so as always that was it I hope this was useful and to my next video take care foreign
Info
Channel: John Savill's Technical Training
Views: 10,532
Rating: undefined out of 5
Keywords: microsoft, linux, wsl
Id: RTv7G79YYPU
Channel Id: undefined
Length: 54min 57sec (3297 seconds)
Published: Mon Apr 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.