Last active
September 30, 2020 18:36
-
-
Save exelix11/c01077e94d9d0d4e7df1e7835fc77150 to your computer and use it in GitHub Desktop.
Wsl scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[automount] | |
enabled=false | |
[interop] | |
enabled=false | |
appendWindowsPath=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
May want to fix the locales warning