一応 windows/WSL2 にてUbuntuを動かしてみたけど、使い慣れているCentOSで構築したい.
参照先 https://www.geekfeed.co.jp/geekblog/install_CentOS8_on_wsl2_for_free
https://github.com/yuk7/CentWSL
CentOS7 †
参照先はCentOS8ですが、ここではCentOS7で試してみます。
CentWSL
からCentOS7のリリースファイルを取得します。
https://github.com/yuk7/CentWSL/releases
から「7.0.1907.3
」の「CentOS7.zip(350MB)」を取得
「CentOS7.zip」を展開して、中にある「rootfs.tar.gz」を解凍して「rootfs.tar」にする。これを適当な場所に配置して
下記コマンドを実行する
PS C:\Users\supervisor> wsl --import CentOS7 "C:\Users\supervisor\AppData\Local\Packages\CentOS7" "C:\Users\supervisor\Desktop\rootfs.tar" --version 2
PS C:\Users\supervisor> wsl.exe --list -v
NAME STATE VERSION
* CentOS7 Stopped 2
PS C:\Users\supervisor>
コマンドプロンプト(cmd)から「wsl」コマンドでログインします。
C:\Users\supervisor>wsl -d CentOS7
[root@f supervisor]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@f supervisor]# id
uid=0(root) gid=0(root) groups=0(root)
[root@f supervisor]#
パスワードなしで直接CentOS7にログインできます。
っで、cudaを入れる。nvidia様から取得したcudaライブラリファイルをwindows10PCの「\\wsl\CentOS7\tmp」に配置すると/tmpから参照できます。
[root@f supervisor]# cd /tmp
[root@f tmp]# yum localinstall ./cuda-repo-rhel7-8-0-local-ga2-8.0.61-1.x86_64.rpm
[root@f tmp]# yum install cuda-toolkit-8-0 **cuda-8-0ではない**
これでOK
Gautomatchを実行したら計算が完了しました
アカウント修正 †
そのままだとrootになってしまう。一応このままでも構わないが
できれば一般ユーザでログインしてsudoでroot権限を行使したい. なので
[root@f supervisor]# groupadd em
[root@f supervisor]# useradd -m -g em -G wheel saber
[root@f supervisor]# id saber
uid=1000(saber) gid=1000(em) groups=1000(em),10(wheel)
[root@f supervisor]# passwd saber <--パスワードも定義します. あるいはvisudoでwheelをNOPASSWDにするとか
Changing password for user saber.
New password:
Retype new password:
[root@f supervisor]# exit
として通常使用するアカウントを用意します。*ここでグループ「wheel」に加えてsudoできるようにします
そして、コマンドプロンプトから「wsl」コマンドで「-u」でユーザを指定してログインします。
C:\Users\supervisor>wsl -d CentOS7 -u saber
[saber@f supervisor]$ id
uid=1000(saber) gid=1000(em) groups=1000(em),10(wheel)
[saber@f supervisor]$ pwd
/mnt/c/Users/supervisor
[saber@f supervisor]$
ssh接続 †
現状のままは、wsl2なCentOS7にログインできてcuda計算ができる...っがそれはコマンドラインでしかない.
ホストなwindows10PCからこのwsl2なCentOS7にログインして、Xアプリケーションを立ち上げるためには、
なのでその設定を行う. まず wsl2なCentOS7 にログインして「yum install openssh-server」を実行します
[コマンドプロンプト]
C:\Users\supervisor>wsl -d CentOS7 -u saber
[saber@f supervisor]$ sudo yum install openssh-server
wslはsystemdに対応していないようで sshd を起動させると
[saber@f ~]$ sudo systemctl start sshd
Failed to get D-Bus connection: Operation not permitted
[saber@f ~]$
と言われる。この回避策がhttps://github.com/yuk7/CentWSL/issues/11
に載っている
mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl
これでsystemctl は使えそうだが、事前にcentos7のキーを手動で作成する必要があるみたい
[saber@f ~]$ sudo ssh-keygen -A
ssh-keygen: generating new host keys: RSA1 RSA DSA ECDSA ED25519
[saber@f ~]$ sudo systemctl start sshd
[saber@f ~]$ ps -ef |grep ssh
root 257 94 0 01:16 ? 00:00:00 /usr/sbin/sshd -D
saber 259 95 0 01:16 pts/0 00:00:00 grep --color=auto ssh
[saber@f ~]$
このwsl2なCentOS7は「ifconfig」の値から「172.29.193.125」のアドレスを有している。
ホストのwindows10PCからはこのアドレスめがけてTeraTermらでアクセス可能であるが、windows10PC以外から
アクセスさせるには netsh コマンドを使ってポートフォワードの設定が必要です. 参照 router/windows#pe178b02
CentOS8 †
今後メインで使うのでCentOS8でも作ってみる.
https://github.com/yuk7/CentWSL/releases
から8.1.1911.1 for Insider only
の「CentOS8.zip(70.2MB)」を取得
「CentOS8.zip」を展開して、中にある「rootfs.tar.gz」を解凍して「rootfs.tar」にする。
これを適当な場所に配置してPowerShellを起動して、その中で下記コマンドを実行する
[PowerShell]
PS C:\Users\supervisor> wsl --import CentOS8 "C:\Users\supervisor\AppData\Local\Packages\CentOS8" "C:\Users\supervisor\Desktop\rootfs.tar" --version 2
PS C:\Users\supervisor> wsl.exe --list -v
NAME STATE VERSION
* CentOS7 Running 2
CentOS8 Stopped 2
PS C:\Users\supervisor>
次にコマンドプロンプト(cmd)を起動してそこから「wsl」コマンドでログインします。
[コマンドプロンプト]
C:\Users\supervisor>wsl -d CentOS8
[root@f supervisor]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
[root@f supervisor]# id
uid=0(root) gid=0(root) groups=0(root)
[root@f supervisor]#
WSLの停止 †
コマンドプロンプト/PowerShellにて
C:\Users\supervisor>wsl -l -v
NAME STATE VERSION
* CentOS7 Stopped 2
CentOS8 Running 2
C:\Users\supervisor>wsl -t CentOS8
C:\Users\supervisor>wsl -l -v
NAME STATE VERSION
* CentOS7 Stopped 2
CentOS8 Stopped 2
C:\Users\supervisor>
で停止できる