Showing posts with label WSL. Show all posts
Showing posts with label WSL. Show all posts

Oct 31, 2022

How fun is Windows?

Received new laptop that runs Windows 11 over the weekend.


Had spent some times on customize a few things:
  1. Install Google_Pinyin 
  2. Setup the input method switching to (left) ctrl-shift notkey.
  3. Install WSL/WSL2
  4. Install Windows Terminal
  5. Install Multipass (VM orchestrator)
  6. Setup ssh-keygen
  7. Create sample multipass VM with cloud-init
  8. Install python3 (in Windows 11)

Between WSL and Multipass, I need to setup the routing in order for them to communicate.

PS> Set-NetIPInterface -ifAlias "vEthernet (WSL)" -Forwarding Enabled
PS> Set-NetIPInterface -ifAlias "vEthernet (Default Switch)" -Forwarding Enabled

And to show the final routing table:
PS> Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table

One the routing is configured, then I proceed with ssh-keygen and setup the public key authentication between WSL and multipass.

~$ cd .ssh
~/.ssh$ ssh-keygen -t ed25519 -C "xx@wsl2"
~/.ssh$ ssh-keygen -l -f id_ed25519.pub
~/.ssh$ ssh-copy-id -i id_ed25519.pub xx@remote_server


Next, I need to setup multipass VM with cloud-init.

Create a cloud-init.yaml file for multipass:
-------------------------------
users:
  - default
  - name: xx
    groups: sudo
    shell: /bin/bash
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    ssh_authorized_keys:
      - ssh-rsa <rsa keys in one line>
package_update: true
package_upgrade: true
packages:
  - nodejs
  - python3
-------------------------------


PS> multipass multipass launch -c 2 -m 2G -d 20G -n ubuntu-vm --cloud-init cloud_init.yaml


Learnt some tricks in Windows command line. I install Python (with cmdline) and locate where is the python.exe.

PS> winget install python --source msstore
PS> where python

Oct 22, 2022

Couldn't open a raw socket. Error: Permission denied (13)

With Multipass, do I still need VMware Player to run Linux with full privilege, under Windows OS ?

WSL is more common choice of running virtual machine nowadays comparing to VMware Player.

With Multipass, everything seems more easier/faster now. 😇 

Here's my story today, on how I need to run nmap port scan to a router.

PS> multipass launch -n scanner

PS> multipass shell scanner

ubuntu@scanner:~$ sudo snap install nmap

ubuntu@scanner:~$ sudo nmap -sU -p 53 192.168.31.1
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-21 23:17 +08
Couldn't open a raw socket. Error: Permission denied (13)

ubuntu@scanner:~$ sudo snap connect nmap:network-control

ubuntu@suzuki:~$ sudo nmap -sU -p 53 192.168.31.1
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-21 23:18 +08
Nmap scan report for XiaoQiang (192.168.31.1)
Host is up (0.0027s latency).

PORT   STATE SERVICE
53/udp open  domain

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds

ubuntu@scanner:~$ sudo nmap -n -sS -p 1-1024 192.168.31.1
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-21 23:35 +08
Nmap scan report for 192.168.31.1
Host is up (0.0075s latency).
Not shown: 1020 closed tcp ports (reset)
PORT    STATE SERVICE
53/tcp  open  domain
80/tcp  open  http
443/tcp open  https
784/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 0.34 seconds
ubuntu@scanner:~$

With this, I have more confidence with Multipass now. 😉

Sep 16, 2022

Backup and Restore WSL for Linux

Check WSL version

wsl -l -v 

Backup the (Ubuntu) distro

wsl --export (distribution) (filename.tar)

wsl --export Ubuntu Backup_Ubuntu.tar

wsl --export Ubuntu c:\users\xx\desktop\Backup_Ubuntu.tar

To restore a WSL distro from a backup

wsl --import (distribution) (install location) (file location and filename)

wsl --import Ubuntu d:\wsl c:\users\xx\desktop\Backup_Ubuntu.tar


Sep 15, 2022

Install Linux on Windows with WSL

Prerequisites: Setting up WSL on Windows.

  1. Open Command Prompt as Administrator

 

Install WSL 

wsl --install

List the available online Linux distribution

wsl -l -o

wsl --list --online

Install an Ubuntu distribution

wsl --install -d Ubuntu

Check WSL version

wsl -l -v 

Set the default WSL version (1/2)

wsl --set-default-version 2 

Upgrade an Ubuntu to WSL version 2

wsl --set-version Ubuntu 2

Upgrade to WSL2


Links: