【Windows 11】Install Android Subsystem and Linux Subsystem

This article uses a computer system:
insert image description here

1. Android subsystem

1.1 Install WSA

The main thing is to install a software called: Windows Subsystem for Android (WSA).

First of all, in the settings of the computer: time and language - language and region, change the region to the United States.

Then go to the Microsoft Store and search for: Amazon AppStore.

insert image description here

When installing the Amazon App Store, you will first be prompted to install the WSA mentioned earlier. In this way, our purpose is achieved.
insert image description here
As for the Amazon app store, it is not recommended to use it, and it has stopped serving in the country. You can sign up for an account in the US region and log in to see for yourself (not necessary).

1.2 use

Now, after doing some settings, you can install the Android APP.

Search the Windows function in the search bar, and in the enable or disable Windows function, make sure that " Virtual Machine Platform " and " Hyper-V" are checked. At the same time, in order to install the Linux subsystem, the " Windows Subsystem for Linux " is also checked by the way. After checking, save and restart the computer. (If there is an error or prompt about WSL, that is, the Linux subsystem, don't worry about it)
insert image description here

Open WSA, share the folder here. Purpose: To enable the Android subsystem to access the files of Windows users, so that the apk installation package we downloaded to Windows can be installed.
insert image description here

Close WSA, download apkthe installation package of the software you want to install, and search online by yourself. There should be many such websites. I use: https://apkpure.com/cn/app (it seems to need magic)

Save the installation apk package to the download folder of the computer, or other directories under the user folder.

Open WSA, click System - File, and come to this interface: it uses part of the storage space of your Windows to simulate the Android system.
insert image description here

Click Windows, go in and find the apk you saved, click, an option will pop up, choose to install. There may be an error, just try again.

After the installation is complete, it can be opened like other Windows software.

insert image description here


Note:

Don't install too many APPs now, the installation subsystem may be infected after installing the Linux subsystem later, the specific performance is: when starting to install the APP, it shows that WSA has stopped working. (I met)

At this time, just reset the WSA in the settings, the settings and installed software will be cleared, and it will be fine to go through the process again.
insert image description here

Two, the Linux subsystem

2.1 Install WSL and WSL related concepts

In the previous step, we have checked " Windows Subsystem for Linux " (WSL: Windows Subsystem for Linux) and "Virtual Machine Platform".

WSL is a compatibility layer designed for Windows 10 and Windows Server 2019 to run Linux binary executables on Windows. Here is some key information about WSL:

  1. Compatibility : WSL allows you to run most command-line tools, applications, and utilities of a Linux distribution on Windows without launching a virtual machine or using a dual-boot.

  2. Integration : You can seamlessly move files between Windows and Linux, and even access Linux files in Windows' File Explorer.

  3. Performance : Since WSL is a lightweight compatibility layer rather than a full virtual machine, it has very little performance overhead .

  4. Developer friendly : WSL is especially useful for developers as it allows them to use Linux's development tools on Windows and test cross-platform applications on the same machine.

  5. Versions : WSL has two versions, WSL 1 and WSL 2. WSL 2 introduces a full Linux kernel, offering better performance and full syscall compatibility.


The WSL version enabled from "Windows Features" is WSL 1.

It is recommended to useWSL 2 , go to the Microsoft store to search for WSL, you can see (Microsoft's official one), and install it.

insert image description here

Comparison between 1 and 2:

Features/Aspects WSL1 WSL2
architecture compatibility layer full linux kernel
performance File system performance is slow Especially faster when using the Linux native file system
system call limited support Full system call compatibility
Docker support limited native support
network Share IP with host Use your own IP address
File system Access Windows files via DrvFs Access Windows files through 9P protocol
Start Time faster Slightly slower due to VM startup (actually quite fast)
memory usage lower Use more memory due to VM
distribution support All distributions available in the Microsoft Store All distributions available in the Microsoft Store + custom distributions
kernel update Bundled with Windows Update Can be updated independently

2.2 Install a Linux distribution

WSL 2 includes a full Linux kernel. This is one of the main differences between WSL 1 and WSL 2.

  • WSL 1 : It uses a compatibility layer to run Linux binaries. This means that it does not include a real Linux kernel, but emulates the behavior of a Linux kernel. This makes WSL 1 less performant than WSL 2 in some cases, especially when filesystem operations are involved.

  • WSL 2 : It uses a real Linux kernel and runs in a lightweight virtual machine. This provides better performance and full Linux system call compatibility. Microsoft provides a dedicated Linux kernel for WSL 2, but users can also update or modify this kernel themselves.

This kernel is distributed with Windows as a separate component, which means it can be updated independently of Windows Update. This provides users with greater flexibility, allowing them to more easily obtain new versions and features of the kernel.


Even though WSL 2 includes a full Linux kernel, users still need to download a Linux distribution for the following reasons:

  1. User Space vs. Kernel Space : The Linux operating system can be divided into two main parts: the kernel and user space. The kernel is responsible for interacting with the hardware, managing resources, etc., while user space contains all user-level applications and tools. WSL 2 provides a Linux kernel, but users still need a Linux distribution to provide userspace components.

  2. Choice of distribution : Linux has multiple distributions, such as Ubuntu, Debian, Fedora, etc., and each distribution has its specific software packages, configurations, and tools. Users can choose the appropriate distribution according to their needs and preferences.

  3. Package management : Each Linux distribution has its own package manager, such as Ubuntu apt, Fedora, dnfetc. These tools allow users to easily install, update and manage software.

  4. Environment configuration : Different Linux distributions may have different default environment configurations, services and tools. Downloading a specific distribution allows users to get their desired working environment.

  5. Compatibility : Certain applications or tools may work better or only be available on specific Linux distributions.

There are many ways to install a Linux distribution, this article introduces the most basic 2.

2.21 Install from Microsoft Store

Just go to the Microsoft store and search for the distribution you want to install, such as Ubuntu, then select the version you want and download it.

After the download is complete, double-click to start the installation program: during this period, you need to set up a Linux user

insert image description here

By default, the desktop is not installed, and the startup methods are as follows:

  • Run (win r), wsl, press enter (will start the default WSL distribution if only one distribution is installed, such as Ubuntu, then it is the default);
  • Run, bash, Enter (early command, not recommended, may conflict with Git Bash and the like);
  • Run, wt(Windows Terminal), create a new Ubuntu tab.
    insert image description here

Many commands and command-line jobs work fine:
insert image description here

2.22 Install with command

Now run it in Powershell wsl--help, you can see the wsl command, Chinese, easy to understand, I put it at the end of the article.

Here is an example:

(1) Obtain the Linux distribution available for installation:wsl --list --online

以下是可安装的有效分发的列表。
使用 'wsl.exe --install <Distro>' 安装。

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed

(2) Install the distribution you need: wsl --install Ubuntu-22.04

There is nothing else to say.

2.23 Expansion

  1. Check the wsl version: wsl --version
    This command outputs the specific software version of wsl, not the WSL1 and WSL2 we are talking about, for example
    insert image description here

  2. If you want to check whether you are using WSL1 or WSL 2, you can use: wsl --list --verbose
    insert image description here
    or use: wsl --status
    insert image description here
    or use in running Linux: uname -aview
    insert image description here

  3. Set default version of WSL: wsl --set-default-version 2
    This command will set the default WSL version for all future installations of Linux distributions. Versions of already installed distributions will not be affected.
    If you want to change the version of a specific Linux distribution already installed, for example:wsl --set-version Ubuntu 2

  4. Multiple Linux distributions are installed, and a certain distribution is set to start by default, for example:wsl --set-default Ubuntu

3. Expansion

It is recommended to install a Linux-Windows dual system or use a server. It is recommended to run the PC version of each software on the computer.

This kind of virtualization technology may be unstable sometimes and can be used for entertainment and learning.

3.1 Storage location

In WSL, the file system of a Linux distribution is stored as a special file , often called a "disk image" file. These files are stored slightly differently for WSL 1 and WSL 2:

  1. WSL 1

    • The Linux distribution filesystem for WSL 1 is stored in a hidden folder within the Windows filesystem. Typically, this location is:
      C:\Users\<YourUsername>\AppData\Local\Packages\<DistroPackageName>\LocalState\rootfs\
      
      where <YourUsername>is the Windows username and <DistroPackageName>is the package name for the Linux distribution, e.g. CanonicalGroupLimited.UbuntuonWindowsfor Ubuntu.
  2. WSL 2

    • WSL 2 uses a real Linux kernel and a lightweight virtual machine. Therefore, its filesystem is stored as a VHDX file, usually located at:
      C:\Users\<YourUsername>\AppData\Local\Packages\<DistroPackageName>\LocalState\ext4.vhdx
      

insert image description here

Generally speaking, Ubuntu installed in this way is located on our C drive, including the kernel, add-ons, and so on. After I followed it, it took up about 20G (should also include other content).


As mentioned earlier, Linux in WSL requires Windows to share storage space, that is to say, it will mount each disk and partition of Windows to the root directory. Of course, he will use part of the storage space to serve the Linux system. For example, he will use a lightweight virtual machine to run the Linux kernel. The file system of this part of the space is ext4 (Linux mainstream file system).

The original Windows partitions still maintain their original file system type (such as NTFS), but use the " 9P" protocol to mount to the Linux root directory.
insert image description here

3.2 Virtualization Technology

Hyper-VIt is a hardware virtualization technology provided by Microsoft that allows users to run multiple virtualized operating systems on a single physical computer . It was introduced in Windows Server 2008 and has since been included in some Windows client editions as well, such as the Professional and Enterprise editions of Windows 10 and Windows 11.

Here are some key features and capabilities of Hyper-V:

  1. Hardware virtualization : Hyper-V uses hardware-assisted virtualization technology, which requires the physical computer's CPU to support virtualization, and this feature has been enabled.

  2. Isolation : Each virtual machine runs in its own isolated environment, which provides OS-level isolation for each virtual machine.

  3. Flexible resource management : Users can assign specific CPU, memory, storage and network resources to each virtual machine.

  4. Virtual Hard Disk : Hyper-V supports multiple virtual hard disk formats, such as VHD and VHDX.

  5. Virtual Networking : Hyper-V allows the creation and management of virtual network switches, enabling communication between virtual machines and between virtual machines and external networks.

  6. Integration Services : These are special services that run inside the virtual machine to improve performance and enable the virtual machine to interact better with the Hyper-V host.

  7. Snapshots and Checkpoints : Allow users to capture the current state of a virtual machine so that they can be restored to that state if needed in the future.

  8. Relation to WSL 2 : While WSL 2 uses a lightweight virtual machine to run the Linux kernel, it does not use Hyper-V directly. However, both WSL 2 and Hyper-V rely on the same underlying virtualization technology.

  9. Compatibility : Certain other virtualization solutions may not work properly when Hyper-V is enabled, as they may conflict with Hyper-V.

Hyper-V is primarily used for server virtualization in enterprise environments, but it can also be used in desktop environments for development, testing or learning purposes.


The " Virtual Machine Platform " (Virtual Machine Platform) is an optional feature of Windows that provides a lightweight virtualization solution for Windows, specifically to support WSL 2.

Here are some key points of the "virtual machine platform":

  1. WSL 2 support : Unlike WSL 1, WSL 2 uses a real Linux kernel and runs on a lightweight virtual machine. To support this virtualization, Windows introduced the "Virtual Machine Platform" feature.

  2. Lightweight Virtualization : "Virtual Machine Platform" provides a lightweight virtualization solution that is simpler and more efficient than Hyper-V. It is designed for running WSL 2 and other lightweight virtualization tasks.

  3. Relationship to Hyper-V : While both "Virtual Machine Platform" and Hyper-V use the same underlying virtualization technology, they are designed for different purposes. Both "Virtual Machine Platform" and Hyper-V can be enabled.

  4. Enable/Disable : To use WSL 2, the "Virtual Machine Platform" feature needs to be enabled. This can be done through Windows feature settings or using command line tools.

  5. Hardware requirements : "Virtual Machine Platform" requires that the computer supports hardware virtualization and that this feature is enabled.

3.3 Windows virtual memory

Similar to Linux's swap partition (file), Windows virtual memory is a memory management feature that allows a computer to use hard disk space as RAM (random access memory). When a computer's physical RAM is used up, Windows moves some data to an area on the hard disk called the "page file" (or "swap space"), freeing RAM space for other programs to use

Virtual memory (page file) and Hyper-V and "virtual machine platform" are two completely different concepts, and there is no direct dependency between them.
insert image description here
Generally, it is automatically set by the system, but it can also be customized:
insert image description here

3.3 wsl help file

用法: wsl.exe [Argument] [Options...] [CommandLine]

运行 Linux 二进制文件的参数:

    如果未提供命令行,wsl.exe 将启动默认 shell。

    --exec, -e <CommandLine>
        不使用默认 Linux shell 执行指定的命令。

    --shell-type <Type>
        使用提供的 shell 类型执行指定的命令。

        类型:
            standard
                使用默认 Linux shell 执行指定的命令。

            login
                使用默认 Linux shell 作为登录 shell 执行指定的命令。

            none
                不使用默认 Linux shell 执行指定的命令。

    --
        按原样传递命令行的剩余部分。

选项:
    --cd <Directory>
        将指定的目录设置为当前工作目录。
         如果使用 ~,则将使用 Linux 用户的主路径。如果路径以
        / 字符开头,它将解释为绝对 Linux 路径。
        否则,该值必须为绝对 Windows 路径。

    --distribution, -d <Distro>
        运行指定的分发。

    --user, -u <UserName>
        以指定的用户身份运行。

    --system
        启动 shell 进行系统分发

用于管理适用于 Linux 的 Windows 子系统的参数:

    --help
        显示用法信息。

    --debug-shell
        打开 WSL2 调试 shell 以进行诊断。

    --event-viewer
        打开 Windows 事件查看器的应用视图。

    --install [Distro] [Options...]
        安装适用于 Linux 的 Windows 子系统分发。
        若要查看有效分发列表,请使用 'wsl.exe --list --online'。

        选项:
            --no-launch, -n
                安装后不要启动分发。

            --web-download
                从 Internet 而不是 Microsoft Store 下载分发。

            --no-distribution
                仅安装所需的可选组件,不安装分发。

    --mount <Disk>
        在所有 WSL 2 分发中附加并装载物理或虚拟磁盘。

        选项:
            --vhd
                指定 <Disk> 代表虚拟硬盘。

            --bare
                将磁盘附加到 WSL2 但不装载。

            --name <Name>
                为装入点使用自定义名称装载磁盘。

            --type <Type>
                装载磁盘时使用的文件系统,如果未指定则默认为 ext4。

            --options <Options>
                其他装载选项。

            --partition <Index>
                要装载的分区索引,如果未指定则默认为整个磁盘。

    --release-notes
        打开 Web 浏览器查看 WSL 发行说明页面。

    --set-default-version <Version>
        更改新分发的默认安装版本。

    --shutdown
        立即终止所有正在运行的分发和 WSL 2
        轻型虚拟机。

    --status
        显示适用于 Linux 的 Windows 子系统的状态。

    --unmount [Disk]
        从所有 WSL2 分发中卸载并分离一个磁盘。
        如果未使用参数调用,则卸载并分离所有磁盘。

    --update
        更新适用于 Linux 的 Windows 子系统程序包。

        选项:
            --web-download
                从 Internet 而不是 Microsoft Store 下载更新。

            --pre-release
                如果可用,则下载预发布版本。表示使用 --web-download。

    --version, -v
        显示版本信息。

用于管理适用于 Linux 的 Windows 子系统中的分发的参数:

    --export <Distro> <FileName> [Options]
        将分发导出为 tar 文件。
        对于标准输出,文件名可以是 "-"。

        选项:
            --vhd
                指定应导出为 .vhdx 文件的分发。

    --import <Distro> <InstallLocation> <FileName> [Options]
        将指定的 tar 导入为新分发。
        对于标准输入,文件名可以是 "-"。

        选项:
            --version <Version>
                指定要为新分发使用的版本。

            --vhd
                指定提供的文件为 .vhdx 文件,而不是 tar 文件。
                此操作将在指定的安装位置生成一个 .vhdx 文件的副本。

    --import-in-place <Distro> <FileName>
        将指定的 .vhdx 导入为一个新分发。
        此虚拟硬盘必须使用 ext4 文件系统类型格式化。

    --list, -l [Options]
        列出分发。

        选项:
            --all
                列出所有分发,包括
                目前正在安装或卸载的分发。

            --running
                仅列出目前正在运行的分发。

            --quiet, -q
                仅显示分发名称。

            --verbose, -v
                显示所有分发的相关详细信息。

            --online, -o
                使用 'wsl.exe --install' 显示可以安装的可用分发列表。

    --set-default, -s <Distro>
        将分发设置为默认分发。

    --set-version <Distro> <Version>
        更改指定分发的版本。

    --terminate, -t <Distro>
        终止指定分发。

    --unregister <Distro>
        注销分发并删除根文件系统。


Write love you forever into the end of the poem ~

Guess you like

Origin blog.csdn.net/weixin_43764974/article/details/132268834