
Foreign Linux: Run Linux binaries on Windows without drivers or modification - anacleto
https://github.com/wishstudio/flinux
======
mappu
Cygwin is impressively complete - if you haven't checked in on it recently,
there are over 5000 packages in the official repo (that's more than Arch
Linux's official repos), and adding the
[http://cygwinports.org/](http://cygwinports.org/) repo gives you full KDE,
GNOME 3 and Xfce on windows (although KDE has a first-party port).

What this tool offers over Cygwin is the ability to run _unmodified_ linux
binary-only software for which you do not have the source code. For me there's
not very much of that although i release some at $DAYJOB.

~~~
Maakuth
My biggest gripe with Cygwin (aside performance on some syscalls) has been
package management, which used to require setup.exe to add or upgrade
packages. That was nicely mitigated when I found out about apt-cyg[1]. It's a
apt-getish frontend for setup.exe command line. Not as nice as real apt-get of
course, but "apt-cyg install something" takes care of the most important use
case.

1: [https://github.com/transcode-open/apt-cyg](https://github.com/transcode-
open/apt-cyg)

EDIT: changed to github url

~~~
Lambdanaut
It would also be really nice if Cygwin did a quick ping on all of the package
hosts and then ordered them in order of least latency relative to you.
Oftentimes I have to re-start the install process because I accidentally chose
a host that's slow enough to delay the install for hours.

~~~
AlfonsoP
I wish it would sort by network throughput instead of latency.

------
kyberias
This has been tried before as the author notes. E.g.

[http://lbw.sourceforge.net/](http://lbw.sourceforge.net/)

Previous experiments have stumbled on Linux usage of %gs and other
segmentation issues.

The present project is possibly trying to overcome those obstacles with
dynamic recompilation. It's in very early stages though.

~~~
david-given
Hey, I resemble that project!

Yeah, it ground to a halt due to fundamental differences in the way Linux and
Windows binaries work. I'm actually now kind of scared at how much _working_
hackery LBW ended up containing: it'd dynamically patch the binary after
trapping out at instructions manipulating things that Windows wouldn't allow
access to.

(The LBW instruction patching code is here. It's entertainingly bonkers.
[http://sourceforge.net/p/lbw/code/ci/master/tree/src/ehandle...](http://sourceforge.net/p/lbw/code/ci/master/tree/src/ehandler.cc))

Not all the horror was Windows, mind: Linux's interface to executables is
barely documented and extremely fragile, involving passing a key-value table
full of magic parameters on the stack after the argument and environment
tables. And, of course, I'd have to replicate this otherwise glibc would crash
out. (At least, I thought I did --- I cannot now find any of the actual code.
Maybe I got rid of it?)

I eventually gave up because it was obviously not a tenable approach. Plus,
it'd completely fail on 64-bit platforms. Dynamic recompilation is obviously a
way more preferable approach. If I ever have to use Windows again, god forbid,
I'm definitely checking this out.

------
Surio
This looks like an interesting project to keep an eye out for. On the topic of
cygwin, I would also like to recommend mobaXterm, that I use instead of cygwin
nowadays... It is an interesting choice in the alternatives we have. So, those
of you that use cygwin, take a look at it here:
[http://mobaxterm.mobatek.net/](http://mobaxterm.mobatek.net/)

If you are thinking about trying cygwin, I would recommend this instead, as
the installation is relatively easier when compared to cygwin. (I have no
affiliation to mobaxterm)

Another new indispensible tool for me is cmder, which leverages ConEmu, clink
and mysysgit to provide a wonderful UX in the commandline for me - just
brilliant. Here:
[http://bliker.github.io/cmder/](http://bliker.github.io/cmder/)

Memo to self: Spend the next 4 months learning powershell during lunch breaks!

~~~
bryanlarsen
The big problem with MobaTerm is that it includes really old versions of the
standard unix utilities, and it's difficult to integrate with newer & missing
utilities. This isn't a problem that's limited to MobaXTerm, but the way
MobaXTerm does things makes it harder to fix.

Let's say you want to set up a standard dev setup. So you install MobaXTerm,
vagrant, emacs, msysgit, and rsync. Each of these require SSH for full
operation, so in the interest of making things easy, the installers bundle
SSH. You now have up to 5 copies of SSH installed, all storing their private
keys, cert stores and configuration in different places. What a mess. And some
things aren't compatible with each other. IIRC, vagrant is built with cygwin,
so you have to make sure you use a cygwin rsync with it, the msys rsync won't
work.

To keep everything sane, start with the standard cygwin or msys installer, and
install everything using that.

Does conemu include mingw-get? If so, that sounds like it might be a good
solution. If not, I recommend avoiding it.

Or just reformat and install Linux. That's what I ended up doing. Putting up
with poor HiDPI support in Linux was much more tolerable than the horrors of
trying to use Unix utilities in Windows. And HiDPI support is improving
quickly in Linux land....

~~~
Surio
I agree with your point on the very clumsy SSH tack-on take up with this
approach.

About the older utilities, again, I completely agree. But, the way to create
the mx3 bundles is easy. Actually, on the website/forums, several users there
have been a few 3rd party utilities of the same. The format is transparent for
anyone to create their own set of utilities on top of what mobs provides.

------
kikki
So it's cool, and a lot of people might see it as a bad thing that if this
took off could potentially bring Linux users back to Windows. I personally
think it could do the reverse though and encourage people to try Linux. If
they enjoy using some small selection of tools that work on Windows
(presumably all CLI tools) then they might be convinced to give a full distro
a go. Interesting concept though and I really hope it works out.

~~~
spurgu
I think it would mainly be used by Linux users forced to use Windows for some
reason (at work, for example).

~~~
sunilkumarc
I totally agree with you. Some of us who really like Linux are forced to use
Windows at work. This project is really going to help a lot of people :)

~~~
wampus
But if you can run this, you can run VirtualBox, which is a much safer
alternative (and simpler, if a live ISO meets your needs).

~~~
usefulcat
But not equivalent for some use cases. Like, say I want to use 'find' (not
windows find.exe) to find files on a Windows filesystem.

~~~
leni536
What I typically miss on Windows is "rsync".

------
sz4kerto
If this can bring me a working * nix shell under Windows, I'd be extremely
happy. Windows is great for everything except I have never learned PS as well
as I know the * nix shells -- with this, I could enjoy the hardware and proper
multi-monitor support, speed and stability (seriously) of Windows and use the
* nix command line.

~~~
cssmoo
To be honest, and I say this with a massive cringe, after 20 years of Unix I'm
more productive with PS in a couple of months! It's quite refreshingly easy to
use and I genuinely had no idea how much time I was wasting on parsing
streams.

Now I feel horrible for revealing my dirty secret :(

~~~
joelthelion
What do you use for grep?

I tried using Powershell and did a few things with it, but while it is a great
shell, the lack of good tools like grep prevented me from being really
productive.

~~~
pjc50
I've ended up with

Select-String "pattern" -Path file.txt | ForEach-Object { Write-Output $_.Line
} | Out-File t.txt

Slightly Heath Robinson, but by default PS will _truncate_ lines to terminal
width, even when writing to a file, which is a disaster for any kind of
subsequent machine processing.

~~~
hug
For the uninitiated this looks completely barbaric, but makes a whole lot of
sense when you consider that PS is built around an object-based pipeline.
'Select-String' in PS doesn't actually return a string, but a 'MatchInfo'
object, which contains more properties -- 'linenumber', 'context', etc, as
well as the 'line' property which contains the actual matched lines as
strings. The default output from any part of the pipeline is a human-
readable/terminal-display-compatible representation of the object's commonly
used properties, thus the truncation.

As an aside, you can replace the foreach with select-object for an efficiency
gain:

    
    
        sls "Pattern" file.txt | select -exp line | out-file t.txt

~~~
ygra
You also don't technically need to go through Select-String if all you care
about is the line itself:

    
    
        (gc file.txt) -match "Pattern" | Out-File t.txt
    

Comparison operators that get an array as their left argument return the items
where the comparison returns true.

------
VSpike
Always nice to have more alternatives, but I find either
[http://bliker.github.io/cmder/](http://bliker.github.io/cmder/) (a tricked
out console with a nicely tweaked git bash environment) or
[http://babun.github.io/](http://babun.github.io/) (Cygwin but easier to
install and with nicer defaults) better for daily use when forced to wallow in
the Windows pool at work.

------
Intermernet
Firstly, this looks brilliant. If anyone can remove the extra layers of
cygwin, mingw, xming etc. and provide a direct ability to execute linux
programs from powershell/cmd , I call Black Magic. Voodoo I tell you; Windows
cannot be this user friendly (I work with it every day).

Secondly, completely off topic, I noticed that Github picks up 0.4% of the
code-base as Objective-C
([https://github.com/wishstudio/flinux/search?l=objective-c](https://github.com/wishstudio/flinux/search?l=objective-c))
due to the files functionally consisting of a single line, `#pragma once`. Is
this statement more common in Objective-C than C or C++ ? Just wondering if
Github detects the language based partly on some statistical analysis of other
existing code, or if it has "set rules".

~~~
matthewmacleod
Github's language detection is actually open-source — you can have a look at
what it does here:
[https://github.com/github/linguist](https://github.com/github/linguist)

Linguist uses a number of different 'strategies' to identify the language – in
the case of C vs. Objective C, it uses a pretty simple heuristic
([https://github.com/github/linguist/blob/master/lib/linguist/...](https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb#L83-L90))
to disambiguate C/C++/ObjC where required (such as in header files, which
can't be disambiguated by file extension.)

In this case, the content of the file can't be reliably disambiguated, so I
imagine it'll probably fall back to the Bayesian classifier. Interesting that
the classifier identifies it as Objective C though!

~~~
pbhjpbhj
I'm not a programmer so bear with me.

They have a cadre of samples in the project, searching on "#pragma once" shows
no examples of Objective-C (that I can see) using that line but does show
C/C++ examples with it. Is that the input to the classifier?

The heuristic you linked appears to default to identifying as C; that regex
doesn't look like it has anything to make the else-if return the sample as
Obj-C.

I'd have expected the fact that most other files on the project were C to be
the dominant factor that - without any other positive result in the classifier
- would weight the files as being C. Presumably this data isn't used in
classifier though?

Interesting.

------
fijal
This is quite funny, since you can't run _unmodified_ linux binaries on other
linuxes (that is a binary distribution on linux is generally not a thing and
there will always be a distribution that does stuff just differently enough),
so a recompilation on windows sounds like as good of a solution.

~~~
emodendroket
I remember from trying to use Linux on a desktop machine (and this was like a
decade ago so maybe it's no longer relevant) that graphics drivers were often
distributed only as binaries.

~~~
towelguy
And I remember (from a decade ago as well) having to recompile my kernel to
use those binary graphics drivers :)

------
sspiff
This is brilliant! Much more light weight than a VM. I hope they can iron out
the remaining kinks.

I used coLinux many moons ago, but it hasn't been updated in any significant
way lately, and still doesn't work on 64-bit Windows.

~~~
stuaxo
It's a shame - it looks like the work was started, it probably isn't _too_
much work to fix the 64 bit stuff ??

~~~
sspiff
I think it's in part because 64-bit requires driver signing, and there are no
funds for signing the coLinux64 driver.

------
72deluxe
Very impressive. I'd appreciate if they could get WINE working under this
though..... :-)

~~~
leni536
Actually there is an effort to make wine compile and run on Windows.

[http://wiki.winehq.org/WineOnWindows](http://wiki.winehq.org/WineOnWindows)

~~~
Mahn
That's interesting, I wonder if it's mature enough to run on itself :-)

------
sengork
"Linux services for Windows NT"

------
anotherevan
This reminded me, with some nostalgia, of a long time ago using Cooperative
Linux on my work Windows machine with sole intent of being able to use Amarok
as my media player.

(Version 1.4, before Amarok turned to crap. I use Clementine now, which has a
native Windows port.)

------
abalashov
I admit that I am a bit lost as to the value of this endeavour, or Cygwin for
that matter, in an era where just about all commodity hardware can sustain
virtualisation.

I used to have the problem of my dayjob requiring me to run Windows and use
Outlook/Exchange, and Cygwin was a useful means of coping with that. But that
was back in 2006. Now, it seems to me one should just fire up a Linux VM in
VirtualBox, full-screen it, and pretend the encapsulating Windows doesn't
exist.

~~~
vectorpush
_or Cygwin for that matter, in an era where just about all commodity hardware
can sustain virtualisation._

I use cygwin primarily as an ssh client for my local linux VMs. My IDE is
vim/tmux/zsh, and I've found ssh via cygwin provides an experience that
closely resembles gnome-terminal in appearance and behavior (gnome-terminal
being the best terminal emulator around IMHO)

~~~
Scarbutt
seems overkill, wouldn't just putty do in your case?

~~~
vectorpush
As I said, I prefer cygwin's look and feel to the alternatives. Also, cygwin
supports transparent windows out of the box. I don't think it's overkill at
all, the only package you need is ssh, everything else lives in the VM.

------
malkia
Wondering how well fork() works?

~~~
RDeckard
I was wondering the same thing. The features page claims "copy on write fork
implementation" but that is not universally true. A cursory look at the code
suggests that every allocation is a Win32 file mapping object (aka NT section)
underneath, which the fork worker (mm_fork) remaps into the forked process.
This means the memory is shared between two processes, and not in a CoW
fashion. A write to the memory region from the forked process will be visible
in the parent. These are not correct semantics for fork.

I am hoping I misread the code and someone can prove me wrong here, because it
looks like a cool project with a lot of potential.

~~~
malkia
From little I've read on cygwin mailing list (btw, cool folks over there) - it
seems the problem is not very easy. If I'm not mistaken the Windows Kernel
actually does support fork()-ing, but the win32k system somehow "forbids" it
(lots of grains of salt). After all for a long time there was a commercial
UNIX compatible offering on Windows that probably used fork() all over and
must've worked (also it supported case-sensitive names for the filesystem)

BTW, the coolest usage of fork(), and granted a pain in the ass to port
possibly was the one in REDIS where antirez used it to fork() at certain time
the current process, then write back the state of memory knowing that it'll
get a "snapshot" of it, and if writes to disk succeed, this "snapshot" would
correctly and fully be written to the disk.

I know there are plenty of other uses (for example this way "lua" can do
threads with just a bit of a communication library on top... e.g. any language
without explicit thread handling can actually use them).

Wondering what made win32k folks disable it. Possibly there are lots of
gotchas...

~~~
MichaelGG
Using fork to get a "snapshot" of memory seems... like a roundabout way of
doing things. The underlying memory mapping mechanism should expose a simple
way of just doing it directly. (I _still_ don't understand the point of fork,
especially when most of the time exec is just gonna overwrite things anyways.
And the impact fork has is to massively increase potentially used memory,
leading to the dumb memory overcommit semantics and hack fixes like OOM
killer.)

~~~
malkia
Yup. indeed, but it seems so elegant, in the same way (elegant) as one can
implement undo using closures - at the expense of unaccounted resources (cpu,
memory, who knows what else).

From redis's page:
[http://redis.io/topics/persistence](http://redis.io/topics/persistence)

"RDB needs to fork() often in order to persist on disk using a child process.
Fork() can be time consuming if the dataset is big, and may result in Redis to
stop serving clients for some millisecond or even for one second if the
dataset is very big and the CPU performance not great. AOF also needs to
fork() but you can tune how often you want to rewrite your logs without any
trade-off on durability"

------
cturner
As cool as this is, a remaining problem I'd have for using Windows is that
I've found git to be slow there. For example, the responsiveness of 'git
status'. I'd guess this is something to do with NTFS being optimised for
things different than unix-tradition filesystems. If so, this tool wouldn't
improve that. Does anyone know more about this area?

~~~
babuskov
Git is built for Linux and relies on some features of Linux filesystems for
speed. As long as underlying filesystem is NTFS, there's no way to speed up
Git.

Although, the "Support NTFS native hardlinks and emulated symbolic links"
could be relevant if it does some magic there.

~~~
eps
> Git [...] relies on some features of Linux filesystems for speed.

Modern NTFS versions support all the things that git needs, so it has less to
do with having magical features in Linux filesystems per se and more with the
fact that they aren't properly mapped onto respective NTFS features in the
abstraction layer (MSYS or similar).

------
tlb
I really want Linux emulation for OSX, which should be much easier. FreeBSD
had very usable Linux emulation on a similar kernel.

------
sgt
Cmd.exe is an abomination though - and Cygwin defaults to using it for
terminal use. I see that this project also does that.

~~~
rossy
> Cmd.exe is an abomination though

Agreed, but I don't think Cygwin defaults to it any more. It uses mintty now,
which understands Cygwin ptys and has a native Windows interface.

I guess you could also use an X11 terminal emulator in this project.

~~~
sspiff
Correct. Cygwin has used mintty as a default since 2011[1].

[1]: [http://cygwin.com/ml/cygwin-
announce/2011-11/msg00040.html](http://cygwin.com/ml/cygwin-
announce/2011-11/msg00040.html)

------
neiesc
I am getting error when using go

[root@ForeignLinux ~]# gccgo hello.go -o test /tmp/cc06PbMI.o: file not
recognized: File truncated collect2: error: ld returned 1 exit status

[https://wiki.archlinux.org/index.php/Go](https://wiki.archlinux.org/index.php/Go)

anyone experienced this?

------
shiggerino
I don't understand what this is supposed to accomplish. What's the advantage
of building on GNU/Linux and running on Windows compared to building on
Windows and running on Windows? Seems like it's needlessly complicating things
making a binary compatibility layer.

~~~
kyberias
It's trying to accomplish exactly the same as Wine, only vice versa.

There is a considerable amount of software written and compiled for Linux that
is not available on Windows.

------
heywire
Unfortunately seems to crash immediately on Windows 10 Tech Preview (build
9926). It's what I can expect for using a prerelease OS though.

Edit: It looks like this might have been something on my end. Re-downloaded
and extracted and it seems to be working now.

------
deevus
Personally I have been using Scoop with ConEmu. I find that is enough for most
things :)

[http://scoop.sh/](http://scoop.sh/)

[http://www.fosshub.com/ConEmu.html](http://www.fosshub.com/ConEmu.html)

~~~
stuaxo
Is Scoop better than Chocolatey? I like chocolatey, but things dont install
semi-regularly.

~~~
deevus
I prefer it over Chocolately, however Scoop is mainly aimed at developer tools
on the command line. Scoop is more a replacement for Cygwin.

Disclaimer: I'm a Scoop contributor.

------
alisnic
this is the exact opposite of WINE, implements linux sys calls in windows

------
justincormack
Midipix is due soon and provides a system call interface for Windows and a
Linux libc.[http://midipix.org/](http://midipix.org/)

------
gtwy
Does this support running X over SSH? The biggest drawback for me with Windows
boxes was always a lack of X support for applications I want to run on remote
servers.

~~~
fizgig
Yes. From the stock bash prompt, run "startxwin". With the resulting xterm,
you can launch any X apps within Cygwin, or you can SSH in (with appropriate
flags and xauth config, etc.) and blow back X apps from the remote Unix box.
It's really nice.

------
ericfontaine
interestingly I wasn't able to run vi, but could run vim. I reported to the
github issue tracker.

This seems very neat. Definitely much less overhead than VirtualBox. Plus can
write to the same filesystem as windows without windows admin privileges
(which can be done with cygwin, but not with virtualbox). Once it supports
x86-64 binaries and threading and users, this could be very useful.

------
bane
So this is the opposite of Wine for Windows?

------
jkot
Cool. CoLinux does something similar

~~~
elcct
I thought it's been dead for ages

~~~
derekp7
This is one of the things that's always driven me nuts on Linux, and also one
of the things I really like. Some projects that are interesting like this seem
to disappear for a while, but often the concept will be resurrected under a
new project. CoLinux is one of them, UserFS (now FUSE) is another one that
went away for a couple kernel versions and is now back. I'm still waiting for
an SSI (single system image) to make a comeback though (Mosix, OpenMosix,
OpenSSI, but none of them work with newer kernel versions).

------
shmerl
That's like Wine in reverse?

------
vander_elst
very nice project! I hope it takes off running applications on cygwin can be a
pain

