Developing for Linux on Windows - Scott Hanselman - NDC Porto 2022

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends how's it going thanks for seeing me again today if you if you didn't see me if you slept in the real developers sleep in and didn't come to the talk this morning this one is going to talk about linux on windows and uh who is using wsl today so you know all this stuff you don't even know why you're here you know all this stuff so this is great so we have a medium-sized room small number of people this is good and we have folks that have been using wsl before and you've seen the youtube videos you've used it in your daily life so if you have something to add if i make a mistake or you have a tip so that we can convert the others that did not raise their hands so that they might see the light are you waiting to be converted or are you going to convert people so you're already you're already sold okay cool because it's the year have you heard it's the year of linux on the desktop the windows desktop yeah where where the sound card works it's good all right cool so i don't um believe in slides so we're not going to do any slides we'll spend some time in notepad here and we'll uh we'll talk about a bunch of different things but i want to provide a little bit of historical context so there was a thing called wsl1 and then there was wsl2 and now it's just wsl so two is now not one but two is just wsl so wsl1 the windows subsystem for linux which really should have been called the linux subsystem for windows it's not really clear why they didn't do that there's some rule some legal thing wsl one was really interesting because it introduced a concept called pico processes tiny processes did anyone use wsl1 back in the day okay good it was okay it worked fine and the deal was that there's different kinds of binaries right and uh some of my are there any linux people here like old-time linux fees linux you're like did you not want were you afraid we would attack you he was like oh ooh i guess no one else is raising their hand so i i did linux like in the late 90s like when it started right and then did anyone uh do courseware in university where you had to use minix you ever heard of minix m-i-n-yeah so minix was literally the thing that started linux it was a tiny unix system and you would get a book the big thick hardback book in university and you would have to write the source code for this tiny mini unix and then you would get for your for your operating systems class you would get homework like write a file system it's not quite the same as make a website but it was it was our homework and uh and then linus torvalds who actually lives in my town in oregon uh took that concept of minix and then he ran with it and then that's where linux came from so i've been a unix head for you know for 30 years so there's different kinds of binaries right the uh if i make a dos binary dos binary still exist on on windows the first two bytes of a windows binary is mz and i think the guys like mike zawinski or something literally the first two bytes of the windows executable format are this dude named mike's initials because he was the guy like that was he made it so he got to put his initials there and that was how that got that way and i thought that was kind of an interesting flex to to do that um dos mz executable header mike mark mark zabowski isn't that great why because he just put 4d 5a so like that's the header that you look for when you want to start up an executable now binaries on linux are called elf binaries and they're a different kind of binary and when you have your machine you have user mode and you have kernel mode right the kernel mode is where all your drivers run and then user mode is where your apps run and what wsl one did is it took the ability to have elf binaries linux binaries that i could copy from another machine and i could then run them and then every time we went from user mode into kernel mode that moment windows would lie to the binary okay let's think about think about this we don't really think about this when we're working on regular apps right but when someone opens a socket or someone opens a file handle who does that it's not the app that does it the app requests for the server open a port to the kernel open a port give me a file handle let me let me talk to this piece of hardware those are all kernel calls in windows we call them kernel calls or you call win32 and in linux they call them syscalls or system calls and there's a big system called table and there's like the 80 percent case of like here's the top 150 syscalls and then there's the long tail of syscalls which is like here's the other 650 something like eight or nine hundred systems so what wsl one did is you would take an elf binary directly up a linux machine in user mode and it could like you know open up a file and print something out to the screen that's the job of that that binary so that means it needs to open a file handle seek on the disk within that file receive those strings and then output them to the console sounds like the simplest thing it's like a hello world type of an application with me but there's no linux kernel so they're going to say cisco 13 that's not a thing so then we would grab it and then redirect it so wsl one was a big left hand right hand broker they would say oh that syscall maps to that windows kernel call that's cool except when this syscall maps to three or four kernel calls or this three or four kernel calls maps to one on the windows side because the mapping was not clean it was still pretty darn cool but then there was the obscure assist calls so like we got 80 working and then 90 percent working and then 95 working and everyone liked it and wsl one was a success uh and then some people would try it and they'd say have you tried wsl i think oh it's crap didn't work with my app well why not it works with my app well it's because they were using an app that made some system call that was one of the ones we didn't map and then each version got a little bit better but for the most part it's like okay we've got 99 of them so then for people that it worked for they'd say this is great it works great and for other people they would say it doesn't work at all it's trash because it only takes one to not work now processes on windows have historically been heavy this has been this way forever this is just part of the operating system design of windows and windows nt the cheapest thing that you can do on windows to do extra work is make another thread the cheapest thing you can do on linux is make another process that's because linux processes don't really think about windowing they don't they never they were not thinking about putting buttons on the screen so if you have a linux process and you want to just make another one you fork the process it's incredibly cheap micro seconds it's like that but on windows every process has windowing behind it it expects that it's a window even invisible apps think that there's a window so forking on windows is like 10x like an order of magnitude slower so they made these things called pico processes let me go back to my notepad and picot processes are tiny processes because if we were going to map one process on linux to one process on on windows we would still be 10x slower so every time the linux elf binary makes a call it goes to the windows kernel the windows kernel does the work and then a pico process would show up in task manager so you could look in task manager you could see bash or you could see vim but it wasn't a windows executable it was a linux executable okay i'm giving you a lot of background because this is what you want right you want the internals and if you all know this or again if i make any mistakes correct me it's important that we get this right okay so then people get confused and people of all ages and all skill levels about the difference between a shell a prompt a console and a terminal and then they use those things interchangeably they say i use cygwin that's fine i don't need wsl you know what cygwin is anyone familiar i'll make sure some people are not i want to make sure that everybody follows along so someone will say or i use con emu i don't need wsl so let's talk about these things so cygwin a collection of gnu and open source tools that provide functionality similar to a linux distribution on windows similar simulated c is a lovely portable language and you can compile c across any operating system so the gnu utilities and what does gnu stand for gnu's not unix which makes it a recursive acronym gnu's not unix they've recompiled the linux utilities awk said vim against windows itself so it's a simulation so i can install that on windows i wanted to give you all like the real deal so let's go to the terminal we'll make it large win get search sigwin love that high quality wi-fi here so it looks like cygwin is not up in uh in wingate so we'll go and run a random executable from the internet what could go wrong this is fine you know you're on like the 1990s version of the internet when it's like the signature can be used to verify and i just said yes to an anonymous unknown object on the internet so that's gonna be that's probably over for me now i'm dead is it running what's happening okay i just installed a virus publicly so what's the deal dude are you running or what's up looks like it ran i said yes pretty sure i said yes maybe i'll say yes again no what's happening install all users yeah that's fine that's fine whatever yolo available download site this all looks very suspicious we should all we should all be wondering why we're doing this right now this generally sucks no i just want to go back what's happening all right we'll let that download that progress bar is not comforting so i'm downloading i'm downloading something very questionable from the internet right now but what i want to show you is that if i i should have probably installed it earlier wow that's so speedy it's a 9600 baud that's downloading a bunch of actual exes and actual dlls so these are going to be bash.exe and vim.exe and awk and said and if i run them they're going to show up in task manager because they're windows executables this is again no disrespect to cygwin this is trash by the way because this is never going to work no disrespect to cygwin it's not linux why is that important to understand because we conflate these things it'll let me run bash scripts it'll make me feel comfortable it'll let me type ls if i want to type ls that's fine it's a sigwin is comfort food but it is not linux it is a user mode distribution recompiled now when i say we conflate things i'm going to go here into the windows terminal and i'm going to show you where it says default terminal application and i'm going to give you a little bit more history because that's what you like to hear right what is the thing responsible for painting on the screen in that example application that we made in our heads it spins through some files it reads the files and it says console.writeline console.log whatever what's the console is that program that i wrote responsible for drawing pixels on the screen no it's responsible for taking a string and returning it to the console what's the console well on windows it's called con host conhost.exe you've never ran conhost.exe you probably didn't even know it existed so let's change our default to conhost by the time we're done i'm sure cygwin will have installed now there's three progress bars so i don't know what that means it's comforting to just stare at them so i'm going to hit the run and i'm going to hit cmd and let's zoom in over here okay this right here cmd if we look at this properties dialog that will look familiar right we've all seen this before that's windows 95 code right there i remember when we got the ability to have true type fonts in the console that's how old that dialogue is that dialogue sucks so much that they're like trying to fit extra check boxes in here and you can tell that somebody did not want to make it taller because they probably weren't allowed to so they just made the space between the check boxes smaller right so anytime anything gets updated in there somebody just shoves it in as close as he possibly can if i type dir what was responsible for that well conhost is the thing that draws the box that's a console if i run powershell let's run the blue one it's not blue scandalous color look at this remember all this nightmare this is the same thing it's got a different icon but the same exact console host is responsible this says command.exe this is powershell.exe and they're both outputting strings and then conhost does the painting so when conhost got upgraded to give you true type everybody got truetype for free now here is a a funny story for my old people which is probably me uh if i type dir s we're going to go through my entire pro my entire directory really old windows programmers know that if you have a log spew like this the way you make it faster is you make it really small did you know that who knew that who knew that do you don't know why you know that you just know that right just like and what's the fastest you minimize it because because it takes a lot of time to do that work because god help me it's synchronous it has to paint and it can only paint as it waits for the thing so if you start painting all the disk access stops i love your face sir is pain you're just like what kind of architectural decision and no one thought this was a problem why history uh history backward compatibility just historical context i mean this is the console from windows 95 and it's in windows 11. it sucks right but to go and redo that is challenging and people people on microsoft and people pick on them for a lot of things but tell you microsoft does not get credit for backwards compatibility with with apple they're like surprise your mac is never going forward to the next operating system you're stuck i've got a mac mini it's been stuck on slo snow leopard from 2003 because one day they just said nope we're going to abandon everyone from there right but you can run visi calc from 1979 on windows 11. like they're obsessed because if we break something in conhost we break it for a billion people there's always somebody out there counting on a window handle or calling an api that they're not supposed to and then we find out that oh we changed this little thing in conhost what's the big deal you broke all of the coca-cola machines in mexico because some programmer was looking in memory for something and made an assumption and you broke it so that's literally the kind of stuff that i'm talking about so this is stupid you see how it's still actually going what a nightmare all i did was ask for a directory that has like a maximum of like 30 frames a second or something so there are now two console hosts there's the windows console host and then the windows terminal can act as one the reason that there's two is because if we broke it then you can switch it back okay right now we have about 98 compatibility which is great but that breaks it for 2 million people because a lot of people use windows so you got to know about this kind of stuff because it's super interesting so now if i go and say windows r type cmd that's going to launch the same exact command.exe into a different console host in this case it's terminal cool and now terminal is going to be responsible for painting except terminal is written from scratch it's written in like directx and it's written in c plus it's hard to the metal it's asynchronous it does like a thousand frames a second and it's a whole other thing and it will work ninety-nine percent of the time 98 of time unless unless you the console writer are doing something weird doing something internal so already you can see that that thing's just ripping along it's going to go as fast as my system can go not lovely that's really really freaking fast it's even cooler it can do things like rectangular selects there's a ton of cool stuff that it can do now i've pissed off the whole thing i should don't rectangular select when you're looking at your entire hard drive that was probably a mistake and it also has this drop down here this drop down does discovery so it will look at your hard drive and if it sees other other prompts too many other shells it's hard i've got to get the language right myself if it sees other shells it'll detect them okay so it detected developer prompt for vs22 and developer powershell because visual studio put a plug-in for terminal and it detected those so windows powershell is the classic one that came with windows command prompt is the fake dos that's been with windows forever powershell came from the windows store that's powershell seven and then ubuntu we're going to talk about when we get into linux and then the other two were detected now sigwin i can add to that that list if it's ever going to install this is just really special um we'll we'll look at that another day imagine a world where cygwin appears in here if you go and run bash.exe with cygwin it's going to be a console app so it requires a console host to pa to paint its strings here's where things really get interesting they were so offended by the console host the original the original crappy one uh and its support for ansi and ascii you know color and vt 100 and terminal stuff that they made their own i think it's called like min tty okay and it is its own terminal tty is a teletype machine or a terminal end of something i'll show you that in a minute so min tty is the sigwin terminal emulator again visiting these websites is like going to the the 90s and it has full extern support secondary fonts all these kind of things emoji yada yada yada it's a vote of no confidence against the console host most of the things that they support are obscure i'm not saying it's bad or good i'm just trying to be very dispassionate about it i'm not trying to sell you anything all these things are open source so i don't care if you use them or not i just want you to know from an educated perspective why these things exist you with me so before they could have cygwin which is the collection of tools that fakes linux they needed a way to paint them reliably because you might run vim on our console host and it might look weird or a an emoji might appear in the corner or they might try to paint something and it'll it'll be the wrong location so min tty has better support it's a different thing that paints on the screen there's this thing though called the pseudo console in linux that was never supported on windows until we made it in 2018 come on internet we introduced khan pty there's a whole really really interesting history of the command line talking all the way back to how these terminals this is dennis ritchie of sea fame on a teletype so these original terminals would send ascii on the wire we heard about remember this ask ascii 10 and ascii 13 this morning carriage return in line feed those get sent serially across the wire and those would tell it to feed a line feed a line or return a carriage and on windows we would have dot matrix printers so we would have a carriage return a lot but on linux they only use line feed because they just wanted to feed the line and there's no carriage here so these would accept text input buffer the input put it on the serial line and then display it and back in the day you might have a terminal like this that would speak a language called vt 220 or vt-100 these things still exist today when i checked in on the plane in 2022 i could peek and see what they were using it was a windows machine running a text box you've seen these and it was running a text based gui that was probably a terminal into a mainframe somewhere right the windows machine was really just a host for that kind of stuff the modern stuff that you would see for that would be like midnight commander anyone use midnight commander i love i'm going to the archives here kids let's see if i have midnight commander win get search midnight there we go grab it win get install midnight commander you everyone use win get if you see if and is this the first time anyone's seen winged like what's that what is he doing so first time now you're going to be using it it's great yeah so win get is like apt-get for windows hence the name and then what it does is it has a oh midnight commander's already installed okay cool oh yeah oh yeah yeah everybody likes midnight command remember that yeah i remember norton commander well it was called norton commander when norton wrote it uh this is uh you know who wrote this do you who knows who wrote that miguel de acaza yeah yeah not just mono he wrote a bunch of stuff that was written by miguel and he wrote a really cool thing if there's any c sharp people in the room uh called gooey dot cs check this out gui dot cs console based user interfaces in c sharp yeah is that a good feeling or is that like was that a shudder of excitement or was that a shutter of like no not again it's happening again why did you just say why i will tell you why here's why this is me writing a blog post called it's 20 20 and it's time for text mode and here's one from 2004 windows is completely missing the text mode boat i'm telling you why because it's fast it's freaking fast it's stupid fast it's never touched the mouse keyboard fast it paints fast there is nothing faster no no amount of um there we go bring that back no no amount of of uh ex hardware acceleration buttons with with uh 3d shadows is going to be faster than freaking midnight commander baby so if you're making a terminal that someone is going to use only their their keyboard on and they're going to move around they're going to move around faster in text mode text mode is great especially the amount of communication sent on the wire is really minimal and writing these in c sharp is super fun so back to uh i think it's hilarious by the way that this thing is still installing anyway yeah so this is running in the context of windows terminal okay so he's positioning his cursors and his stuff around the screen you see that moment right there you see that so what's going on there what's happening is let me make it larger see how there's a flash we're negotiating with the text mode about how many columns and how many rows there are and that's all being done with like ansi art anyone do bbs's bulletin board systems yeah my old friends here love you guys ansi art looked like this and you said ascii are you correcting are you who said that so you call it you call it ansi i think this is antsy art you rob you say it's ascii art ascii art uses letters right so when i was uh when i was a wee lad we would do antsy art that's me ascii art which would be x's and o's and stuff and we'd print them out on like foldable paper and then we'd paste them up and we'd have like a picture of mr spock she had to stand on the other side of the room and squint and it was just black and white and then antsy is what is printing out like that's one character right there and that's another character you print half characters and if you look at the actual code you'd see like a carrot and then a code that switches the color and then the character itself and then you switch back to the other color so this is allowing you to send these things out the original windows console host doesn't you do any of this stuff it doesn't look right so a great deal of work was done in the windows terminal to support ansi thereby supporting backward compatibility and giving us the kinds of expectations that people have there we go here's some a that's some ascii art right so we see the difference there so if i want to do something like this and i want to draw lines like that that are smooth and attached then i'm going to need to use characters that i would not ordinarily have okay yeah oh yeah i got menu i forgot to show you that we got menus too oh this is another great point look at this friends i'm using the mouse right in order to pick these things so that is also mouse support that's in the terminal all of that needed to exist and be supported before we could bring you linux so it's complicated like often when you see things like this or we had that conversation before about cygwin people like to put the word just in front of stuff oh you just you're just running linux on windows well there's a lot going on here right we've been working on this for like six years and it's like oh we'll just run a virtual machine oh w cell's just a virtual machine with linux on it right there was the pseudo console the architecture of the pseudo console the ability to have ansi and ascii support all the way up fonts the whole thing so we go back to our article about the software terminals and the separation of that synchronous painting out to the screen how this terminal the console stuff works the entire architecture of that now brings me to what would old microsoft do they would come out with a terminal say that's the terminal and then they would kill connie mu and min tty and on and on there's a whole ecosystem of things we don't want to kill cygwin it works con emu anyone use con emu great little yeah a couple people back here we don't want to hurt them so what we do is we make an interface of console application services by which they can then call that so now the new versions of con emu and hyper and console z these are on x term these are all consoles that are part of the third-party console ecosystem on windows any one of which you can do i want you to be able to run bash in whatever terminal makes you happy right i like this one you could use kanyemu everything works the same so these apis are all open to the public and they needed to exist before we did these other things okay so back to our man you just are just winning at life right now there segment okay so wsl was not did not have a linux kernel it only ran user mode stuff and it was super fast on the windows file system why was it super fast in the windows file system because they were little tiny windows processes that makes sense a lot of people talk about performance issues with wsl as it relates to file systems we're going to get into that a little bit the better question rather than memorizing well if you use this on that file system and this and that but is to understand the why wsl are really windows processes therefore they will be fast on the windows file system wsl 2 uses a utility virtual machine so then this is where we start saying words like just and i don't like saying just in software because it minimizes people's work you all are working on cool stuff at work and if you told me about your cool thing at work and i said oh that's just and then i named another product you'd go it's kind of my life's work thanks right you'd feel sad you've been able to run hyper-v vms for years right you've been able to run hyper-v virtual box vmware etc these are all hypervisors what's good about them they let you run other operating systems what's bad about them they're heavy hey here's a virtual machine 30 gigs plop right boot it up okay let's wait 15 minutes and then you end up with a square inside your square right here's your host and here's the virtual machine inside it and then we try to hide things we try to make it so you can drag and drop from the inside to the outside or the outside the inside parallels does this really great on a mac it goes out of its way to lie to you to make you feel like you're not really running a virtual machine other problems with virtual machines for this solution are that it doesn't work on windows home that would suck if you had to buy windows pro just to run linux so we went out of our way to make sure that you didn't need hyper-v to run wsl here's where it gets confusing because microsoft if you go out to the start menu type in features you go to turn windows features on and off and you get to this dialog box from the 90s you've got that which you need to turn on you've got these two things and i don't know the difference and then you've got hyper-v proper hyper-v is like a meta checkbox it's the install everything i need including that ugly hyper-v client thing that lets you manage your virtual machines the hypervisor platform sits underneath that but all you need for windows subsystem for linux is virtual machine platform and wsl itself and that works on windows home that works at your house now today and that's cool because kids that are in university are going to want to run bash now they can and it works great they won't have the ability to run full-blown hypervisor type stuff this still uses the hypervisor and the the vt extensions to intel and amd but they don't run you know full boxes but it's cool because it works so when we say utility virtual machine we want to be able to create a small fast vm that starts up quickly that has a real linux kernel i don't know how to spell kernel kernel kernel it's one of those i don't know okay when okay wsl linux kernel there you go there is the source code for the linux kernel that microsoft uses on your machine this is really important it's a real linux kernel it is the linux kernel it's got some little herbs and spices that they've added in it to make it work better on windows but it is linux forked and followed and then it's got a little spice and i'll show you that spice in a little bit okay but it's important that you know that that's there so you can go and see it and compile it even better you can swap the kernel out yourself so it's literally a linux kernel on a file in windows system 32 and if you don't like it and you want to hack on it you can write your own and replace it it's definitely not your grandparents microsoft any questions so far all right this has been going on for a while four years ago we started this so if we come out here and i'm in uh fake dos and when i say dos i mean like you know dawson quotes and i can type dir and stuff like that if i type wsl i immediately have a prompt right here see how fast that was one one thousand okay lsb release dash a that's ubuntu 2004 that's not microsoft this is important that's not microsoft's ubuntu that's ubuntu ubuntu from them now remember all that conversation we had about the difference between kernel mode and user mode the ubuntu that we're using is not shipping the kernel it's the user mode file system for ubuntu up that means zipped up up and then simply downloaded via the windows store they stick it in the windows store we're just using the windows store as a content distribution network otherwise we'd stick it on github and then it untars and then it uses the kernel that we already have the kernel is the windows kernel for security reasons the the windows linux kernel and it gets updated automatically or you can run wsl-update and it will update for you you don't really have to do anything about it we've recently put a preview of wsl in the store in the past you'd have to run windows update to get updates to wsl now you can just get it from the store itself which means you don't need a new version of windows to get new features so we're actually adding new features to wsl from the store but i want you to understand the separation of those things it's super important to understand that you saw how fast that started that's not a vm the way you think of a vm now if we go to the store and we literally search the windows store for linux does it all make you feel dirty don't you just like am i supposed to be here i just feel a little bit questionable whenever i do these things you got kali linux there's the linux preview i was telling that you can just install this over the top of the one you have you've got sousa you got all these different linuxes i could go let's install a linux actually i think we've got alpine and we got oracle linux is alpine in here alpine alpine wsl so i got two ways that i can install this i can push install or i could do it from the command line so i could literally push install but i'm going to be at the command line and type wsl dash dash list dash v those are the linuxes i have running right now docker installs its own i'll explain that to you in a second ubuntu is marked with a star that's the default so when i type wsl i get ubuntu i can get whatever one i want but that's the default i can say wsl dash dash install and i think it's or is it w cell install let's see ah go back ah crap is it dash d thank you i always you know there's like dash install and dash dash install and 1-2 install dash d for distro alpine is that right well now you said there were no is still how many dashes do you want man let's go two dashes are you sure let's try this w cell i don't like dos i'm gonna go to powershell because it's prettier and i have a cool background wcell it's uh list online there we go oh okay so dash dash install d i think i can get alpine even though it's not listing it alpine wsl man you suck maybe i need to get it maybe only certain ones are here i'm going to try anyway so i could say install dash debian and they would go and get that i don't know why alpine's not showing up in the list it's probably not like officially allowed or something let's go and see where alpine is something i'm going to have oh here it is it's untarring there's the tar see up the top there second line so it's doing some things faster than cygwin just saying just saying all right now we're in alpine okay go back out here see now i've installed a linux it's that fast that was pretty fast now where'd cygwin go okay that's a little small a little small it's a lot small ah come on cygwin what are you doing man this thing you can tell it was written in in a time of distress but i want to point this part out here that the console of cygwin is not the same one the host is different that said though if i wanted to there we go like if i run vim so i can't have vim you have vi defaults to vim okay i mean thanks let's see if we can see terminal that sigwin is installed where right click open file location right click open file location for real sorry it's small i'll make it big in a second there we go just want to make this point okay those are windows executables okay now when we ran cygwin that means when i i'm going to close their terminal thing because it's stressing me out and i'm going to right click on this and i'm going to say open file location and i'm going to look at this at the properties and i'm going to look at the target and open that up in notepad to make it larger okay so it looks like they're running this thing mntty so that probably means i can run that down here and that's going to default to some stuff and i can go in here and figure out what does it really mean like what are we running for real and could i add that to the windows terminal you follow so i'm going to right click and say open file location and i see a is there a bash in here here's a bash i'm going to right click on that and say copy as path we'll come out here to fake dos where's fake dos there we go i'm gonna paste that in okay so i just went from fake dos to cygwin so now i know how to run that so then that means i could go into windows terminal hit settings say add a new profile new empty profile name it sigwin sigwin command line i betcha i'm guessing here i've never done this starting directory i don't know save this might work could crash everything who knows maybe i maybe it is crashing everything i may have broke something you mad at me what's happening what's happening all right i have no idea let's try go away okay here's cygwin appearing in the list ah you see how alpine just showed up got detected you go so cygwin doesn't know that it's running in a different thing it just outputs strings but you see how it's color it's outputting ansi control codes which terminal understands so that means that if you use like anaconda or python or whatever you can put whatever you want in here now i just got alpine up to appear and we saw that over here when we said wsl dash list sv so i can say now wsl wsl-d alpine and run it immediately or i can pull it up from here now because i'm using the windows terminal i can hold down alt with one finger and click on these things so now i'm just doing that multiple times we've got ubuntu we've got alpine we've got dos and we've got powershell all in windows terminal okay then i can hit alt enter and go full screen and pretend windows doesn't exist then i can hit w control w control w control w control w because i've gone into windows terminal and i've mapped control t for new tab and control w which are the things i use in my browser window to open tabs and close windows and i map them in here nicely as well so if we go back into ubuntu and we type in df we can actually see the file system we see a couple of interesting things here the most interesting thing is here mount c remember at the beginning of the conversation we said that wsl one is really fast because they're windows processes talking to the windows file system on wsl 2 if you are talking to the windows file system you will be sad it will be about 5 to 10x slower because you're talking to a mount point to a remote drive that runs a different file system it's not the same file system you can think that that's a limitation yeah they're going to do the best they can but they're probably only going to be able to get it about 30 percent faster but if you write to the linux file system which is up there at the top you're writing in fact to a hidden vhd which means that you're bypassing ntfs you're bypassing defender and you're running at full speed it's within three to five percent of native linux speed so your first like thought might be when you get this you're like oh i've got bash i've got i've got vim like i've got all the things i want to do so i'll go to c users scott desktop and then you know party get clone go nuts right but what's wrong with that it's going to be firing off changes to one drive every time i hit something it's going to be fighting with ntfs all of my linux files are going to be looked at by defender or whatever all of that's complicated so what you want to do is you want to stay on the linux file system so i've put my source code here so here's my website i keep typing dir okay now here's where things get weird remember how i said that there's some special herbs and spices in our in our kernel you all know because you're programmers that if you run vim you can't exit ever you just have to shut the computer down right this is just part of world but now you can just shut down the virtual machine here's where we offend people you're either going to be offended or you think it's amazing or you're going to think both and a mumble went to the crowd is this being recorded i hope not because somebody's like this is microsoft you suck you know they made it 52 minutes into the talk and then that was that was that was when they broke me and then hanselman ran notepad from linux and i was like that's unacceptable if you run a dot exe here's the little herbs and spices we have the windows path in your linux path huh yeah it's nice yes and if we see that mz mike matthew zawinski's name or whatever we go i can't handle that i'll let windows handle that isn't that freaking awesome like why not okay so then we had to update notepad remember how i said that we didn't just do anything there was a cast of thousands involved in this stupidity this is amazing so we won't mess up your files okay so now what if we did this what we actually run a plan 9 server and it's your local machine so it doesn't go over the network you have access to your linux file system from windows explorer why not because it's awesome right how freaking cool is that remember when i said at the beginning that you can run a square inside another square does that feel like there's any squares involved it's completely blurring the line between what's possible and what's not possible so then why don't we just put a freaking tux in windows explorer we did thank you very much so now if i click on the linux talks all of my linux distributions appear in windows explorer yeah that's good okay so then what if i run.net on this machine and i run it run to run my website that's going to start up on localhost who's local host what is localhost what is life anyway right we live in a society nobody knows what's happening cats and dogs living together mass hysteria what's localhost who's localhost local to what what is localhost means it means your computer but this is another computer it's a virtual machine so microsoft really works hard on this and the developer division dev div where i work works on what's called the principle of least surprise right i'm not joking this is a real thing when we have conversations about what would the customer expect what would be the least surprising thing to do right uh we also do a thing called the pit of success when when the customer falls they fall into the pit of success so they're going to go and they're going to click on this by the way you notice that it underlines when i put my mouse over it that's new too windows terminal that way i can click on it right so now it's hit localhost that's interesting let's run tcp view from cis internals and look at our ports you see that remember how there's a kernel involved here but it's got to deal with another kernel when you listen on a port on a computer you get one port and one process so that means we've opened up a port 5000 5001 but it happened inside linux we wouldn't want someone to hit localhost 5000 on the outside and get confused we couldn't open another port there so we have a wsl host hold that port open and it port forwards transparently so localhost is your computer that box right there regardless isn't that cool yeah that's the least surprising thing that would work it works really really well that means that i can run my application my node app my ruby app or whatever and as soon as we see someone bind to a port like that we make it available to the outside but the outside is just my computer which is really cool all right when i run h-top i can see all eight processors on my machine and all the memory that i want because it's my machine there's a config file a hidden config file you can set to decide how much memory you want the system to use and it will grow or shrink depending so right now it's using a lot of memory because i'm running docker but ordinarily it only uses about 400 or 500 makes and it grows and shrinks appropriately so then what would be an incredibly amazing and stupid thing to do let's install the on ubuntu 2004 how to install the google in with bing okay let's go over here i'm just going to copy and paste whatever the internet tells me to copy and paste because that's what you do just copy paste from the internet this is fine what could go wrong i'm running apt-get update that's not too bad installing a bunch of stuff when people go on the internet and they're like following instructions and they have a windows machine and then it says hey you want to install this thing go to your terminal and then they show the dollar sign and the windows person says my thing looks like a c colon and they don't feel included now you can just do that with these things work you want to install redis you want to install do it it works just fine the other the other cool thing is that i can go and run applications on linux and i can i can work on them on windows i can work on windows and target linux and do all kinds of stuff while this is coming up here i'm going to open up another ubuntu over here running simultaneous i'm going to go into that folder hanselman i'm going to type code dot instead of explorer dot visual studio code starts up in the corner you can see it says wsl ubuntu if i hit ctrl tilde tilde that gives me a terminal inside of visual studio code for linux if i say control o for open to open up a new file that's the linux file system i can now in windows in a windows app work on my application and this on the local or the linux file system and when i hit f5 i'm debugging from my windows app over to my linux app i can do this in visual studio proper as well so in visual studio senior i can hit f5 and debug as well the other thing that i can do is i can run docker so let's close this one the was going really fast and then it got slow there inside last last second and we'll go over to our github folder and i'm going to say docker build and now i am building in docker docker on windows uses the linux subsystem as its underlying platform so that docker distribution that we saw is docker's little partition it's little space so now i've got my application completely built on docker and i can also click a check box and run kubernetes as well the is not going to work very well right now because the internet here sucks so instead i'm going to click on let's go and say apps u and i'm going to open up where did that one go here we go here's an app in my start menu on windows when you install a gui application with wsl we put a tux over it in the windows start menu and detect it automatically and then when i click on it it starts up full speed so this is a get application that lets me look at my git tree you saw how fast that started so i can look at the history of my application the would start just as fast you see how it looks like a linux application because it is one that's a local file system how do you think that's so fast what's going on there any thoughts any guesses well we got explorer working by doing that local file system thing we just made it a file system and explore it and look at it that's a local remote desktop remote desktop is hardware accelerated 3d hardware accelerated that means i can run like if i wanted to theoretically emulators like i can run the dolphin emulator for a nintendo 64 at 60 frames a second this isn't like slow rdp like back in the day that is hardware accelerated and we have a separate distribution that manages all the hard stuff seems like something you could break or mess up really easily sound works out of the box 3d acceleration works out of the box all of that's done in a hidden distribution so you've got your ubuntu linux distribution and then all of the hard configuration stuff is pre-set up in a hidden part hidden partition that you can't mess up and it's super fast as you can see right and this is the you can see that you can see the difference actually i don't know if you can zoom in or not but you see how the mouse changes when i get in there see how fast that is it's pretty sweet so all of this is in my opinion made i like windows i like the windows desktop i like windows 11. i like my hotkeys i know where everything is but now i can go and target on azure or whatever dot net i can pay 30 percent less because there's not a windows tax i can put things in containers i'm learning more about kubernetes if you're a mac person and you're wondering what the what the hype is about you can run linux on windows and it runs really really really well any questions we are four minutes over what happens if i run yeah that's a good question so the question is what if he wants to run code by installing it in linux [Music] yeah so you'd be in linux running a windows app pointing it to the mount point that would probably be a bad idea let's find out i would probably not do that i think at that point you're asking for trouble think the first question is why would you want to why would you want to do that so i'm in the mount i'm in linux on the mount point and you want me to do that okay so it starts yeah it's like don't well do you trust it it says don't do that so then my my answer my question to you would be do you hate yourself or do you want to learn more yeah don't do that is the answer to that question i think the the point that the gentleman is making is a valid one is that we are going out of our way to tell you don't do that if you choose to do that you will be sad so yeah don't do that i don't know why everyone is moving so slow right now but uh yeah our internets won't work the is uh photoshop for linux and it runs full speed and it's great it's fantastic good question that's a good question uh let's go here first oh there's another great question so if you're in vs code and you use wsl vs code will prompt you to install different extensions like remote containers remote ssh that remote thing opening a remote isn't specific to wsl so if you're using raspberry pi's and you have ssh into the raspberry pi you could develop on windows ssh into the pi or any remote linux system it's not specific to wsl and then if i go and say open workspace from file or something like that there's a section here where it says well i want to open it from a container i can do development inside a docker container i can do it from ssh or from wsl and wsl will notice that you're opening something in wsl and say let me reboot and start up again and what it does is it splits visual studio code in half which is a good thing so extensions check this out let's go back out and let's go ubuntu make the font bigger hanselman code dot okay i'm going to go back out here i'm going to open another ubuntu to make the point and i'm going to hit h top i need to fix my colors there it is right there visual studio code notices that it's never been run before that installs a server that does that called the language the lsp language server process what's lsp stand for protocol so the lsp host so when you're typing your code in rust or go or c sharp and you type like foo dot and there's a drop down who populated that drop down the language server process the language server protocol host some host had the context on.net which is what i know more it's like roslyn knows what to show you you see so that's running over there so in window in the visual studio code your extensions live in a host of their own so if you click on extensions look these are the local installed extensions or that's the one that's installed inside of ubuntu so you can mix and match your extensions and that brings me and we're out of time to what are called dev containers which are genius and you want to go to my youtube and look at my development work that i did with uh jan de davalier from um oh my posh he does his work in go i didn't want to install go so if you want to work on oh my posh you clone his repo you open it in visual studio code it has a dot dev container folder with a docker file it describes everything you need including the extensions that you need in visual studio code and says hey this is a dev container fires up a container builds everything installs the stuff you need to do the work and then runs vs code against the server that runs in the box that's how code spaces works it's the same technology the same concept visual studio code is a client server application every one of those extensions can live in its own container and be remoted with these different protocols not cool it is cool it is it is deeply deeply cool yeah it's fundamentally the biggest thing to happen in my opinion in software in a long time because then i can open up visual studio code to a remote dev container and i could have a chromebook with you know 64 gigs of ram and a 60 16 processor or something like that all right get out of here i'm sorry i'm talking too much [Applause] you
Info
Channel: NDC Conferences
Views: 41,662
Rating: undefined out of 5
Keywords: Linux, WSL, Windows Subsystem for Linux, Windows, Apps, Docker, Terminal, Windows Terminal, NDC, Conferences, 2022, Live, Porto, Scott Hanselman
Id: tuhzVDc0Slg
Channel Id: undefined
Length: 68min 41sec (4121 seconds)
Published: Thu Jun 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.