LoginSignup
2
3

More than 3 years have passed since last update.

WSL2

Last updated at Posted at 2020-12-08

インストール

WSLの設定

.wslconfig
# 外部から接続許可
localhostForwarding=True

[wsl2]
memory=2GB

Windows の機能の有効化または無効化

  • PowerShell 起動 (管理者として実行)
# WSLの有効化 (wslコマンドに必要)
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Virtual Machine Platform の有効化
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all
Hyper-V
# WSL2を入れたらVirtualBoxのゲストOSが途中でフリーズする場合は、Hyper-VをOFFにするとWSL1で利用ができる。

# Hyper-V をインストール (wsl2に必要)
dism.exe /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V

# OFFにする (OS再起動が必要。Virtualboxが起動しない場合はこちら。)
bcdedit /set hypervisorlaunchtype off

# ONにする
bcdedit /set hypervisorlaunchtype auto

x64 マシン用 WSL2 Linux カーネル更新プログラム パッケージ

WSL2を使用

wsl --set-default-version 2

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

ubuntu.PNG


利用

起動方法

rem Ubuntu-20.04 をデフォルト指定
wsl -s Ubuntu-20.04

rem 起動
wsl

ファイル

  • windowsからアクセス
    • \\wsl$
  • Linuxからアクセス
    • /mnt/c

日本語

sudo -s

# ロケール
apt install -y locales
sudo locale-gen ja_JP.UTF-8
update-locale LANG=ja_JP.UTF-8
  • WSL2を再度起動し、日本語になったことを確認。

dockerのインストール

docker-install.sh
apt remove -y \
  docker \
  docker-engine \
  docker.io \
  containerd \
  runc

apt install -y \
 apt-transport-https \
 ca-certificates  \
 curl \
 gnupg-agent \
 software-properties-common \
 iptables

update-alternatives --set iptables /usr/sbin/iptables-legacy
/sbin/iptables --version

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) \
 stable"

apt update
apt install -y \
 docker-ce \
 docker-ce-cli \
 containerd.io \
 docker-compose

service docker start
docker ps -a
docker run --rm hello-world

エクスポート/インポート

# 一覧
wsl --list

# 停止 ( .wslconfig を変更した後は都度必要。 )
wsl --shutdown Ubuntu-20.04

# export
wsl --export Ubuntu-20.04 Ubuntu.tar

# 登録の削除
wsl --unregister Ubuntu-20.04

# インポート
wsl --import Ubuntu-20.04 Ubuntu.tar
2
3
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
2
3