参考博客

WSL2 安装 GUI,并使用 XRDP实现连接(内含汉化操作)

Ubuntu换阿里云源

备份系统源

cp /etc/apt/sources.list /etc/apt/sources.list.backup

清空源

> /etc/apt/sources.list

添加阿里云源

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

刷新应用源

sudo apt update

升级操作

注意:应当按需操作

#sudo apt upgrade

XRDP安装与配置

安装xrdp

sudo apt install xrdp 

备份配置

sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.backup

修改xrdp配置

## 修改 xrdp 的远程连接端口为3390 (原3389是win默认的远程端口,避免和本机远程访问冲突)
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
## 修改 位/像素(bpp)
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini

XFCE4安装与配置

安装xfce4及拓展组件

sudo apt install -y xfce4 xfce4-goodies

指定 x windows system 启动使用我们安装的 xfce4

echo xfce4-session > ~/.xsession
# 修改 xrdp 的窗口管理器的启动脚本 
sudo vim /etc/xrdp/startwm.sh

## 注释掉最后两行(test 和 exec 开头)
#test -x /etc/X11/Xsession && exec /etc/X11/Xsession
#exec /bin/sh /etc/X11/Xsession

脚本顶部及底部添加

## 顶部添加,防止xrdp连接闪退
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
$HOME/.profile

// ...

## 底部添加,启动xfce4
startxfce4

完整配置文件示例参考(修改后)

#!/bin/sh
# xrdp X session start script (c) 2015, 2017 mirabilos
# published under The MirOS Licence

## 防止连接xrdp,输入账号密码后闪退
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
$HOME/.profile

if test -r /etc/profile; then
. /etc/profile
fi

if test -r /etc/default/locale; then
. /etc/default/locale
test -z "${LANG+x}" || export LANG
test -z "${LANGUAGE+x}" || export LANGUAGE
test -z "${LC_ADDRESS+x}" || export LC_ADDRESS
test -z "${LC_ALL+x}" || export LC_ALL
test -z "${LC_COLLATE+x}" || export LC_COLLATE
test -z "${LC_CTYPE+x}" || export LC_CTYPE
test -z "${LC_IDENTIFICATION+x}" || export LC_IDENTIFICATION
test -z "${LC_MEASUREMENT+x}" || export LC_MEASUREMENT
test -z "${LC_MESSAGES+x}" || export LC_MESSAGES
test -z "${LC_MONETARY+x}" || export LC_MONETARY
test -z "${LC_NAME+x}" || export LC_NAME
test -z "${LC_NUMERIC+x}" || export LC_NUMERIC
test -z "${LC_PAPER+x}" || export LC_PAPER
test -z "${LC_TELEPHONE+x}" || export LC_TELEPHONE
test -z "${LC_TIME+x}" || export LC_TIME
test -z "${LOCPATH+x}" || export LOCPATH
fi

if test -r /etc/profile; then
. /etc/profile
fi

## 注释当前两行
#test -x /etc/X11/Xsession && exec /etc/X11/Xsession
#exec /bin/sh /etc/X11/Xsession

## 添加命令
startxfce4

启动Xrdp服务

sudo /etc/init.d/xrdp start 
## 或
systemctl start xrdp

开机启动xrdp

电脑下依然先执行wsl启动ubuntu才可以

systemctl enable xrdp

汉化

参考博客进行汉化,没有成功. 后续在研究!

安装基本的字体文件

sudo apt-get install fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho fonts-ipafont-gothic fonts-unfonts-core

安装语言包等组件

sudo apt-get install language-pack-zh* 
sudo apt-get install chinese*
sudo apt-get install language-selector-common

设置系统默认语言

提示local未安装,则:sudo apt install locales -y

可参考当前博客配置中文
dpkg–reconfigure locales命令问题

#sudo dpkg-reconfigure local es