Win10 Linux subsystem compiles Android system source code

I. Introduction

I heard that win10 integrated Linux as a subsystem. At first, I thought it was an implementation mechanism similar to a virtual machine, and it must have limited performance improvement. But after a little understanding, I found that it is not the mechanism of the virtual machine, but the performance of the Host machine can be fully utilized. This is undoubtedly a perfect substitute for using a virtual machine to learn things on the Linux platform. But I still worry that this subsystem is not as perfect as I expected, so try to compile the Android system. If you can compile Android successfully, it can basically be used as a perfect substitute.

2. Upgrade from Windows 7 to Windows 10

Due to the previous dislike of various rumors about win10, I have not upgraded win10, for fear of facing the horror of being ruled by forced updates for the rest of my life. However, the company has generally adopted win10. It took a while to find that some places are indeed slow, but it has not reached the unbearable level in the legend. What's more, there is also a Linux subsystem, so I made up my mind to upgrade my win7 to win10 .

This section mentions how to upgrade win10 as "purely" as possible.

Essential tools:

(1) windows10 system image.

(2) A U disk (capacity is optional).

It should be noted here that some people will choose GHOST mirroring, but I have always stayed away from GHOST mirroring. The GHOST image will integrate many unnecessary things, various self-righteous modifications to the system configuration, and various messy pre-installed applications. But now it is very difficult to find a "pure" windows 10 installation image, and I only found a not-so-satisfactory iso image. However, it is an installation disk.

To sum it up in one sentence, use the Lao Maotao U disk boot tool to make the U disk into a WInPE boot U disk, and then load the image in WinPE for installation. It is recommended to format the C drive and back up everything in advance: desktop, my documents, C drive directory and other applications, etc.

Note here: When making a U disk to boot, you will be prompted whether to join UEFI boot, do not choose. I wanted to try it at first, but the result was that it stopped at 99% and waited for N long N long, and then the U disk became bricked after forced shutdown. Presumably this UEFI does not support all U disks, and our scenario does not have this need, so don't introduce additional problems to yourself. After that, it was done by using the partition table recovery of the partition assistant.

After installing it, activate it, so I won’t talk about it. The impure image may also pre-install several applications, so delete them all first. It needs to be reinstalled later. Preinstalled applications generally need to be updated due to version issues. And the ghost knows where it was installed, so I simply unloaded it first.

Win10 is installed, so I won't say much about other details.

If you have any questions, you can leave a message to ask, and I will improve the details later when I have time.

3. Install the Linux subsystem in Windows 10

Here I searched for tutorials on CSDN and Baidu at the beginning, but the tutorials I found have expired, and many steps are wrong. Here my suggestion is:

Go directly to the official installation tutorial

My tutorial will also expire, so the official address is given directly here.

Install wsl:  https://docs.microsoft.com/en-us/windows/wsl/install-win10

Install WSL manually (suitable for Microsoft Store not available): https://docs.microsoft.com/en-us/windows/wsl/install-manual

WSL:Windows Subsystem for Linux

Before using WSL1, the compilation was not successful. But I saw someone else compiled successfully on the Internet. But now WSL 2 is released, which is said to be a complete Linux kernel, which has made great progress compared to 1. See the official comparison below, so let's upgrade 2 and try again:

https://docs.microsoft.com/en-us/windows/wsl/compare-versions

Comparing features

COMPARING FEATURES
Feature WSL 1 WSL 2
Integration between Windows and Linux
Fast boot times
Small resource foot print
Runs with current versions of VMware and VirtualBox
Managed VM
Full Linux Kernel
Full system call compatibility
Performance across OS file systems

Then if we have downloaded WSL 1 before, we must first delete the previous WSL 1 and install WSL2:

The lxrun command cannot be used after win10 version 1903. There are two ways to delete the subsystem:

1. wslconfig /l View the name of the subsystem to be deleted, such as Ubuntu-18.04, wslconfig /unregister Ubuntu-18.04 can be deleted

2. Manual deletion

PowerShell:

    rm -Resources $env:localappdata/lxss/

Cmd:

   DEL /S %localappdata%\lxss\

 

I deleted it directly using the above wslconfig /unregister Ubuntu-18.04.

Let's start installing the WSL tutorial:

The manual download method was provided before, and WSL2 seems to be able to use the Microsoft store directly. If your Microsoft store is not available, you can see the manual installation tutorial below.

Step 1: - Enable the Window subsystem

Run a Power Shell with administrator privileges and enter the following command:

PowerShellCopy

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Step 2:- Update to WSL 2

WSL 2 needs to meet several prerequisites:

The system version needs to meet x64xit:  Version 1903  or higher, with  Build 18362  or higher.

To check your own version:

win+R, enter winver.

Simply put, after the update version reaches 1903, it will be WSL 2.

Step 3 - Enable virtual features

Before installing WSL 2, you must enable "Virtual Machine Features":

Run PowerShell with administrator privileges and execute the following command:

 

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Once done, reboot. After the reboot is complete your machine will have WSL installed and updated to WSl 2.

Step 4 - Download the WSL2 Linux kernel update package (if it is ARM64, download the corresponding version)

1. Download the latest package:

WSL2 Linux kernel update package for x64 machines

2. Execute the update package downloaded in step 1 above.

The installation is complete.

Step Five - Set WSL 2 as your default version

Run PowerShell with administrator privileges and enter the following command. What this command does is set WSL 2 as the default version for new Linux installations.

wsl --set-default-version 2

Step Six - Install Your Linux Distribution

Note that this part can use the Microsoft store, if the Microsoft store is not available, use the following manual installation tutorial.

Open the Microsoft store and choose your favorite Linux distribution:

View of Linux distributions in the Microsoft Store

The following are some commonly used versions given on the official website. I downloaded Ubuntu 18.04. Clicking the link will automatically open the Microsoft store, and an available Microsoft account is required.

If the Microsoft store is not available, or if you don't want to use it, you can also manually download the Linux distribution, as follows

Manual installation tutorial:

https://docs.microsoft.com/en-us/windows/wsl/install-manual

Choose the version you want, download, and install.

A simple one-sentence summary: download the installation package of your favorite Linux distribution, and install it. (In WSL1, you need to install the downloaded one in the place you want to be the root directory. In WSL2, you can install it directly. WSL1 needs to pay attention to :

Enter the directory where the downloaded file is located, which is also the root directory of your future Linux system. So try to avoid too deep directory path, and contain Chinese. Although I don't know what's wrong with including Chinese, but it can be avoided).

I chose Ubuntu18.04. Then enter the command line, use the cd command to enter this directory, and execute the following command:

Add-AppxPackage .\app_name.appx

Add-AppxPackage is a program of win10, this command is called directly. The latter .\app_name.appx is the name of the release version you downloaded yourself, be careful to replace it with the file you downloaded in the previous step.

Finally, I want to emphasize again: this directory will become the root directory of your Linux system.

After installation, enter the command bash in the terminal to enter the Linux system, seamless switching, perfect. Well, you've entered the Linux world, it's that simple.

There may be some discrepancies here. The manual part was written in WSL 1 last time, and the Microsoft store is directly used by WSL2.

 

Step Seven - Boot Linux

The way to start it in WSL 1 is to enter bash at the command line. WSL 2 is the distribution that runs the installation. For example, mine is Ubuntu 18.04, which can be found in the program or in the Microsoft store. Of course, you can also use the command line to start, enter ubuntu1804 in the command line, and the Linux kernel will be started. This command will vary depending on the distribution you have installed.

There is a problem here:

The solution to "The object type of reference does not support the attempted operation" appears when using WSL2

This is also the problem I encountered, directly quote:

======== Source address: https://blog.csdn.net/weixin_43347283/article/details/107006275 =====================

question:

The attempted operation is not supported for the referenced object type. (The attempted operation is not supported for the type of object referenced.)
Solution:

1. Temporary solution (not recommended):

Run CMD as an administrator, enter:

netsh winsock reset

Restarting the computer fixes it.

2. A relatively long-term solution (recommended):

(Used so far, there is still no problem)

(1) Download this software:

www.proxifier.com/tmp/Test20200228/NoLsp.exe
​(
Because a ladder is required to access and download, some friends are inconvenient, so I uploaded it to Baidu Cloud to share here:)
(Link: https://pan.baidu.com/ s/1bVZ0OXZPxEt8l1IHYaFK3A, extraction code: vjge)

(2) Run CMD as an administrator and enter:

NoLsp.exe C:\windows\system32\wsl.exe
  • 1

Please pay attention to the location of the NoLsp.exe program and your wsl.exe location.
Cause and solution analysis:
the sock port conflict between the proxy software and wsl2, use netsh winsock reset to reset and repair.
The Proxifer developers explain it as follows:

wsl.exe will display this error if the Winsock LSP DLL is loaded into its process. The easiest solution is to use the WSCSetApplicationCategory
WinAPI call to wsl.exe to prevent this. Behind the scenes, this call creates an entry for wsl.exe in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog.
This will tell Windows not to load the LSP DLL into the wsl.exe process

The above solution comes from:

1.https://github.com/microsoft/WSL/issues/4177
2. https://answers.microsoft.com/zh-hans/insider/forum/all/wsl2%E5%AE%89%E8%A3%85kali/b6dd4c62-1130-4a7c-9462-1e9e5f38dab2?auth=1

Zhihu’s answer can be found in the following link, which is also me:
https://zhuanlan.zhihu.com/p/151392411

======== Source address: https://blog.csdn.net/weixin_43347283/article/details/107006275 =====================

 

The following should be able to run the Linux subsystem normally.

The first startup will let you set up a user, I just hit enter. By default, the Root account will be used. Some people may not be used to log in as the root account, you can use

useradd [username] to add an account, and then use commands in PowerShell to modify the default login account.

Usage of useradd: https://www.cnblogs.com/zknublx/p/9360821.html

Set the default login user:

The new version of lxrun can no longer be used, and it has been replaced by WSLConfig.

For example, I first logged in as root, and then added an account with useradd adminabc.

Then turn off WSL, configure the WSL default login account as the adminabc added above under administrator privileges, so that there will be a home folder, and avoid terrorist operations such as rm / * -rf. Execute the following command:

ubuntu1804 config --default-user grf123

ubuntu1804 config --default-user adminabc

It is mainly the parameters of this config. If you have installed other distributions, remember to change them.

 

If you find that you can’t complete the command by pressing Tab, remember to execute bash. You know, what we usually use is actually in bash, which is different from the original terminal.

 

After installation, enter Ubuntu. The root directory is located in this directory. I have been looking for it for a long time:

C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState

After the default installation is complete, the Linux system is located on the system disk. If you look at the above directory, you can see that it is a virtual hard disk, which can be expanded, but it is not easy to shrink.

So I searched, how to modify the installation directory so that it can be installed on a disk with a relatively large space.

Original address: https://blog.csdn.net/w851685279/article/details/108904106?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduend~default-1-108904106.nonecase&utm_term=wsl2%E 6 %94%B9%E5%8F%98%E5%AE%89%E8%A3%85%E4%BD%8D%E7%BD%AE&spm=1000.2123.3001.4430

 

1. View installed linux distributions

wsl -l --all -v

2. Export the distribution version as a tar file to the d drive

wsl --export Ubuntu-20.04 d:\wsl-ubuntu20.04.tar

3. Unregister the current distribution

wsl --unregister Ubuntu-20.04

4. Re-import and install WSL on the D drive

wsl --import Ubuntu-20.04 d:\wsl-ubuntu20.04 d:\wsl-ubuntu20.04.tar --version 2

5. Set the default login user as the user name during installation

ubuntu2004 config --default-user USERNAME

6. Delete wsl-ubuntu20.04.tar

del d:\wsl-ubuntu20.04.tar

 

Well, now enter the world of Linux, let's start configuring the source first.

Fourth, configure the Linux update source

Don't think this paragraph is unimportant. In fact, the source of the Linux subsystem is not exactly the same as what we usually configure. In order to install a g++ I also tried several sources. There are also slight differences between Ali and Ali's source. This difference is reflected in the fact that one can install g++ and the other cannot.

Here is the source of my final installation of g++:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

Save everyone time.

Then I won't go into details about sudo apt update and the like.

5. Try to compile Android 7.

Why choose android 7, because I was familiar with 7 before, and the book I bought also used this version. So try 7 first. Of course, I didn't compile it successfully in the end, but I will make a record of the problems I encountered and the solutions for your reference.

The first is to obtain the Android source code. Due to well-known reasons, use the Tsinghua source:

https://mirror.tuna.tsinghua.edu.cn/help/AOSP/

Here is a description of the Tsinghua mirror image:

Refer to the Google tutorial  https://source.android.com/setup/build/downloading ,  just https://android.googlesource.com/ use all of  https://aosp.tuna.tsinghua.edu.cn/ them instead.

Since using the HTTPS protocol is safer and more convenient for us to handle flexibly, it is strongly recommended to use the HTTPS protocol to synchronize the AOSP image.

Due to the heavy CPU/memory load caused by AOSP mirroring, we have limited the number of concurrency, so it is recommended to:

  1. When syncing, the concurrency number should not be too high, otherwise a 503 error will appear, that is, the -jfollowing number should not be too large, and it is recommended to choose 4.
  2. Please try to choose staggered peak synchronization when the traffic is small.
  • 2017-08-28 : Updated image size information
  • 2016-06-24 : close git:// protocol, only support HTTPS
  • 2016-04-03 : Remove redundant content in monthly init package, update usage
  • 2015-12-21 : Added monthly initialization package, fixed some document errors
  • 2015-10-13 : Fix upstream replacement documentation error
  • 2015-10-13 : Fix secondary image documentation error
  • 2015-10-09 : Restore access to git://aosp.tuna.tsinghua.edu.cn/aosp/
  • 2015-10-08 : Mirror address updated to https://aosp.tuna.tsinghua.edu.cn/ (without /android at the end)

 

If you need a certain version of the android code, use the following command:

 

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.0.1_r1

For the list of -b, you can refer to the "Source Code Marking and Listing" website, and I will list it here:

https://source.android.com/source/build-numbers#source-code-tags-and-builds

segmented version the branch Version supported devices
OPR5.170623.007 android-8.0.0_r17 Oreo Nexus 6P
OPR4.170623.009 android-8.0.0_r16 Oreo Nexus 5X
OPR3.170623.008 android-8.0.0_r15 Oreo Pixel XL、Pixel
OPR1.170623.027 android-8.0.0_r13 Oreo Pixel XL、Pixel、Pixel C
OPR6.170623.021 android-8.0.0_r12 Oreo Nexus Player
OPR6.170623.019 android-8.0.0_r11 Oreo Nexus 6P
OPR4.170623.006 android-8.0.0_r10 Oreo Nexus 5X
OPR3.170623.007 android-8.0.0_r9 Oreo Pixel XL、Pixel
OPR1.170623.026 android-8.0.0_r7 Oreo Pixel XL、Pixel、Pixel C
OPR6.170623.013 android-8.0.0_r4 Oreo Nexus 5X、Nexus 6P
OPR6.170623.012 android-8.0.0_r3 Oreo Pixel XL、Pixel
OPR6.170623.011 android-8.0.0_r2 Oreo Pixel XL、Pixel
OPR6.170623.010 android-8.0.0_r1 Oreo Pixel C
NZH54D android-7.1.2_r33 Nougat Pixel XL、Pixel

The latest one should have reached android11, but this website has not been updated yet, I will update it later. I choose the 7.1 version first:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.2_r33

 

Note: During repo sync, there may be errors due to network reasons:

This error is reported during repo sync, because the .git file in this path has not been downloaded.

Checking out projects:  88% (465/528) platform/prebuilts/clang/host/darwin-x86error: Cannot checkout platform/prebuilts/clang/host/linux-x86: ManifestInvalidRevisionError: revision refs/tags/android-7.1.2_r33 in platform/prebuilts/clang/host/linux-x86 not found

Because repo sync is easily affected by the network and fails, even domestic sources may fail, so you should sync several times until you are clearly told that the sync is successful, and then start compiling. If there is an error report, sync several times.

Fetching projects: 100% (529/529), done.
Checking out files: 100% (8484/8484), done.orm/prebuilts/sdkChecking out files:   2% (242/8484)
Checking out files: 100% (539/539), done.tform/system/coreChecking out files:  28% (154/539)
Checking out files: 100% (421/421), done.tform/system/tpmChecking out files:  18% (77/421)
Checking out files: 100% (15774/15774), done.m/test/vtsChecking out files:  44% (6985/15774)
Checking out files: 100% (25/25), done.latform/tools/external/fat32libChecking out files:  32% (8/25)
Checking out projects: 100% (528/528), done.
repo sync has finished successfully.

repo sync has finished successfully, so the code is completely synced. Don't worry, you can sync again. Then start compiling again. A few times before, I started compiling without sync, and all kinds of inexplicable errors occurred.

 

The solution is to enter this directory and execute repo sync. Let repo sync the current directory separately. At the end there is a "." parameter, which means to synchronize the current directory. In short, we must pay attention to the complete sync code before starting to compile.

 

Here is a compilation guide website:

https://developer.sony.com/develop/open-devices/guides/aosp-build-instructions/#build-aosp-nougat-7-1

In fact, you should check this kind of website as soon as possible. I also encountered a problem and couldn’t solve it. I found this website after searching everywhere, so I will release it here first. If you don't know how to compile Android, first read the relatively formal document above, and follow it step by step.

Here I copy the compilation steps of android 7:

To prevent errors generated by having the wrong version of Java installed on your computer, we will start by removing any conflicting Java version and adding the correct version. Java 8 is needed to build Android 7.x.x.

(People’s words: In order to avoid problems caused by the JAVA version, the Java 8 environment is required to compile the Android 7.xx version, and open-jdk is required, which is different from the earlier version. Simply put, the following steps first give the existing java to Cleared, then follow open-jdk8)

  1. On your computer: In a terminal window, enter the following command:
     
    sudo apt-get purge openjdk-* icedtea-* icedtea6-*
  2. A guide will appear on the screen. Follow the instructions to remove Java.
  3. Once Java is removed, install the correct version of Java by entering the following commands in a terminal window:
     
    sudo apt-get update sudo apt-get install openjdk-8-jdk java -version

    You should now see something similar to the following in your terminal window:

     
    java version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

 

After the Java environment is installed, you need to install various tool libraries required for compilation. Some can be successfully installed, some cannot be installed successfully, some need to update the source, and some need to find a substitute. Search it yourself.

sudo apt-get install bison g++-multilib git gperf libxml2-utils make zlib1g-dev:i386 zip liblz4-tool

 

Not much to say about the compilation steps. I also encountered some problems when compiling:

There is a prompt:
/bin/bash: prebuilts/misc/linux-x86/bison/bison: cannot execute binary file: Exec format error

 

It seems that the bison in this prebuilt directory cannot be executed. I went in and executed it and found that it really couldn't. The reason is that this application is a 32-bit program, and the runtime library needs to be installed to run it under 64-bit. Guess it is the thing with 386 above. Finally a solution was found here:

https://www.cnblogs.com/JiuHuan/p/10073632.html

Now able to run 32 bit programs. Then compile it again, report an error again, and can't find a good way to liberate it. I think there is still a gap between the Linux subsystem and the original one. Let this go, I'll try to compile android 10.

At present, the progress of compiling android 7 is here. I can't find a good solution. If someone knows what's going on, please give me a call.

 

6. Try to compile android 10

I think 10 is newer after all, maybe some outdated things are no longer used, maybe it can be edited. Please update this tutorial later.

Guess you like

Origin blog.csdn.net/grf123/article/details/103191996