単にWindowsでBashが動くようになるという話ではない

すでに各所で話題になっていますが、Microsoftが現在開催中の開発者向けカンファレンス「Build 2016」において、Windows 10でBashを正式にネイティブサポートすることを発表しました。
[速報]マイクロソフト、BashシェルをWindowsに搭載。Emacs、VT100などサポート。Build 2016 - Publickey
Windows 10がBashに公式ネイティブ対応。マイクロソフトとカノニカルが協力、Ubuntu Linuxのコマンドラインツールがそのまま動作 - Engadget Japanese

Bashが動く」と言っても、どうやら単純にBashを仮想環境で動かしたり、Bashと同じ動作をする独自のツールを開発したというわけではないようです。単にBashが動くだけであれば、古くからCygwinとかが普及しているのでそれほど驚くことではないですね。

Windows NTはもともと内部的にサブシステムの仕組みで動作しています。今回MSがやったのは、このサブシステムの仕組みを使って、ユーザランドUbuntu LinuxをNTカーネル上に実装したということのようです。「Windows Subsystem for Linux」と呼ばれているのがそれです。

つまり、「Bashが動く」ではなく、「ユーザランドUbuntuがネイティブで動く」というのが正しい表現と言えます。これは/bin/bashとその周辺のコマンドはもとより、aptやsshawkといった様々なLinuxコマンドがそのまま使えるということで、かなり強力な仕組みです。

この辺りについては、今回の開発に協力したCanonicalのチームメンバーであるDustin Kirkland氏のブログに少し紹介されています。
From the Canyon Edge: Ubuntu on Windows -- The Ubuntu Userspace for Windows Developers

"So maybe something like a Linux emulator?" Now you're getting warmer! A team of sharp developers at Microsoft has been hard at work adapting some Microsoft research technology to basically perform real time translation of Linux syscalls into Windows OS syscalls. 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". (No, it's not open source at this time.)

LinuxシステムコールをリアルタイムにWindowsシステムコールに変換して処理することで、Ubuntuのバイナリをそのまま(再コンパイルなどすることなく)動作させているそうです。BashシェルからWindowsファイルシステムにアクセスすることも可能だそうです。

f:id:zinbe:20160331122233p:plain

また同氏によれば、まだ完全ではないものの、LTP(Linux Test Project)のほとんどのテストはパスできているとのことです。

The vast majority of the LTP passes and works well. But there are some imperfections still, especially around tty's an the vt100. My beloved byobu, screen, and tmux don't quite work yet, but they're getting close!

Build 2016のライブ配信チャンネルでは、実際にいろいろなバイナリが動いている様子が公開されています。
Running Bash on Ubuntu on Windows! | Build 2016 | Channel 9

gccコンパイルしたり、sshでリモートログインしたり、aptでgitをインストールしたりしてます。WindowsVisual Studio CodeでRubyスクリプト修正して、それをLinuxサブシステム上で走らせたりもしてます。