LoginSignup
0
2

More than 3 years have passed since last update.

Windows Subsystem for Linux の 導入をなるべく自動化で頑張るためのメモ Ver 20200209

Last updated at Posted at 2020-02-09

※ 自動化に関する情報は大募集中なのでコメントに書いてもらえると嬉しかったりはします

これは何

  • Windows Subsystem for Linux(以下WSL) がWindows10に導入されてから年月が立ちますが、割とGUIの操作や手動でやらないといけない操作が多く、導入が割と面倒だったりします。
  • とはいえWSL関連の記事を色々集めると、実は殆どの動作はCLIベースで実行可能で、自動化が可能な所まで来てたりもします。
  • この記事はWSLの導入に関して、どこまでCLIベースで実行可能か、というのを残すメモです。
  • 面倒になって、記事へのリンクで済ませるところ多数になるかもしれませんがご容赦を。内容が大きくなったら別記事化するかもしれません。(日本語化の仕方とかは各ディストリで結構違ったりするので…)

WSL導入のための各ステップに対するCLIコマンドとか

開発者モードへの移行

  • technetにどうやらpowershell用のスクリプトがあるようです。
  • 中身はレジストリを弄るようで、単独でpowershell上で実行してもいいのでは、という気はしなくはないです(未確認)。
  • 実際は下記のようなコマンド。おそらく管理者が必要かと(未確認)
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"

WSL の 有効化

  • 実は公式Docsにあります。
  • 管理者でPowrshellコンソールを開き、下記コマンドを実行。
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  • 有効化後 PCの再起動が必要です。

ディストリビューションのダウンロード

  • MicroSoftStore経由の方が手順が少なくて便利ですが、まあ、GUIなので・・・
  • Qiita内で纏めてる人もいますがPowershell上で 手動DL + インストールで実行可能です。MSの記事にも書かれています
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu -OutFile Ubuntu.appx -UseBasicParsing

Add-AppxPackage .\wsl-ubuntu.appx

WSL 初期導入設定(初期ユーザ+passwordとか)

> ubuntu.exe --help
Launches or configures a Linux distribution.

Usage:
    <no args>
        Launches the user's default shell in the user's home directory.

    install [--root]
        Install the distribuiton and do not launch the shell when complete.
          --root
              Do not create a user account and leave the default user set to root.

    run <command line>
        Run the provided command line in the current working directory. If no
        command line is provided, the default shell is launched.

    config [setting [value]]
        Configure settings for this distribution.
        Settings:
          --default-user <username>
              Sets the default user to <username>. This must be an existing user.

    help
        Print usage information.

初期導入:non pass sudo 設定

  • 割とここは共通で行ける
  • 自分の記事から手順を引っ張ってきます。ちなみに前項目のWSL初期設定上でのパスワードはばれてOKです。理由は ここの手順でそのパスワードを消去する ので、パスワードログインを無効化するので…
sudo bash -c "echo \"[デフォルトユーザ名] ALL=(root) NOPASSWD: ALL\" >> /etc/sudoers.d/nonpass_sudo"

sudo chmod 0440 /etc/sudoers.d/nonpass_sudo
sudo visudo -c

sudo passwd -d [デフォルトユーザ名]

日本語化

  • ここはディストリビューションによって大きく変わるので個別掲載予定
  • ubuntu系、debian系、kali-linuxで大きく違ってたりします。

参考資料

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2