Today I Learned (2019-11-18)

How to reset WSL on Windows

  • Type apps & into the search box in the bottom left of the taskbar.
  • Click Apps & features in the search results. The Settings app will open.
  • On the Apps & features page in the Settings app, type Ubuntu, or the name of the Linux distribution you want to reset, in the ‘Search this list’ box.
  • Ubuntu, or the name of your Linux distribution, will appear. Click it and then click Advanced options.
  • In the Settings app, scroll down the list of options until you see Reset. There are two options, Repair and Reset. We want to reset our distribution, so click Reset.
  • You will see a warning that resetting the app will permanently delete its data and sign-in preferences. Click Reset again in the pop-out dialog.
  • The resetting process will take a few seconds. Once it’s complete, a tick icon will appear to the right of the Reset button.

Changing mount path of WSL from /mnt/c to /c

This works for all of your drives at once. Create /etc/wsl.conf with this content

# Enable extra metadata options by default
[automount]
enabled = true
root = /
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

Source: https://github.com/microsoft/WSL/issues/1918

Move WSL to an external drive

1. Set permissions to the target folder. First, I think you must set some permissions to the folder where the distribution will be moved. You may use icacls <dir> /grant "<user>:(OI)(CI)(F)" to set the proper permissions.

C:\> whoami
test\jaime

C:\> icacls D:\wsl /grant "jaime:(OI)(CI)(F)"

NOTE: In addition to the above permissions, I have activated the long path names in Windows.

2. Move the distribution. Using lxrunoffline move.

C:\wsl> lxrunoffline move -n Ubuntu-18.04 -d d:\wsl\installed\Ubuntu-18.04

You may check the installation folder using

C:\wsl> lxrunoffline get-dir -n Ubuntu-18.04
d:\wsl\installed\Ubuntu-18.04

3. Run the distribution. after moving the distribution, you can run the distribution using wsl or the same lxrunoffline

C:\wsl> lxrunoffline run -n Ubuntu-18.04 -w
user@test:~$ exit
logout

C:\wsl> wsl
user@test:/mnt/c/wsl$ exit
logout

Use the mirror protocol to automatically select the best mirror

Using mirror protocol as part of your /etc/apt/sources.list entry will instruct apt command to fetch mirrors located within your country only. In order to use mirror protocol update all lines within /etc/apt/sources.list file from the usual eg.:

deb http://us.archive.ubuntu.com/ubuntu/ ...

to:

deb mirror://mirrors.ubuntu.com/mirrors.txt ...

Repeat the above for all relevant lines where appropriate. Alternatively, use sed command to automatically edit your /etc/apt/sources.list file. Update the below sed command where appropriate to fit your environment:

$ sudo sed -i -e 's/http:\/\/archive/mirror:\/\/mirrors/' -e 's/\/ubuntu\//\/mirrors.txt/' /etc/apt/sources.list

Gõ tiếng Việt trên Ubuntu

Cách gõ Dvorak trên Ubuntu với ibus-unikey

Các bộ gõ tiếng Việt trên ubuntu

  • ibus-unikey là bộ gõ có sẵn trong source, dễ cài nhất nhưng có vấn đề bị revert keyboard như ở trên
  • ibus-teni (telex-vni) mới hơn
  • ibus-bamboo: cùng tiêu chí với teni, bộ gõ mới nhất, được cập nhật thường xuyên, hỗ trợ nhiều chế độ gõ cho nhiều ứng dụng khác nhau, tuy nhiên chưa được nổi tiếng như ibus-unikey vì hầu hết các tài liệu hướng dẫn đều viết về ibus-unikey (có lẽ vì unikey namesake quá nổi tiếng trên Windows)

Install IP Time USB Wifi Adapter driver for Ubuntu Linux

It’s not that hard… provided you know where to look.

First, find out the model ID by going

lsusb

You’ll get something like this, where “Realtek” is the chip manufacturer, which is usually the case for IPTime

Next, google the ID, it will take you to stack overflow, in my case, this answer

Which leads me to this repository

A few commands later…

cd rtl88x2BU_WiFi_linux_v5.3.1_27678.20180430_COEX20180427-5959
VER=$(sed -n 's/\PACKAGE_VERSION="\(.*\)"/\1/p' dkms.conf)
sudo rsync -rvhP ./ /usr/src/rtl88x2bu-${VER}
sudo dkms add -m rtl88x2bu -v ${VER}
sudo dkms build -m rtl88x2bu -v ${VER}
sudo dkms install -m rtl88x2bu -v ${VER}
sudo modprobe 88x2bu

And voila, it works even without a reboot

How to set up squid

On Ubuntu

Basic squid conf

/etc/squid3/squid.conf instead of the super bloated default config file

auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

# Choose the port you want. Below we set it to default 3128.
http_port 3128

Setting up a user

sudo htpasswd -c /etc/squid3/passwords username_you_like

and enter a password twice for the chosen username then

sudo service squid3 restart

How to install tinyproxy, the comprehensive guide

You should build from source, since the latest version on Ubuntu repository doesn’t support authentication yet

git clone https://github.com/tinyproxy/tinyproxy.git
sudo apt-get install automake cmake asciidoc 

cd tinyproxy
./autogen.sh
make && make install

Add authentication

vi /etc/tinyproxy.conf
-----
BasicAuth user password
Allow your.local.ip.address
-----
sudo /etc/init.d/tinyproxy restart