LoginSignup
0
1

More than 1 year has passed since last update.

Ubuntu 22.04 LTS での headless な RDP の足掛かり

Last updated at Posted at 2023-02-08

概要

目次

 目次
   前書き
 本文
   ・gnome-shell, mutter
   ・gnome-screen-cast.py
   ・RDP クライアントの拡張ディスプレイ化
   変更した設定の戻し方
   ・gnome-monitor-config
 引用元、参照元、参考先

前書き

 GNOME における Wayland のディスプレイサーバーかつコンポジタ(コンポジッター)は Mutter だそうです。gnome-shell は Mutter に比べてさらに多くの依存関係を必要としているようです。従来の xorg や、Wayland の場合でも fedora(36以降) なら headless にできるみたいです。

本文

以下の内容は実験的なものになるため、実行は非推奨です。
※自己責任でお願いします。

gnome-shell, mutter

 以下のコマンドによる画面の追加は GNOME 42 の Ubuntu Desktop では認識しませんでした。
1.sudo systemctl start gdm3

bash
USER@servername:~$ gnome-shell --wayland --headless --virtual-monitor 1280x720 --no-x11 --replace

# または

USER@servername:~$ sudo apt install mutter
USER@servername:~$ mutter --wayland --headless --virtual-monitor 1280x720 --no-x11 --replace

---

Ubuntu Desktop ではなくて GNOME Shell になら headless に RDP で接続できます。

bash
# Ubuntu Desktop の終了
systemctl --user stop gnome-remote-desktop.service
sudo systemctl stop gdm3

# GNOME Shell を仮想ディスプレイ付きで起動
bash -c \
  "$( echo -e \
      'nohup gnome-shell --wayland --headless --virtual-monitor 1920x1080 --no-x11 >/dev/null 2>&1 &' \
       \\\n \
      'echo $! > /tmp/gnome-shell' )"
ps aux | xargs -a "/tmp/gnome-shell" grep

# キーリングの解錠、RDP サーバーの起動
bash ~/gdm3-key
systemctl --user start gnome-remote-desktop.service
systemctl --user status gnome-remote-desktop.service

# 終了
systemctl --user stop gnome-remote-desktop.service
xargs -a "/tmp/gnome-shell" kill
gnome-screen-cast.py

 次のスクリプトでは、仮想的なディスプレイを追加することができました。ただ headless はうまくいきませんでした。↓使用させていただいたもの
gnome-screen-cast.py ・使い方
gdm3-key

bash
USER@servername:~$ cd $HOME
USER@servername:~$ curl -sSL -o ~/gnome-screen-cast.py "https://gitlab.gnome.org/-/snippets/15/raw/master/gnome-screen-cast.py"
USER@servername:~$ sudo systemctl start gdm3
USER@servername:~$ bash ~/gdm3-key
   [Unlock Keyring] password for $(whoami): --completed--
   RDP:
           Status: enabled
           TLS certificate: /home/$(whoami)/.local/share/gnome-remote-desktop/rdp-tls.crt
           TLS key: /home/$(whoami)/.local/share/gnome-remote-desktop/rdp-tls.key
           View-only: no
           Username: $(whoami)
           Password: RDP_Password
   VNC:
           Status: disabled
           Auth method: prompt
           View-only: yes
           Password: (null)
USER@servername:~$ python3 ~/gnome-screen-cast.py -v 1280 720
   session path: /org/gnome/Mutter/ScreenCast/Session/u2
   stream path: /org/gnome/Mutter/ScreenCast/Stream/u2
   added
# 終了方法:[Ctrl C]
   interrupted
   pipeline: <Gst.Pipeline object at 0x7f2d2b598180 (GstPipeline at 0x55f0d07e20d0)>
   draining pipeline
   stopping

\\\\\\\\\\\\\\\\\\\\\\\
# または 
# USER@servername:~$ nohup sh -c 'exec python3 ~/gnome-screen-cast.py -v 1280 720' >/dev/null 2>&1 &
# 終了方法:jobs ; fg 1 ; [Ctrl C]

# もしくは
read back < <(bash -c \
  "$( echo -e \
      'nohup python3 ~/gnome-screen-cast.py -v 1280 720 >/dev/null 2>&1 &' \
       \\\n \
      'echo $!' \
  )") && echo PID:$back
ps aux | grep "$back"
kill "$back"
RDP クライアントの拡張ディスプレイ化

 次のコマンドで RDP 接続したクライアントの画面を(プライマリディスプレイのミラーとしてではなく)拡張ディスプレイとして使うことができます。※(解像度はクライアントに依存)

bash
# Key と Value の一覧表示
USER@servername:~$ gsettings list-recursively | grep "rdp"
   org.gnome.desktop.remote-desktop.rdp enable 'true'
   org.gnome.desktop.remote-desktop.rdp screen-share-mode 'mirror-primary'
   org.gnome.desktop.remote-desktop.rdp tls-cert '/home/$(whoami)/.local/share/gnome-remote-desktop/rdp-tls.crt'
   org.gnome.desktop.remote-desktop.rdp tls-key '/home/$(whoami)/.local/share/gnome-remote-desktop/rdp-tls.key'
   org.gnome.desktop.remote-desktop.rdp view-only 'false'

# 個々の設定されている Value の表示
USER@servername:~$ gsettings get org.gnome.desktop.remote-desktop.rdp screen-share-mode
   'mirror-primary'

# Value の範囲
USER@servername:~$ gsettings range org.gnome.desktop.remote-desktop.rdp screen-share-mode
   enum
   'mirror-primary'
   'extend'

# Value を設定
USER@servername:~$ gsettings set org.gnome.desktop.remote-desktop.rdp screen-share-mode extend

変更した設定の戻し方

 "Ubuntu 設定 → ディスプレイ" の開き方
(gnome-control-center display) &

bash
gsettings set org.gnome.desktop.remote-desktop.rdp screen-share-mode mirror-primary

sudo shutdown -r now

sudo systemctl start gdm3
bash ~/gdm3-key

# RDP で接続して手動で解像度変更
(gnome-control-center display) &

sudo systemctl stop gdm3
systemctl --user stop gnome-remote-desktop.service

sudo systemctl start gdm3
bash ~/gdm3-key

# RDP で再接続して確認
gnome-monitor-config

 ディスプレイの、プライマリを切り替えたり、配置を変えたり、解像度を変更したりできます。↓使用させていただいたもの
gnome-monitor-config

bash
# GitHub からリポジトリをコピー
sudo apt install git
git clone "https://github.com/jadahl/gnome-monitor-config.git" ~/gnome-monitor-config-master

# 諸々のツールをインストール
sudo apt install libcairo2 libcairo2-dev meson ninja-build cmake
sudo apt update && sudo apt upgrade -y
sudo reboot

# ビルド
USER@servername:~$ cd ~/gnome-monitor-config-master
USER@servername:~/gnome-monitor-config-master$ meson build && cd build
USER@servername:~/gnome-monitor-config-master/build$ meson compile && cd src

# できたものを home ディレクトリにコピー
USER@servername:~/gnome-monitor-config-master/build/src$ ls
USER@servername:~/gnome-monitor-config-master/build/src$ cp gnome-monitor-config ~/gnome-monitor-config
USER@servername:~/gnome-monitor-config-master/build/src$ ls -laF ~/gnome-monitor-config

使い方

bash
sudo systemctl start gdm3
bash ~/gdm3-key

~/gnome-monitor-config --help
| Usage: ./gnome-monitor-config [OPTIONS...] COMMAND [COMMAND OPTIONS...]
| Options:
|  -h, --help                  Print help text
| Commands:
|   list                       List current monitors and current configuration
|   set                        Set new configuration
|   show                       Show monitor labels
| Options for 'set':
|  -L, --logical-monitor       Add logical monitor
|  -x, --x=X                   Set x position of newly added logical monitor
|  -y, --y=Y                   Set y position of newly added logical monitor
|  -s, --scale=SCALE           Set scale of newly added logical monitor
|  -t, --transform=TRANSFORM   Set transform (normal, left, right, flip)
|  -p, --primary               Mark the newly added logical monitor as primary
|  -M, --monitor=CONNECTOR     Add a monitor (given its connector) to newly added logical monitor
|  -m, --mode                  1920x1080@60,000
-L : 論理モニターを追加する。
-p : 引数のモニターをプライマリディスプレイとする。
-M : -L(=論理モニター)に引数のモニターを接続する。
  -x : 引数のモニターの左辺が左端から何ドット目か指定する。
  -y : 引数のモニターの上辺を何ドット下降させるか指定する。
       ※通常は上辺同士が揃う。
       ※最も height が高いモニターを基準とする。
  -m : 解像度を指定する。
       ※ 横×縦@Hz.Hz

例)
# 設定値一覧
~/gnome-monitor-config list
# 解像度一覧
~/gnome-monitor-config list | awk '/Monitor/ {print $3,$5}; /id:/ {print $2,$3}'

# 使い方 (左から数える)
~/gnome-monitor-config set -LpM 1番目 -LM 2番目 -x num -LM 3番目 -x num

# HDMI-1を左から1番目、HDMI-2を2番目
 # 次の時、
    HDMI-1: 1920 1080
    HDMI-2: 1280 720
~/gnome-monitor-config set -LpM HDMI-1 -LM HDMI-2 -x 1920 -y 360

# プライマリディスプレイを切り替える
~/gnome-monitor-config set -LM HDMI-1 -LpM HDMI-2 -x 1920 -y 360

# 場所を入れ替える
 # HDMI-2を左から1番目、HDMI-1を2番目
~/gnome-monitor-config set -LM HDMI-2 -y 360 -LpM HDMI-1 -x 1280

# 解像度を変更する
 # id: の値を入力
~/gnome-monitor-config set -LpM HDMI-1 -m 1280x720@59.940200805664062 -LM HDMI-2 -x 1280
~/gnome-monitor-config set -LpM HDMI-1 -m 1920x1080@60 -LM HDMI-2 -x 1920 -y 360

# "Single Display" にする
# ※ x, y を指定してはいけない
~/gnome-monitor-config set -LpM HDMI-1

引用元、参照元、参考先

Headless native backend and virtual monitors
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1698
How to running headless mode on wayland?
・https://www. eddit.com/r/gnome/comments/xpadym/how_to_running_headless_mode_on_wayland/
Turn off the primary screen with wayland
・https://www. eddit.com/r/gnome/comments/zaunxf/turn_off_the_primary_screen_with_wayland/
桌面
https://cyp0633.icu/archives/1914#header-id-6
Bashシェルスクリプト上での `read` コマンドの便利な使い方いろいろ
https://genzouw.com/entry/2019/02/07/080311/775/
現在動作しているプログラムを調べるには
https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/027psax.html
Linuxコマンド(Bash)でバックグラウンド実行する方法のまとめメモ
https://qiita.com/inosy22/items/341cfc589494b8211844
とほほのAWK入門
https://www.tohoho-web.com/ex/awk.html#basic_syntax
git clone の際に clone 先のディレクトリを指定する方法
https://obel.hatenablog.jp/entry/20190824/1566650052

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1