By default, WSL2 automatically terminates its virtual machine when all terminal sessions are closed or after being idle. To keep WSL running continuously in the background (for daemons, background services, Docker, or SSH), you can use the following methods.
Configure .wslconfig (Recommended)
In Windows, create or edit %USERPROFILE%\.wslconfig (usually C:\Users\<YourUsername>\.wslconfig):
1 2
[wsl2] vmIdleTimeout=-1
vmIdleTimeout=-1 sets the idle timeout to infinity, preventing WSL2 from shutting down automatically after closing terminal windows.
To apply the changes, restart WSL in PowerShell/CMD:
# Replaces "auth: password" with "auth: none" in the code-server config. sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml
1
sudo service code-server@$USER status
Local Client
1 2
set -x ssh -N -L 8080:127.0.0.1:8080 songzy@maomaosenlin.cc
Then, you can visit http://localhost:8080 in your local machine to access the code server started in remote machine.
Extensions
Some extensions are not avaliable in the default extension market, you might need to install them manually. Let us use the “C/C++” extension as an example.
The file downloaded by wget (or curl) cannot be installed directly since it is in a gzip format. So we need to first rename it with suffix .gz and then gunzip it:
Then, you can install the ms-vscode.cpptools-1.10.3@linux-x64.vsix either from commandline or search for the “Extensions: Install from VSIX” after typing “Shift-Command-P”.
Alternatives
vscode.dev: This is a lightweight vscode running in browser to manipulate local files.
GitHub Codespaces: This is not free, and has network connection issue (you know it) from time to time.
%PUBLIC% (not supported, not replaced by any value)
%SystemDrive%\Users\Public
%SystemDrive%
No
C:
C:
%SystemRoot%
No
The Windows directory, usually C:\Windows, formerly C:\WINNT
%SystemDrive%\Windows
%TEMP% and %TMP%
Yes
%SystemDrive%\Documents and Settings{username}\Local Settings\Temp
%SystemRoot%\TEMP (for system environment variables %TMP% and %TEMP%), %USERPROFILE%\AppData\Local\Temp (for user environment variables %TMP% and %TEMP%)
WSL 2 uses a Virtual Hard Disk (VHD) to store your Linux files. In WSL 2, a VHD is represented on your Windows hard drive as a .vhdx file. The WSL 2 VHD uses the ext4 file system. This VHD automatically resizes to meet your storage needs and has an initial maximum size of 256GB.
ncdu
1
du -h --max-depth=1 . | sort -h
or
1 2
sudo apt install ncdu ncdu
Then press ? for shortcuts.
“ncdu” stands for “NCurses Disk Usage”, where “NCurses” stands for “new curses”, where “curses” is a pun on the term “cursor optimization”, which is a library for TUI.
set ignorecase set hlsearch set encoding=utf-8 set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8 set cursorline set autoindent set smartindent set scrolloff=4 set showmatch set number
set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab set fileformat=unix
colorscheme desert
set nocompatible " required filetype off " required
" set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin()
" alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required Plugin 'gmarik/Vundle.vim'
" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin) Plugin 'Chiel92/vim-autoformat' nnoremap <F6> :Autoformat<CR> let g:autoformat_autoindent = 0 let g:autoformat_retab = 0 let g:autoformat_remove_trailing_spaces = 0
" All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required
% These commands are used to identify and select the hard drive
diskpart list disk sel disk % These commands are used to list the partitions, select the Boot EFI partition, % then assign it a drive letter list vol sel vol 2 assign letter=D: exit % These commands are used to change into the Boot EFI folder and delete the GRUB folder cd /d D: ls ls EFI cd EFI ls rmdir /s ubuntu
reread - Reread supervisor configuration. Do not update or restart the running services.
update - Restart service(s) whose configuration has changed. Usually run after ‘reread’.
reload - Reread supervisor configuration, reload supervisord and supervisorctl
restart - Restart service(s)
service
1 2 3 4
service ssh status service ssh restart
netstat –nlp | grep 22
tee
1
tee
In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input.