Windows 2022
Sponsored Link

Windows Subsystem for Linux2022/12/27

 
Windows Subsystem for Linux (WSL) を有効化して Windows Server 上で Linux が利用できるようにします。
[1] PowerShell を管理者権限で起動してインストールします。
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

# VirtualMachinePlatform 有効化 (WSL 2 では必要)
PS C:\Users\Administrator> Enable-WindowsOptionalFeature -online -FeatureName VirtualMachinePlatform 
Do you want to restart the computer to complete this operation now?
[Y] Yes  [N] No  [?] Help (default is "Y"): N

Path          :
Online        : True
RestartNeeded : True

# WSL インストール (インストール後の問いに [Y] で要システム再起動)
PS C:\Users\Administrator> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 

Do you want to restart the computer to complete this operation now?
[Y] Yes  [N] No  [?] Help (default is "Y"): Y

Path          :
Online        : True
RestartNeeded : True


PS C:\Users\Administrator> curl.exe -L https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -o Microsoft.VCLibs.x64.14.00.Desktop.appx 
PS C:\Users\Administrator> Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx 
PS C:\Users\Administrator> wsl --update 
PS C:\Users\Administrator> wsl --status 
Default Version: 2

PS C:\Users\Administrator> wsl -l -o 
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.

NAME               FRIENDLY NAME
Ubuntu             Ubuntu
Debian             Debian GNU/Linux
kali-linux         Kali Linux Rolling
SLES-12            SUSE Linux Enterprise Server v12
SLES-15            SUSE Linux Enterprise Server v15
Ubuntu-18.04       Ubuntu 18.04 LTS
Ubuntu-20.04       Ubuntu 20.04 LTS
OracleLinux_8_5    Oracle Linux 8.5
OracleLinux_7_9    Oracle Linux 7.9

# 例として Ubuntu 20.04 をインストール
PS C:\Users\Administrator> wsl --install -d Ubuntu-20.04 
Downloading: Ubuntu 20.04 LTS
Installing: Ubuntu 20.04 LTS
Ubuntu 20.04 LTS has been installed.
Launching Ubuntu 20.04 LTS...

# 別ターミナルが起動する
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: ubuntu     # デフォルトユーザーを設定 (任意の名前で OK)
New password:                       # デフォルトユーザーのパスワードを設定
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.15.79.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Dec 27 02:14:28 PST 2022

  System load:  0.1                 Processes:             9
  Usage of /:   0.1% of 1006.85GB   Users logged in:       0
  Memory usage: 4%                  IPv4 address for eth0: 172.23.195.139
  Swap usage:   0%

0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This message is shown once once a day. To disable it please create the
/home/ubuntu/.hushlogin file.
ubuntu@rx-7:~$

# Windows 側のリソースは [/mnt/c] にマウントされアクセス可能
ubuntu@rx-7:~$ df -h 
Filesystem      Size  Used Avail Use% Mounted on
none            3.9G  4.0K  3.9G   1% /mnt/wsl
drivers         120G   21G  100G  18% /usr/lib/wsl/drivers
none            3.9G     0  3.9G   0% /usr/lib/wsl/lib
/dev/sdc       1007G  1.1G  955G   1% /
none            3.9G   72K  3.9G   1% /mnt/wslg
rootfs          3.9G  1.9M  3.9G   1% /init
none            3.9G     0  3.9G   0% /dev
none            3.9G     0  3.9G   0% /run
none            3.9G     0  3.9G   0% /run/lock
none            3.9G     0  3.9G   0% /run/shm
none            3.9G     0  3.9G   0% /run/user
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
none            3.9G   72K  3.9G   1% /mnt/wslg/versions.txt
none            3.9G   72K  3.9G   1% /mnt/wslg/doc
drvfsa          120G   21G  100G  18% /mnt/c
drvfsa           80G  5.4G   75G   7% /mnt/d

# Linux 側の root 権限が必要なリソースへは、設定したデフォルトユーザーで [$ sudo (command)] でアクセス可能
ubuntu@rx-7:~$ sudo ls -la /root 
[sudo] password for ubuntu:
total 16
drwx------  2 root root 4096 Apr 22  2020 .
drwxr-xr-x 19 root root 4096 Dec 27 02:14 ..
-rw-r--r--  1 root root 3106 Dec  5  2019 .bashrc
-rw-r--r--  1 root root  161 Dec  5  2019 .profile
関連コンテンツ