How to Elegantly Roll Back from Arch Linux to Windows#
Background: How to Elegantly Migrate to Arch Linux.
Data Backup#
Just copying the previous article.
Use WeiPE and DiskGenius tools for data backup and partition cloning.
Since you may not be able to attend online classes or do exercises in the PE environment, we can first use DiskGenius's partition imaging feature to save the partition image to an external hard drive, then return to the Windows system and use DiskGenius to restore the partition image to the external hard drive (this is because partition imaging is a 4K/sequential read and write operation, while partition restoration is sequential read 4K/sequential write operation, and the small file read and write speed of solid-state drives is significantly greater than that of mechanical hard drives).
- Create a WeiPE environment.
- Enter the WeiPE environment and use DiskGenius for disk imaging operations.
- Restore the hard drive after installing Windows.
Install System#
Install it yourself.
Configure OI Environment#
CP Editor#
Go to the CP Editor official website to download the installation package, select Windows as the platform, choose v6.10.1 (as of August 18, 2022), and select corresponding architecture-setup.exe
, as we need to manually install the compiler.
MSYS2#
To use Clang-Format and Clangd, we need to use MSYS2 to install them. It seems that selecting architecture-setup-with-gcc-xxxx-llvm-xxxx.exe
is sufficient, but I haven't tested it.
- Go to the MSYS2 website, find the first step under Installation, Download the installer, and click the button to download the installer.
- Install MSYS2.
- Enter the MSYS2 Shell and type
pacman -S msys2-keychain
to install the keychain. - Type
pacman -Syu
to update the packages. - Type
pacman -S mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-make mingw64/mingw-w64-x86_64-gdb mingw64/mingw-w64-x86_64-clang mingw64/mingw-w64-x86_64-clang-tools-extra
to install the compiler. - Set environment variables.
- Set
MINGW_HOME
to your MSYS2 path (default isC:\msys2
) undermingw64
(for 64-bit computers) ormingw32
(for 32-bit computers), for example, for 64-bit set it toC:\msys2\mingw64
. - Set
C_INCLUDE_PATH
to%MINGW_HOME%\include
. - Set
LIBRARY_PATH
to%MINGW_HOME%\lib
. - Add
%MINGW_HOME%\bin
toPATH
.
- Set
Configure CP Editor#
-
Open CP Editor, click on
Options -> Settings
in the menu bar. -
Find
Language -> C++ -> C++ Command
, configure according to your preference; my configuration isg++ -Wall -Wextra -O2 -lm --std=gnu++14
for CCF compilation parameters. -
Find
Extensions -> Code Formatting -> Clang Format
, setClang Format Program
toclang-format
, and configure the style according to your preference. My settings are as follows:BasedOnStyle: Google IndentWidth: 4
-
Find
Extensions -> Language Server -> C++ Server
, check to enable it, and set the delay according to your preference; too short a delay may cause it to be unusable. My setting is1000ms
.
PowerShell 7 and oh-my-posh#
Install PowerShell#
Go to the PowerShell GitHub page, find the installer for your architecture in the latest Release, and install the latest PowerShell.
Configure Windows Terminal#
Download MesloLGM NF font and install it.
To use the GUI settings of Windows Terminal, you need to download Windows Terminal Preview from the Microsoft Store.
In Settings -> Profiles -> Defaults -> Additional Settings -> Appearance -> Text -> Font
, set the default font to Fira Code.
Install and Configure oh-my-posh#
- Search for
oh-my-posh
in the Microsoft Store and install it. - Open PowerShell, create a new
Powershell
folder under$Home\[My ]Documents
, and createMicrosoft.PowerShell_profile.ps1
under it, enteringoh-my-posh init pwsh | Invoke-Expression
.
WSL2#
Install Arch Linux#
-
Go to
Control Panel -> Programs -> Turn Windows features on or off
, checkWindows Subsystem for Linux
andVirtual Machine Platform
, and click OK. -
Restart your computer.
-
Go to this link to download and install the WSL2 upgrade package.
-
Open PowerShell and type
wsl --set-default-version 2
to set WSL to use WSL2 by default. -
Download LxRunOffline, extract it and add it to
PATH
. -
Download archlinux-bootstrap-x86_64.tar.gz.
-
Open a new PowerShell window and type
LxRunOffline i -n archlinux -f <bootstrap path> -d <storage location> -r root.x86_64
. -
Type
wsl --set-version archlinux 2
. Please ensure you have enabledVirtual Machine Platform
, and if your system supportsHyper-V
, please enable it. -
Type
wsl -d archlinux
to enter WSL. -
In PowerShell, type
wsl --shutdown archlinux && wsl -d archlinux
to restart and connect to WSL. -
In WSL, type
cd /etc && explorer.exe .
to open/etc
in File Explorer. -
Open
pacman.conf
, uncomment themultilib
source, and add thearchlinuxcn
source:[archlinuxcn] Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
-
Open
pacman.d/mirrorlist
and uncomment the domestic mirror sources. -
In WSL, type the following commands.
pacman -Syy pacman-key --init pacman-key --populate pacman -S archlinuxcn-keyring pacman -S base base-devel nano git wget
-
In WSL, type
passwd
to set the root password. -
Create a normal user and set a password.
useradd -m -G wheel -s /bin/bash <username> passwd <username>
-
Type
EDITOR=nano visudo
, uncomment%wheel ALL=(ALL:ALL) NOPASSWD: ALL
, pressCtrl+O Enter
to save, andCtrl+X
to exit. -
Type
id -u <username>
to query the ID of the newly created user; the first account should be1000
. -
Type
exit
to exit WSL. -
In PowerShell, type
LxRunOffline su -n archlinux -v <account id>
. -
Open PowerShell with administrator privileges, type
net stop LxssManager && net start LxssManager
to restart the WSL service. -
Open the Microsoft® Update Catalog, and download the latest
Windows Subsystem for Linux Update
(as of August 18, 2022,5.10.102.2
). -
Install the update, open PowerShell with administrator privileges, and type
wsl --shutdown && wsl -d archlinux
to restart WSL and enter WSL, then typeuname -a
to check the kernel version.
Install and Configure zsh and oh-my-zsh#
- Enter WSL.
- Type
pacman -S zsh
to install zsh. - Type
chsh
, enter the password, and switch the shell to/bin/zsh
. - Type
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
to install oh-my-zsh. - Type
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
to install the powerlevel10k theme. - Type
git clone https://ghproxy.com/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && git clone https://ghproxy.com/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
to install plugins. nano ~/.zshrc
, setZSH_THEME="powerlevel10k/powerlevel10k"
,plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
.- Exit and restart WSL.
KDE Plasma#
Basic Installation#
sudo pacman -Syu plasma
Basic Usage#
It is recommended to use GWSL to connect to Plasma. Search for GWSL
in the Microsoft Store. The GWSL in the national region is paid, but there is no difference between the trial version and the paid version, with no time limit and no payment required, but it is still recommended to support the author.
After downloading, open GWSL, click the icon on the taskbar to bring up the Dashboard. Click GWSL Distro Tools
, then enable Display/Audio Auto-Exporting
. GWSL supports placing Linux program windows on the Windows desktop, but I prefer to use a separate virtual desktop to place the entire Plasma.
To do this, you need to do the following:
- Create a new virtual desktop.
- Open GWSL on the newly created virtual desktop.
- Right-click the GWSL icon on the taskbar, select the top
XServer Profiles
, and chooseFullscreen Mode
. - A full-screen black window will appear on the virtual desktop; no action is needed, switch to another virtual desktop.
- Left-click the GWSL icon on the taskbar, select
Shortcut Creator
. - In the pop-up window, fill in
Shortcut Label
asKDE Plasma
, andShortcut Command
asdbus-launch startplasma-x11
. If you have multiple WSL containers, selectRun In
asarchlinux
(i.e., your container name). - Use the search tool to search for
KDE Plasma on archlinux
, open the folder, and copy the shortcut to the desktop to start Plasma. - Double-click the shortcut.
- Return to the virtual desktop where GWSL is in full screen, and you will find that Plasma has started.
Some Tricks#
After this configuration, there will be a problem:
- Switching virtual desktops will cause the GWSL window to minimize.
First, you need to have a Python 3.x environment installed and use python -m pip install pywin32 pyvda
to install the Win32 API and the module for operating virtual desktops.
One More Problem#
At this point, we will find that the GWSL window still minimizes when switching virtual desktops. Thanks to the new features of Windows 11, we can set different wallpapers on multiple virtual desktops. However, the icons on the desktop cannot be separated. My solution is not to place files on the desktop.
Solution#
We can still write a script to set the GWSL window to a non-minimized state using Python's Win32 API and the powerful pyvda library.
from pyvda import VirtualDesktop
import win32gui, win32con
import asyncio
hwnd_title = {}
WINDOW_NAME = 'VcXsrv Server - Display Qin Yuzhen\'s Notebook:0.0' # Please modify this to your window name
GWSL_VD_NUM = 2 # Please modify this to your virtual desktop number
DEBUG = False # Show debug information
def get_all_hwnd(hwnd, mouse) -> dict:
global hwnd_title
hwnd_title = {}
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})
async def main():
while True:
if VirtualDesktop.current().number != GWSL_VD_NUM:
await asyncio.sleep(0.1)
continue
win32gui.EnumWindows(get_all_hwnd, 0)
hwnd = win32gui.FindWindow(None, WINDOW_NAME)
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
if DEBUG:
print('Unminimized', hwnd)
await asyncio.sleep(0.1)
if __name__ == '__main__':
asyncio.run(main())
This code uses AsyncIO to un-minimize the window, with a 0.1s interval between each check.
Reference: Python Control Window on Top, Author: DG Xi.
To make the transition between windows less abrupt, we can change the desktop background to match Plasma.
WSA#
If you have already installed the Windows Subsystem for Android, please uninstall it first.
MagiskOnWSA with GApps#
As the name suggests, this allows you to run Magisk (root access) and GApps (Google Services Framework and Google Play, etc.) on the Windows Subsystem for Android.
Unfortunately, before this article was written, LSPosed/MagiskOnWSA had already been banned. However, we can use the script provided by LSPosed/MagiskOnWSALocal to compile it under Linux.
Using GitHub Actions (Recommended)#
If you have a GitHub account and know a bit about GitHub operations, it is recommended to use this method, although strictly speaking, this violates the terms of GitHub Actions and abuses the rights to build for free from open-source repositories. If your WSL container can access GitHub, it is recommended to compile manually.
The specific steps are as follows:
-
Fork LSPosed/MagiskOnWSALocal.
-
Create a new
workflows
folder under the.github
folder. -
Create a
.yml
file with any name in theworkflows
folder and paste the Workflow. The Workflow has been placed on Luogu Cloud Clipboard. -
Click on the
Actions
tab on the webpage to enable Actions. -
Refer to steps 8-14 below to select the configuration you need, then run the Workflow.
Manual Compilation (Not Recommended)#
This method requires a "good network environment."
The specific steps are as follows:
-
Use
wsl --install -d Ubuntu
to create a new Ubuntu container. -
Set the username and password in the new window.
-
Enter the following script to change to the Tuna source:
wget https://gitee.com/weizy1983/CNSolutions/raw/master/ubuntu/tunasource/UbuntuTunaSource.sh sudo chmod 777 UbuntuTunaSource.sh sudo ./UbuntuTunaSource.sh ubuntu20.04
-
Type
sudo apt-get install python3-pip winetricks -y
to install dependencies. -
Open a directory in WSL, such as
$Home\Documents
. -
Clone the Git repository by typing
git clone https://ghproxy.com/https://github.com/LSPosed/MagiskOnWSALocal
. -
Enter the repository directory and run
scripts/run.sh
, typebash scripts/run.sh
. -
When the
Build arch
selection page appears, use the default settings and press Enter to confirm. -
When the
WSA release type
appears, choose as needed; I choseinsider slow
/Beta Channel
, use the up and down keys to move, space to select, and Enter to confirm. -
Then for
Magisk version
, choose as needed; I choseBeta Channel
. -
Then it will ask
Do you want to install gapps?
chooseYes
, and press Enter to confirm. -
Then for
Variants of gapps
, since OpenGApps does not yet officially support Android 12, you can only choose Pico. -
Then choose
Do you want to keep amazon appStore?
, selectNo
, do not keep the Amazon App Store. -
For
Root solution
, chooseMagisk
as the root solution. -
The terminal will display your solution; just wait for it to complete.
ARCH=x64 RELEASE_TYPE=insider slow MAGISK_VER=beta GAPPS_VARIANT=pico REMOVE_AMAZON=remove ROOT_SOL=magisk
Installation#
Settings -> Privacy and Security -> Developer Options -> Enable Developer Options
.- Open your MagiskOnWSALocal directory, if you used GitHub Actions, download the Artifact and extract it to a folder.
- Right-click
Install.ps1
, open it with PowerShell, and wait for it to complete. - Search for and install WSATools from the Microsoft Store.
- Install Android SDK Platform Tools.
- Install a proxy software you like (if you do not have a "good network environment"), I use Clash for Android, then configure it.
- Enter Google Play Store, log in to your account, and install Microsoft Desktop.