Windows 2025
Sponsored Link

Windows Subsystem for Linux2025/01/16

 

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> wsl --update 
Downloading: Windows Subsystem for Linux 2.3.26
Installing: Windows Subsystem for Linux 2.3.26
Windows Subsystem for Linux 2.3.26 has been installed.
The operation completed successfully.
Checking for updates.
The most recent version of Windows Subsystem for Linux is already installed.

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
Ubuntu-18.04                    Ubuntu 18.04 LTS
Ubuntu-20.04                    Ubuntu 20.04 LTS
Ubuntu-22.04                    Ubuntu 22.04 LTS
Ubuntu-24.04                    Ubuntu 24.04 LTS
OracleLinux_7_9                 Oracle Linux 7.9
OracleLinux_8_7                 Oracle Linux 8.7
OracleLinux_9_1                 Oracle Linux 9.1
openSUSE-Leap-15.6              openSUSE Leap 15.6
SUSE-Linux-Enterprise-15-SP5    SUSE Linux Enterprise 15 SP5
SUSE-Linux-Enterprise-15-SP6    SUSE Linux Enterprise 15 SP6
openSUSE-Tumbleweed             openSUSE Tumbleweed

# 例として Ubuntu 24.04 をインストール
PS C:\Users\Administrator> wsl --install Ubuntu-24.04 
Downloading: Ubuntu 24.04 LTS
Installing: Ubuntu 24.04 LTS
Ubuntu 24.04 LTS has been installed.
Launching Ubuntu 24.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: serverworld   # デフォルトユーザーを設定 (任意の名前で 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 24.04 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)

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

 System information as of Wed Jan 15 18:38:09 PST 2025

  System load:  0.81                Processes:             43
  Usage of /:   0.1% of 1006.85GB   Users logged in:       0
  Memory usage: 5%                  IPv4 address for eth0: 172.18.176.117
  Swap usage:   0%


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

# Windows 側のリソースは [/mnt/c] にマウントされアクセス可能
serverworld@rx-7:~$ df -h 
Filesystem      Size  Used Avail Use% Mounted on
none            3.9G     0  3.9G   0% /usr/lib/modules/5.15.167.4-microsoft-standard-WSL2
none            3.9G  4.0K  3.9G   1% /mnt/wsl
drivers          80G   16G   64G  21% /usr/lib/wsl/drivers
/dev/sdc       1007G  1.2G  955G   1% /
none            3.9G   72K  3.9G   1% /mnt/wslg
none            3.9G     0  3.9G   0% /usr/lib/wsl/lib
rootfs          3.9G  2.2M  3.9G   1% /init
none            3.9G  496K  3.9G   1% /run
none            3.9G     0  3.9G   0% /run/lock
none            3.9G     0  3.9G   0% /run/shm
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
none            3.9G   76K  3.9G   1% /mnt/wslg/versions.txt
none            3.9G   76K  3.9G   1% /mnt/wslg/doc
C:\              80G   16G   64G  21% /mnt/c
D:\             160G  644M  160G   1% /mnt/d
tmpfs           794M   16K  794M   1% /run/user/1002

serverworld@rx-7:~$ sudo ls -l /mnt/c/Users 
total 0
drwxrwxrwx 1 serverworld serverworld 512 Jan 15 18:23  Administrator
lrwxrwxrwx 1 serverworld serverworld  18 Apr  1  2024 'All Users' -> /mnt/c/ProgramData
drwxrwxrwx 1 serverworld serverworld 512 Dec 11 10:28  Default
lrwxrwxrwx 1 serverworld serverworld  20 Apr  1  2024 'Default User' -> /mnt/c/Users/Default
drwxrwxrwx 1 serverworld serverworld 512 Dec 10 17:29  Public
-rwxrwxrwx 1 serverworld serverworld 174 Apr  1  2024  desktop.ini

# Linux 側の root 権限が必要なリソースへは、設定したデフォルトユーザーで [$ sudo (command)] でアクセス可能
serverworld@rx-7:~$ sudo ls -la /root 
total 24
drwx------  4 root root 4096 Jan 15 18:37 .
drwxr-xr-x 22 root root 4096 Jan 15 18:43 ..
-rw-r--r--  1 root root 3106 Apr 22  2024 .bashrc
drwx------  2 root root 4096 Jan 15 18:37 .cache
-rw-r--r--  1 root root    0 Jan 15 18:37 .motd_shown
-rw-r--r--  1 root root  161 Apr 22  2024 .profile
drwx------  2 root root 4096 Jan 15 18:37 .ssh

# 終了する場合は exit
serverworld@rx-7:~$ exit 
logout

# 再実行する場合は以下
PS C:\Users\Administrator> wsl -d Ubuntu-24.04 
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
serverworld@rx-7:/mnt/c/Users/Administrator$
関連コンテンツ