有一台过于强悍的ARM软路由,但是较为合适的系统只有OpenWRT,故可使用chroot构建一个桌面环境来利用多余性能。

首先,通常OpenWRT默认的shell为ash,在chroot后会因为找不到子系统的ash而切换失败,需要替换默认的shell为bash,通过$SHELL环境变量可以查看当前的shell:

echo $SHELL

如果已经是/bin/bash,则无需手动安装,否则需要使用opkg安装bash并手动设置:

opkg update && opkg install bash

之后修改/etc/passwd中root行的/bin/ash为/bin/bash即可。
接下来可以开始安装debian子系统,假设存放路径为/debian,版本使用debian10(buster),构架使用arm64,配置清华源:

opkg install debootstrap
mkdir /debian
debootstrap --arch=arm64 buster /debian http://mirrors.tuna.tsinghua.edu.cn/debian

debootstrap将子系统安装完毕后,需手动将/proc、/sys、/dev添加到子系统的目录中:

mount -o bind /proc /debian/proc
mount -o bind /sys /debian/sys
mount -o bind /dev /debian/dev
mount -o bind /dev/pts /debian/dev/pts

注意,重启后上述挂载目录失效,需要重新挂载,当然也可以添加到OpenWRT的启动脚本中。
之后就可以使用chroot切换至debian环境了:

chroot /debian

如果需要将这个切换的终端在后台保持,可配合screen命令(可使用opkg install screen安装)使用:

screen -S myterminal
chroot /debian

之后可通过按下Ctrl+A后再按下D将终端切换回后台。再使用

screen -r myterminal

返回该终端。
使用screen将终端搁置到后台后,当前登录的终端即使退出了,debian中的程序仍然会保持在后台运行,这样就可以在debian中配置桌面和vnc,再从外部连接到该桌面了。
安装xfce4桌面和vncserver:

apt-get update && apt-get upgrade -y
apt-get install xfce4 tightvncserver

安装完成后配置vncserver:
先直接运行vncserver以生成配置文件,这里将要求设置vnc的连接密码,此部分日志记录如下:

root@RLink:~# vncserver

You will require a password to access your desktops.

Password:
Warning: password truncated to the length of 8.
Verify:
Would you like to enter a view-only password (y/n)? n
xauth:  file /root/.Xauthority does not exist
xauth: (argv):1:  bad display name "RLink:1" in "add" command
xauth:  file /root/.Xauthority does not exist

New 'X' desktop is RLink:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/RLink:1.log

之后会默认创建:1(端口5901),已可以使用vnc登录,但是并不显示桌面。故需先将该桌面kill掉:

vncserver -kill :1

然后修改启动脚本:在~/.vnc/xstartup中添加一行:startxfce4 &
使该文件应为如下内容:

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
startxfce4 &

之后再次运行vncserver,便可从外部连接到该桌面了。该终端可使用Ctrl+A、D搁置到后台,保持程序继续运行。
如果需要调整分辨率,可以在运行vncserver时指定分辨率,如:

vncserver -geometry 1920x1080

如果桌面的虚拟终端无法打开(常见的情况为安装时未安装虚拟终端),可以在终端中安装xfce4-terminal。
如果出现文本显示问题,可以安装locales之后通过dpkg-reconfigure locales重新配置编码方式,一般选择UTF-8即可,以生成相关配置文件,之后将export LANG=C.UTF-8写入~/.profile文件中,并source .profile使其生效,再重新打开桌面。之后需要安装相应的字体文件,可以通过apt安装(如apt-get install fonts-wqy-zenhei),也可以将其他字体拷贝到/usr/share/fonts/truetype/下即可。

[以下内容更新于2020.4.14]
如果提示cannot change locale,则说明子系统的语言配置与主系统不符,或子系统的语言配置出现问题。
在子系统中先安装locales,再使用dpkg-reconfigure重新配置locale即可:

apt-get update && apt-get install locales
dpkg-reconfigure locales

按照主系统中相同配置即可。通常可在生成配置一栏勾选en_US.UTF-8和zh_CN.UTF-8,之后默认语言环境选择C.UTF-8即可。

标签: Linux, OpenWRT

添加新评论