Live data from Hacker News

Ubuntu on Windows

blog.dustinkirkland.com

151–160 of 933 posts

Re: Ubuntu on Windows

#151
post #4

"Linux geeks can think of it sort of the inverse of "wine" -- Ubuntu binaries running natively in Windows. Microsoft calls it their "Windows Subsystem for Linux"." I find it amazing that you can have such a functional Ubuntu environment by translating system calls. Microsoft does have the advantage of Linux being open-source I suppose, while the Wine project had to reverse engineer DLLs. Or have you supply them on yo…

So, uh. I did this! Crudely. In 2010.

http://cowlark.com/lbw/

It's a Linux syscall translator for Windows. It works well enough to run a Debian userland, although it's got so many holes and rough edges that I would never, ever, ever suggest using it for anything other than a stunt.

It uses Interix to do most of the heavy lifting, so all LBW does is to translate from Linux syscalls to Interix syscalls; so we get a Unix filesystem and user permissions and sockets and fork etc for free. (Interix was great. I'm glad they're bringing it back from the dead.) Unfortunately not all the system calls directly map onto each other; so Interix has a native fork(), but Linux emulates with clone(). I couldn't make threads work.

A few of the biggest problems were:

- the Windows page size is 64kB; the Linux page size is 4kB. The ld.so loader will try to map two bits of executable within the same 64kB boundary, and, of course, this doesn't work on Windows. I crudely hack around it by allocating pages of RAM and copying things. Write-back mapping only works at all if the application lets mmap() pick the address.

- very very very different register usage. glibc on Linux uses gs as a 'pointer' to the current thread's private data area, via a special syscall. Windows resets gs to 0 on every interrupt! I crudely hack around this by intercepting null pointer dereferences, looking at the instruction to see if it was gs, and then reloading it with the right value.

- even then, that syscall sets gs to point at a GTD segment with a size of 2^32; this wraps round the entire address space, which allows very large offsets in gs to be treated as negative numbers. Windows doesn't let you create GTD segments. It only allows LTD segments, and it caps the segment limit to the end of the user address space, so this trick won't work. I crudely hack around this by intercepting segmentation violations, looking at the instruction to see it it's a [gs+negative number] dereference, and then binary patching the executable to use a different instruction.

- glibc is horrible and undocumented. There's a big pile of key-value strings pushed onto the stack above the environment when the process is initialised, containing various magic numbers. ld.so will just crash if you get this wrong. I spent a lot of time reverse engineering the ld.so source code to figure out what these were and how to set them up.

It was all vile and horrible, but it worked surprisingly well (i.e., it worked, which was surprising).

Using the NT kernel's personality system to implement Linux syscalls natively is totally the right thing to do; that's obviously what they're doing here.

I would love to know about the internal Microsoft politics which made releasing this possible. I wonder how long it's been brewing? I did LBW in about a month of evenings; the core logic wasn't hard. I wouldn't be at all surprised if this hasn't been floating about inside Microsoft for years.

Re: Ubuntu on Windows

#152
post #90

Earlier quoted context omitted.

I completely agree. I only really switched to OSX because getting node tools to work on windows and cygwin is a pita.

I've been "stuck" with a 2010 Macbook since Apple isn't refreshing it's laptop hardware soon enough. Plus I'm sick of soldered in RAM and other BS. For devs that do heavy Linux work (but have stuck with a Mac OS for GUI/app reasons), is it time to move (back) to Windows? If so, what would be a good laptop to get at the moment?

I would say no, especially if your mac had an i7 and reasonable amounts of ram.

Re: Ubuntu on Windows

#153
post #69

I don't get it. What's the use case for a few core utilities running natively?

You can run any* Linux binary on WinLS, including apt-get in the Ubuntu rootfs. * within the probably surprisingly broad limits of the WinLS syscall emulation, though it wouldn't support niche OS config stuff, SELinux calls, etc.

So I can install apt then install apps like Firefox, Thunderbird and run them that way instead of using Windows binaries? Interesting ...

Re: Ubuntu on Windows

#154
This is great.

For the last couple of years, as a windows user, I have just been installing Git Scm, which includes something similar to this and have been using that for all script / command line needs.

If this was baked into Windows so much the better! I would love it if nobody ever wrote a single CMD or PS1 file ever again. Let's please all just converge on bash and put this debate behind us.

Re: Ubuntu on Windows

#156
post #12
post #4

"Linux geeks can think of it sort of the inverse of "wine" -- Ubuntu binaries running natively in Windows. Microsoft calls it their "Windows Subsystem for Linux"." I find it amazing that you can have such a functional Ubuntu environment by translating system calls. Microsoft does have the advantage of Linux being open-source I suppose, while the Wine project had to reverse engineer DLLs. Or have you supply them on yo…

Windows NT had a POSIX subsystem awhile ago, not sure what happened to it. The NT Kernel was designed to have different personalities like Win32, OS/2, POSIX, etc It could be an updated version.

From elsewhere in this thread:

"Windows NT was designed from the start to have modular subsystems. It was most infamously used to provide a POSIX subsystem which really only checked boxes on government acquisition forms. :-)"

https://news.ycombinator.com/item?id=11391290

Re: Ubuntu on Windows

#158
post #90

Earlier quoted context omitted.

I completely agree. I only really switched to OSX because getting node tools to work on windows and cygwin is a pita.

I've been "stuck" with a 2010 Macbook since Apple isn't refreshing it's laptop hardware soon enough. Plus I'm sick of soldered in RAM and other BS. For devs that do heavy Linux work (but have stuck with a Mac OS for GUI/app reasons), is it time to move (back) to Windows? If so, what would be a good laptop to get at the moment?

Why not move to Linux?

Re: Ubuntu on Windows

#159
post #4

"Linux geeks can think of it sort of the inverse of "wine" -- Ubuntu binaries running natively in Windows. Microsoft calls it their "Windows Subsystem for Linux"." I find it amazing that you can have such a functional Ubuntu environment by translating system calls. Microsoft does have the advantage of Linux being open-source I suppose, while the Wine project had to reverse engineer DLLs. Or have you supply them on yo…

Some long term thoughts:

1) Linux has won the server (web) market. Developers would like to use a Unix box to work on their server code so they typically move to OS X. This could prevent that switch because they can still use Windows to developer their Linux server software.

2) Many projects start out as Linux and stay Linux and are only ported after much time and effort to Windows. Enterprises when faced with a tool that they want to use will also look to switch off Windows. Now rather than the cost of switching they only have to pay to upgrade their windows boxes to use the tool.

3) There is now a major incentive for developers to only build Linux binaries because it will work more places. This might cause a faster drain of developers as they eventually remove all windows specific code and can more easily migrate elsewhere. This feels eerily similar to the OS2 story and no doubt in the next week I expect to see more than a few articles discussing this very thing.

4) It will be much easier for Microsoft to bring much loved Linux tools to Windows so you can expect to see a more rapid increase of tools announced that now work for Windows.

Re: Ubuntu on Windows

#160
post #33

Scott Hanselman has a good write-up here: http://www.hanselman.com/blog/DevelopersCanRunBashShellAndUs... Google Cache: https://webcache.googleusercontent.com/search?q=cache:http:/...

Looks like they are launching ELF files, then translating the linux syscalls to WIN32API calls at runtime.
Post reply on HN