Skip to content

Instantly share code, notes, and snippets.

@exelix11
Last active September 30, 2020 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exelix11/c01077e94d9d0d4e7df1e7835fc77150 to your computer and use it in GitHub Desktop.
Save exelix11/c01077e94d9d0d4e7df1e7835fc77150 to your computer and use it in GitHub Desktop.
Wsl scripts
[automount]
enabled=false
[interop]
enabled=false
appendWindowsPath=false
:: Create and initialize an Ubuntu WSL vm from a rootfs
:: The folder on disk weighs less than 300MB
:: Great for making test containers
@echo off
set BASE_URL=http://cdimage.ubuntu.com/ubuntu-base/releases/20.04.1/release/ubuntu-base-20.04-base-amd64.tar.gz
set USER_NAME=exelix
set USER_PASSWORD=exelix
set WSL_BASE_PATH=D:\WSL\
set VM_NAME=%1
set ROOTFS_SRC=%2
set WSL_DIR=%WSL_BASE_PATH%%VM_NAME%
if "%VM_NAME%"=="" (goto arg_fail)
if "%ROOTFS_SRC%"=="" (set ROOTFS_SRC=%BASE_URL%)
if exist %ROOTFS_SRC% goto install
:download
curl %ROOTFS_SRC% --output tmp.tar.gz || goto error_fail
set ROOTFS_SRC=tmp.tar.gz
:install
wsl --import %VM_NAME% %WSL_DIR% %ROOTFS_SRC% || goto error_fail
:setup
wsl -d %VM_NAME% -- adduser --disabled-password --gecos "" %USER_NAME%
wsl -d %VM_NAME% -- echo "%USER_NAME%:%USER_PASSWORD%"^|chpasswd
wsl -d %VM_NAME% -- usermod -aG sudo %USER_NAME%
:online_setup
wsl -d %VM_NAME% -- apt update
wsl -d %VM_NAME% -- apt install -y sudo nano
wsl -d %VM_NAME% -- apt-get install -y locales
wsl -d %VM_NAME% -- locale-gen "en_US.UTF-8"
wsl -d %VM_NAME% -- update-locale LC_ALL="en_US.UTF-8"
:done
echo Done !
echo Launch with
echo wsl -d %VM_NAME% -u %USER_NAME%
echo Set default user by editing HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss
goto :eof
:error_fail
pause
goto :eof
:arg_fail
echo Usage:
echo new-wsl VM_NAME ROOTFS_FILE_OR_URL
@exelix11
Copy link
Author

May want to fix the locales warning

apt-get install -y locales
locale-gen en_US.UTF-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment