LoginSignup
0
0

More than 1 year has passed since last update.

WSLで構築した環境をエクスポートして共有する

Last updated at Posted at 2022-07-28

やりたいこと

WSL2を使って構築した環境を他の人に共有する

作ってエクスポートまで

  1. 元となるディストリビューションをインストール
    wsl --install -d Ubuntu
    
  2. そのディストリビューションでセットアップする
  3. 作り終わったディストリビューションを停止
    wsl -t Ubuntu
    
  4. 適当なディレクトリにエクスポートする
    wsl --export Ubuntu  c:\tmp\ubuntu.tar
    
  5. 作成したtarファイルを共有したい相手に渡す

使う側の作業

  1. WSLの有効化をしておく
    https://docs.microsoft.com/ja-jp/windows/wsl/install-manual
  2. wslconfigも準備する(必要に応じて)
    %USERPROFILE%\.wslconfig
    [wsl2]
    kernelCommandLine=vsyscall=emulate
    
  3. 使いたい端末で受け取ったtarファイルをインポート
    wsl --import My-Ubuntu c:\wsl\My-Ubuntu\ c:\Download\ubuntu.tar
    
  4. ユーザ名を変更する(必要に応じて)
    wsl -u root -d Ubuntu
    
    usermod -l 変更後のユーザ名 変更前のユーザ名
    groupmod -n 変更後のユーザ名 変更前のユーザ名
    usermod -d /home/変更後のユーザ名 -m 変更後のユーザ名
    exit
    
  5. デフォルトユーザを変更する:powershell(必要に応じて)
    # 一時的にfunction定義
    Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); };
    
    # 定義したfunctionを実行する
    WSL-SetDefaultUser Ubuntu ユーザ名
    exit
    
  6. これで、Windowsターミナルに追加されてるUbuntuで操作できる
    あとは追加でパスワードも変更するなり良しなに
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0