事前準備
J:\WSL2\Ubuntu-24.04>wsl.exe --list --online
インストールできる有効なディストリビューションの一覧を次に示します。
'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.5 openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed openSUSE Tumbleweed
- インストールオプションではインストール先を指定できないようなので、一旦所定の場所にインストールしてからエクスポートしてインポートするという手順を取ることになりそう。実際には、シャットダウン -> ext4.vhdxをコピー、wslコマンドでディストリビューションを削除 -> wslコマンドでディストリビューションを登録でなんとかなりそうな気がする。
--install [ディストリビューション] [オプション...]
Linux 用 Windows サブシステム ディストリビューションをインストールします。
有効なディストリビューションの一覧を確認するには、'wsl.exe --list --online' を使用します。
オプション:
--no-launch, -n
インストール後にディストリビューションを起動しません。
--web-download
Microsoft Store ではなくインターネットからディストリビューションをダウンロードします。
--no-distribution
必要なオプションのコンポーネントのみをインストールし、ディストリビューションをインストールしません。
--enable-wsl1
WSL1 サポートを有効にします。
手順
J:\WSL2>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-22.04 Stopped 2
- wsl.exe --unregister Ubuntu-22.04
J:\WSL2>wsl.exe --unregister Ubuntu-22.04
登録解除。
この操作を正しく終了しました。
Ubuntu 24.04をインストールする
- wsl.exe --install Ubuntu-24.04 --no-launch
J:\WSL2>wsl.exe --install Ubuntu-24.04 --no-launch
インストール中: Ubuntu 24.04 LTS
Ubuntu 24.04 LTS がインストールされました。
この操作を正しく終了しました。
Ubuntu 24.04の初期設定をする
- 設定 -> アプリ -> Ubuntu 24.04をクリックして起動
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: #######
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.153.1-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Sun Jun 16 13:48:11 JST 2024
System load: 0.26 Processes: 59
Usage of /: 0.1% of 1006.85GB Users logged in: 0
Memory usage: 1% IPv4 address for eth0: 172.31.123.91
Swap usage: 0%
This message is shown once a day. To disable it please create the
/home/#######/.hushlogin file.
#######@5950X:~$
J:\WSL2>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-24.04 Running 2
Ubuntu 24.04をエクスポートする
- wsl.exe --shutdown
- wsl.exe --export Ubuntu-24.04 E:\\20240616-Ubuntu-24.04.tar
J:\WSL2>wsl.exe --shutdown
J:\WSL2>wsl.exe --export Ubuntu-24.04 E:\<PATH>\20240616-Ubuntu-24.04.tar
エクスポートが進行中です。これには数分かかる場合があります。
この操作を正しく終了しました。
Ubuntu 24.04をインポートする
J:\WSL2>mkdir Ubuntu-24.04
J:\WSL2>wsl.exe --import Ubuntu-24.04 J:\WSL2\Ubuntu-24.04 E:\<PATH>\20240616-Ubuntu-24.04.tar
インポート中です。この処理には数分かかることがあります。
この操作を正しく終了しました。
J:\WSL2>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-24.04 Stopped 2
J:\WSL2>wsl -u #######
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
#######@5950X:/mnt/j/WSL2$ exit
logout
J:\WSL2>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-24.04 Running 2
初期設定
システムを最新にする
- sudo apt update
- sudo apt upgrade
/etc/wsl.confの設定
[boot]
systemd=true
[automount]
enabled= true
root= /mnt/
options= "metadata,umask=22,fmask=11"
mountFsTab= false
# Enable DNS – even though these are turned on by default, we'll specify here just to be explicit.
# [network]
# # generateHosts= true
# # generateResolvConf= true
$ touch .fetchids
$ touch .fetchmailrc
$ chmod 700 .fetch*
$ ls -la .fetch*
-rwx------ 1 ####### ####### 0 Jun 16 14:43 .fetchids
-rwx------ 1 ####### ####### 0 Jun 16 14:43 .fetchmailrc
poll <mailserver>
protocol pop3
uidl
user <pop3 username>
pass <password>
keep
fetchsizelimit 0
no rewrite
no fetchall
no mimedecode
mda "/usr/bin/procmail"
ssl
$ touch .procmailrc
$ chmod 640 .procmailrc
$ ls -la .procmailrc
-rw-r----- 1 ####### ####### 225 Jun 16 14:48 .procmailrc
MAILDIR=$HOME/Mail
DEFAULT=$MAILDIR/
LOGFILE=$MAILDIR/log/`date +%Y%m%d.log`
LOCKFILE=$MAILDIR/.lockmail
FOLDER=`date +%Y%m`
:0 ic
* ? test ! -d inbox/$FOLDER
| mkdir inbox/$FOLDER
:0:
inbox/${FOLDER}/.
MAILDIR=/mnt/e/EFS/Winbin/WSL2/mail
$ sudo chown -R #######:####### /mnt/e/EFS/Winbin/WSL2
[sudo] password for #######:
mail.sh
#!/bin/sh
/usr/bin/date
/usr/bin/fetchmail --fetchmailrc /home/#######/.fetchmailrc -v
.bash_profile
/home/#######/mail.sh
cron/crontab
- wsl.exe -u root -- service cron start
- crontab
# m h dom mon dow command
* * * * * echo "Cron test at $(date +\%Y-\%m-\%d\ \%H:\%M:\%S)" >> /home/#######/crontest.txt 2>&1
59 8,23 * * * /home/#######/mail.sh >>/mnt/e/EFS/Winbin/WSL2/log/cron/`date +\%Y\%m\%d.log` 2>>/mnt/e/EFS/Winbin/WSL2/log/cron/error.log
バックアップ
Z:\>wsl.exe --export Ubuntu-24.04 E:\<PATH>\20240616-Ubuntu-24.04.tar
エクスポートが進行中です。これには数分かかる場合があります。
この操作を正しく終了しました。