WSL installation and use (Ubuntu22.04)

overview

This article mainly records the installation and use process of Windows WSL, including the WSL installation process, WSL installation of Ubuntu, Ubuntu replacement mirror source, Ubuntu installation and configuration of Dcoker, etc.

Introduction to WSL

Windows Subsystem for Linux (WSL for short) is a compatibility layer that can run native Linux binary executable files (ELF format) on Windows 10\11. It was developed by Microsoft in cooperation with Canonical. Its goal is to enable pure Ubuntu, Debian and other images to be downloaded and decompressed to the user's local computer, and the tools and utilities in the image can run natively on this subsystem. [1-3]
If you use Windows 10 2004 or above, you can run desktop applications in a window through WSL 2, and there is no need to install other X servers.
Reference link

WSL installation

Installation Environment

Operating System: Microsoft Windows 11 Home Chinese Edition
Version Number: 10.0.22621
Virtualization: Enabled

Installation method one: command line installation (not recommended, strange problems may occur)

Enter in cmd:wsl --install

Installation method two: Install through the control panel

windows+ S, search the control panel, open the control panel: 控制面板->程序->启用或关闭Windows功能->适用于Linux的Windows子系统, check it, restart the host, and WSL will be installed.

WSL installation of Ubuntu22.04 (via Microsoft Store)

Open Microsoft Storethe search WSLand you will see the supported operating systems and choose Ubuntu 22.04to install them.
Insert image description here

Ubuntu changing mirror source

Enter Ubuntu

Open the latest terminal of win11 and select Ubuntu 22.04 to enter the Ubuntu subsystem.
Insert image description here

Change mirror source

# 切换至root用户后,执行下述指令
# 备份旧的镜像源文件
$ mv /etc/apt/sources.list /etc/apt/sources.list.bk
# 更换为阿里源
$ vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
# 更新软件
$ apt-get update 

Install Docker on Ubuntu

# snap安装docker
$ snap install docker
# 修改docker配置文件
# 如果是自行搭建的镜像仓库,使用`insecure-registries`避免出现报错Error response from daemon: Get "https://ip:port/v2/": http: server gave HTTP response to HTTPS client
$ vi /var/snap/docker/current/config/daemon.json
{
    
    
    "log-level":        "error",
    "registry-mirrors": [
        "https://artifact.srdcloud.cn",
        "https://hub-mirror.c.163.com"
    ],
    "insecure-registries": ["IP:PORT"],
    "experimental": true
}
# 修改完配置要先停止docker,再重新启动,否则配置不生效
$ snap stop docker
$ snap start docker
# 查看docker配置
$ docker info

Problem solving

Using WSL, it was found that it could not ping the host or connect to the external network.

When I installed it for the first time, I installed WSL through the Microsoft Store. As a result, Ubuntu could not ping the host machine or connect to the external network. I tried all online methods to no avail. The solution is通过控制面板卸载WSL后重装

WSL migration to other disk

Problem Description

WSL's subsystem will be installed on the C drive by default. With use, the C drive will occupy more and more space, causing WSL system abnormalities.

Solution

Migrate the WSL subsystem to other disks. The specific process is as follows:

  1. View WSL status: wsl -l -vMake sure the subsystem is in Stoppedstatus before migrating
  2. Export subsystem image:wsl --export linux_name E:\ubuntu.tar
  3. Log out of the Linux subsystem:wsl --unregister linux_name
  4. Import system:wsl --import <子系统名称> <要迁移的磁盘路径> E:\ubuntu.tar --version 2
  5. Modify default user:ubuntu22.04.exe config --default-user root

Guess you like

Origin blog.csdn.net/Loiterer_Y/article/details/131641960