WSL+Rocky9セットアップ » 履歴 » バージョン 4
開発 次郎, 2025/05/06 01:58
| 1 | 1 | 開発 次郎 | h1. WSL+Rocky9セットアップ |
|---|---|---|---|
| 2 | |||
| 3 | |||
| 4 | h2. WSLにRocky9を追加する |
||
| 5 | |||
| 6 | h3. Rocky9イメージをダウンロードする |
||
| 7 | |||
| 8 | https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-Container-Base.latest.x86_64.tar.xz |
||
| 9 | |||
| 10 | * (出典) |
||
| 11 | ** https://blog.yamk.net/posts/20250125-wsl2-rocky9/ |
||
| 12 | |||
| 13 | h3. WSLにRocky9を追加する |
||
| 14 | |||
| 15 | イメージ保存先は任意のディレクトリ。%WSL_IMAGES%とする。 |
||
| 16 | |||
| 17 | <pre><code class="bash"> |
||
| 18 | # 配置先フォルダ作成 |
||
| 19 | mkdir %WSL_IMAGES% |
||
| 20 | # WSL2にインポート (tar.xz は展開不要) |
||
| 21 | wsl --import "Rocky9" %WSL_IMAGES%\Rocky9 Rocky-9-Container-Base.latest.x86_64.tar.xz --version 2 |
||
| 22 | </code></pre> |
||
| 23 | 2 | 開発 次郎 | |
| 24 | WSL2にインストールされているか確認する |
||
| 25 | |||
| 26 | <pre><code class="powershell"> |
||
| 27 | PS C:\> wsl -l -v |
||
| 28 | NAME STATE VERSION |
||
| 29 | * RockyLinux9 Stopped 2 |
||
| 30 | </code></pre> |
||
| 31 | |||
| 32 | 3 | 開発 次郎 | h3. 起動してrootのパスワードを設定する |
| 33 | 2 | 開発 次郎 | |
| 34 | 1 | 開発 次郎 | <pre><code class="powershell"> |
| 35 | 3 | 開発 次郎 | PS C:\> wsl -d Rocky9 |
| 36 | root@DESKTOP-F5MH7I8 wsl]# passwd |
||
| 37 | Changing password for user root. |
||
| 38 | New password: |
||
| 39 | BAD PASSWORD: The password contains the user name in some form |
||
| 40 | Retype new password: |
||
| 41 | passwd: all authentication tokens updated successfully. |
||
| 42 | [root@DESKTOP-F5MH7I8 wsl]# exit |
||
| 43 | logout |
||
| 44 | 2 | 開発 次郎 | PS C:\> wsl --shutdown |
| 45 | PS C:\> wsl -l -v |
||
| 46 | NAME STATE VERSION |
||
| 47 | 1 | 開発 次郎 | * Ubuntu Stopped 2 |
| 48 | Rocky9 Stopped 2 |
||
| 49 | CentOS7 Stopped 2 |
||
| 50 | 3 | 開発 次郎 | </code></pre> |
| 51 | |||
| 52 | h3. 通常使用ユーザをsudoユーザとして登録する |
||
| 53 | |||
| 54 | <pre><code class="powershell"> |
||
| 55 | [root@DESKTOP-F5MH7I8 ~]# myUsername=devel |
||
| 56 | [root@DESKTOP-F5MH7I8 ~]# adduser -G wheel $myUsername |
||
| 57 | [root@DESKTOP-F5MH7I8 ~]# echo -e "[user]\ndefault=$myUsername" >> /etc/wsl.conf |
||
| 58 | [root@DESKTOP-F5MH7I8 ~]# passwd $myUsername |
||
| 59 | Changing password for user devel. |
||
| 60 | New password: |
||
| 61 | BAD PASSWORD: The password is shorter than 8 characters |
||
| 62 | Retype new password: |
||
| 63 | passwd: all authentication tokens updated successfully. |
||
| 64 | </code></pre> |
||
| 65 | |||
| 66 | h3. WSL2に割り当てるメモリを設定する |
||
| 67 | |||
| 68 | <pre><code class="powershell"> |
||
| 69 | PS C:\> @' |
||
| 70 | [wsl2] |
||
| 71 | memory=4GB |
||
| 72 | swap=0 |
||
| 73 | '@ > ${Env:USERPROFILE}/.wslconfig |
||
| 74 | </code></pre> |
||
| 75 | |||
| 76 | 4 | 開発 次郎 | h3. systemdを有効にする(有効にならない?5/6) |
| 77 | 3 | 開発 次郎 | |
| 78 | <pre><code class="powershell"> |
||
| 79 | PS C:\> wsl -d Rocky9 |
||
| 80 | </code></pre> |
||
| 81 | |||
| 82 | <pre><code class="bash"> |
||
| 83 | cat <<'__EOT__' > /etc/wsl.conf |
||
| 84 | # See: https://learn.microsoft.com/en-us/windows/wsl/wsl-config |
||
| 85 | [boot] |
||
| 86 | 1 | 開発 次郎 | systemd=true |
| 87 | 4 | 開発 次郎 | [user] |
| 88 | default=devel |
||
| 89 | 3 | 開発 次郎 | __EOT__ |
| 90 | </code></pre> |
||
| 91 | |||
| 92 | WSLを再起動する |
||
| 93 | |||
| 94 | <pre><code class="powershell"> |
||
| 95 | PS C:\> wsl --shutdown |
||
| 96 | PS C:\> wsl -d RockyLinux9 |
||
| 97 | </code></pre> |
||
| 98 | |||
| 99 | なぜなpsコマンドがインストールされていないのでインストールする |
||
| 100 | 1 | 開発 次郎 | |
| 101 | <pre><code class="bash"> |
||
| 102 | 4 | 開発 次郎 | $ sudo dnf install procps-ng |
| 103 | $ ps auxw | grep systemd |
||
| 104 | </code></pre> |
||
| 105 | |||
| 106 | h3. 各種パッケージをインストールしておく |
||
| 107 | |||
| 108 | <pre><code class="bash"> |
||
| 109 | # 不足パッケージを導入 |
||
| 110 | dnf install -y procps-ng coreutils-common dnf-plugins-core bash-completion net-tools zip unzip bzip2 xz zstd openssh-clients telnet perl |
||
| 111 | # エディタはお好みで |
||
| 112 | dnf install -y vim-enhanced |
||
| 113 | # EPEL レポジトリの追加 |
||
| 114 | dnf config-manager --set-enabled crb |
||
| 115 | dnf install -y \ |
||
| 116 | https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \ |
||
| 117 | https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm |
||
| 118 | # EPEL 由来ツール追加 |
||
| 119 | dnf install -y htop whois bind-utils wireshark-cli tcpdump traceroute nc dhcping fping |
||
| 120 | 2 | 開発 次郎 | </code></pre> |