「Termux」给手机安装一个Ubuntu图形化桌面

原创

本文最后更新于 <span id="expire-date"></span> 天前,文中部分描述可能已经过时。

这里以 Ubuntu 和 Xfce4 为例,已解决中文乱码和没声音的问题,视频演示效果见后文。

使用 tmoe-linux 简化操作

现在已经有 2moe 大佬维护的脚本及镜像,不必自己一步一步安装那么麻烦。

以下命令三选一,获取他的脚本,按照显示的菜单进行后续安装。

bash -c "$(curl -L git.io/linux.sh)"
bash -c "$(curl -L l.tmoe.me)"
bash -c "$(curl -L https://gitee.com/mo2/linux/raw/2/2)"

手机没有 root 则选择 proot 容器;
有 root 可选 chroot 容器。(实际上并不推荐给予 Termux root 权限,很危险!)

可选安装 Debian、Arch、Fedora、Ubuntu、Deepin、Kali 等发行版。

IMG_20210406_072431

有问题请去 GithubGitee 反馈。

当然最好还是在自己的电脑上体验完整的的 Linux 系统,arm64 版移植系统体验很糟糕,各种报错😣,Ubuntu、Kali 等发行版都提供 live 镜像,可以试用之后再考虑是否实机安装。顺便强烈推荐 Ventoy ,比 Rufus 等启动盘制作工具更舒服。


以下是旧文。

首次安装请尽量在网络通畅的情况下进行,换国内源可能遇到各种各样的问题。

爪机信息:

点击展开
  • OS: Android 10
  • Device: Redmi Note 7 (lavender)
  • ROM: QQ3A.200805.001
  • Baseband: msm
  • Kernel: aarch64 Linux 4.4.238-OniiChanKernel-Faham-X-12.0+
  • CPU: Qualcomm Technologies, Inc SDM660
  • GPU: Qualcomm Technologies, Inc SDM660
  • RAM: 3346MiB / 3728MiB

安装 Ubuntu

  1. 安装 AnLinux app

  2. 安装 Ubuntu (你也可以尝试其它组合,成败随缘)

    点击展开

    打开 AnLinux 的仪表盘,选择推荐的第一个 Ubuntu,得到以下命令并在 Termux 中运行
    pkg install wget openssl-tool proot -y && hash -r && wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/Installer/Ubuntu/ubuntu.sh && bash ubuntu.sh

    等待几分钟……安装完成。

  3. 启动 Ubuntu

    ./start-ubuntu.sh
  4. 初始化操作

    apt-get update&&apt-get upgrade
    apt-get install sudo
    sudo apt-get install curl wget unzip unrar screenfetch -y
  5. 给我们的 Ubuntu 安装一个 micro 文本编辑器,比 vim 容易上手。(后面会用到)

    点击展开
    cd ../bin
    curl https://getmic.ro | bash

    144044461

  6. 声卡驱动

    • 安装 pulse

      sudo apt install pulseaudio
      sudo apt install pavucontrol
    • 查看声卡ID和名字

      pactl list sources short

      报错:

      Connection failure: Connection refused
      pa_context_connect() failed: Connection refused

      试试 pulseaudio --start

      W: [pulseaudio] main.c: This program is not intended to be run as root (unless --system is specified).

      好像不理它也能用,或者参考一下这篇 pulseaudio run as root [duplicate]
      重新查看声卡ID和名字,显示:
      0 auto_null.monitor module-null-sink.c s16le 2ch 44100Hz SUSPENDED
      似乎能用的样子。

    • 但我们还需要修改配置文件,使用前面安装的 micro 编辑器打开它

      micro ../etc/pulse/default.pa

      最后一行写上
      load-module module-simple-protocol-tcp rate=44100 format=s16le channels=2 source=0 record=true port=12345
      只用一行,不要回车断开。
      rate、format、source 分别改成前面获取的数据,分别对应音频采样率、声卡名字、声卡ID,端口随意,别被占用就行。
      Ctrl+S 保存,Ctrl+Q 退出。
      pulseaudio --start 重启 pulse 服务

    安装并打开 Simple Protocol Player
    如果是本机,ip 填 localhost 或者 127.0.0.1,端口和采样率按照刚才的参数填写。

解决中文乱码

  1. 安装中文支持包language-pack-zh-hans:
    sudo apt-get install language-pack-zh-hans
  2. micro ../etc/environment(在文件的末尾追加):
    LANG="zh_CN.UTF-8"
    LANGUAGE="zh_CN:zh:en_US:en"
  3. micro ../var/lib/locales/supported.d/local 同样在文件末尾添加:
    en_US.UTF-8 UTF-8
    zh_CN.UTF-8 UTF-8
    zh_CN.GBK GBK
    zh_CN GB2312
  4. 最后执行命令 sudo locale-gen,显示:
    Generating locales (this might take a while)...
    en_US.UTF-8... done
    zh_CN.GB2312... done
    zh_CN.GBK... done
    zh_CN.UTF-8... done
    zh_SG.UTF-8... done
    Generation complete.
    中文字体生效 😃

安装 VNC Viewer

wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/DesktopEnvironment/Apt/Xfce4/de-apt-xfce4.sh && bash de-apt-xfce4.sh
这个比较慢,下载的资源包有几百兆,解压之后占用一两个 G。

安装过程中还有一些选项需要指定:

  • 语言和键盘布局: 选 English 或者 Chinese 好像区别不大,就算选择中文且前面已经安装中文语言包并进行配置,它实际上还是默认显示英文。(至少中文乱码问题解决了 😌)
  • Display Manager: gdm3 和 light,遇事不决选默认。
  • vncserver 的密码: 在后续使用 VNC Viewer 的过程中会用到,别起 123456 这么简单的,随便掺点英文组合。

有时还会安装出错,使用 VNC 远程连接桌面发现黑屏,中间一个方块,似乎是由于网络问题导致的下载文件不全,换网、洗把脸、重新安装就好了。

报错信息
vncserver-stop. 100%[=====>]     100  --.-KB/s    in 0s

2020-11-18 08:13:36 (469 KB/s) - ‘/usr/local/bin/vncserver-stop.1’ saved [100/100]

You can now start vncserver by running vncserver-start
It will ask you to enter a password when first time starting it.
The VNC Server will be started at 127.0.0.1:5901 You can connect to this address with a VNC Viewer you prefer
Connect to this address will open a window with Xfce4 Desktop Environment


Running vncserver-start


To Kill VNC Server just run vncserver-stop


/usr/local/bin/vncserver-start: line 4: vncserver: command not found
root@localhost:~# vncserver-start
/usr/local/bin/vncserver-start: line 4: vncserver: command not found

连接桌面

  • 建议安装火狐浏览器。Chrome 我这里没有安装成功,Edge 没有 Linux 版。
    sudo apt-get install firefox

常规启动

  • Termux 运行
    ./start-ubuntu.sh
    vncserver-start
    pulseaudio --start
  • Simple Protocol Player 播放
  • 本机 VNC Viewer 新建会话
    ip 地址:127.0.0.1:1 (具体 ip 和端口看自己终端启动相关服务时显示的信息)
    名称随意,最后输入刚才设置的密码进行连接,不加密就不加密吧,无妨。
    如果不能连接,检查相关服务是否正常开启且未被杀后台

视频演示

流畅度比预料中好一些。

如果想用电脑进行远程连接获得更好的大屏效果,启动时使用 vncserver -geometry 1920x1080 修改分辨率,但 WIFI 速度不够或者设备性能不足的情况下,视频播放时会断层加载。


2020.12.28
睿站的初审应该和二审打一架 😑
IMG_20201219_132258

待解决的问题

  • sudo apt-get install -y npm
  • Sudo: setrlimit(RLIMIT_CORE): Operation not permitted

    试试 micro ../etc/sudo.conf,填写:

    Set disable_coredump false
  • sudo apt install -y snapd

    安装成功,但使用 snap 命令时总是卡住
    安装软件时发送的请求也全部跑到 localhost 去了

    root@localhost:~# sudo snap install telegram-desktop       error: cannot communicate with server: Post http://localhost/v2/snaps/telegram-desktop: dial unix /run/snapd.socket: connect: no such file or directory
    root@localhost:~# systemctl restart snapd
    System has not been booted with systemd as init system (PID 1). Can't operate.
    Failed to connect to bus: Host is down

    参考 Snap cannot communicate with server

  • sudo apt install scrcpy

    能否控制另一部手机?有待测试……

  • # cd ..
    # du -h --max-depth=1
    # 其它分区读取正常

    du: cannot access './proc/24757/net/nf_conntrack_expect': Permission denied

    linux下root目录满导致整个分区数据满:挂载硬盘扩容

  • 点击展开
    [2020.11.21 08:32:30] Launched version: 2000001, install beta: [FALSE], alpha: 0, debug mode: [FALSE], test dc: [FALSE]
    [2020.11.21 08:32:30] Executable dir: /usr/bin/, name: telegram-desktop
    [2020.11.21 08:32:30] Initial working dir: /root/
    [2020.11.21 08:32:30] Working dir: /root/.local/share/TelegramDesktop/
    [2020.11.21 08:32:30] Command line: telegram-desktop --
    [2020.11.21 08:32:30] Executable path before check: /usr/bin/telegram-desktop
    [2020.11.21 08:32:30] Logs started
    [2020.11.21 08:32:30] Launcher filename: telegramdesktop.desktop
    [2020.11.21 08:32:30] Checking for XDG Desktop Portal...
    [2020.11.21 08:32:30] XDG Desktop Portal is not present :(
    [2020.11.21 08:32:31] Connecting local socket to /tmp/runtime-root/c8a98f2fe164925688f81a251c978b91-{87A94AB0-E370-4cde-98D3-ACC110C5967D}...
    [2020.11.21 08:32:31] This is the only instance of Telegram, starting server and app...
    [2020.11.21 08:32:31] Could not copy '/root/.local/share/TelegramDesktop/log_start0.txt' to '/root/.local/share/TelegramDesktop/log.txt' to start new logging!

本文作者:青菜芋子

本文链接: https://loafing.cn/posts/Termux-Ubuntu-GUI.html

文章默认采用 CC BY-NC-SA 4.0 许可协议,如有转载请注意遵循。

评论

您所在的地区可能无法访问 Disqus 评论系统,请切换网络环境再尝试。