投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2024年9月4日水曜日

【Raspberry Pi 5】ローカルディスプレイのデスクトップ画面をミラーリングするリモートデスクトップ接続の設定方法について

 ■ 概要

  ここでは、安全なローカルネットワーク上にあるRaspberry Pi 5 (Raspberry Pi OS)に、ローカルHDMIディスプレイに表示されるデスクトップをミラーリングしたリモートデスクトップ接続を行う手順を確認している。

 このリモートデスクトップ接続にはVNCを用いているが、Raspberry PiにHDMI接続したディスプレイで通常表示されるデスクトップ画面そのものをミラーリングして、リモートの環境で操作する方法を取り扱っている点が特徴的である。

 通常、ユーザーはRaspberry PiにHDMI接続したディスプレイに表示される画面でログインし、デスクトップ操作を行う。これらのユーザーをリモートからサポートするためには、上記のような方法でのリモートデスクトップ接続が必要である。


■ ローカル画面をミラーリングしてリモートデスクトップ接続するための設定


◯ ヘッドレスでラズパイが起動した場合に備えるための設定

 Raspberry Pi 5は、HDMIに関して初期設定のまま、ヘッドレス(HDMI接続ディスプレイなし)で起動すると、内部でローカル画面描画に関するシステムの機能の処理能力を制限するようである。そのためローカルディスプレイをミラーリングするリモートデスクトップの反応が非常に遅くなった。

 しかし、次のように、「video=HDMI-A-1:1920x1080@60D」という設定を次のファイルの次のような設定項目の最後に付けて、再起動を行うと問題が解消した。

# nano /boot/firmware/cmdline.txt

console=serial0,115200 console=tty1 root=PARTUUID=xxxxxxxx-02 rootfstype=ext4 fsck.repair=yes rootwait video=HDMI-A-1:1920x1080@60D

# reboot

 あるいは、この設定なしで、「ダミーHDMI」のドングルをRaspberry Pi 5のHDMIポートに取り付けておいても、ヘッドレスでもローカル画面をミラーリングしたリモートデスクトップを快適に使うことができた。


◯ x11vncのインストール

# apt install x11vnc -y

以下の追加パッケージがインストールされます:
  liblzo2-2 libtcl8.6 libtk8.6 libvncclient1 libvncserver1 tcl tcl8.6 tk tk8.6
提案パッケージ:
 tcl-tclreadline
以下のパッケージが新たにインストールされます:
  liblzo2-2 libtcl8.6 libtk8.6 libvncclient1 libvncserver1 tcl tcl8.6 tk tk8.6 x11vnc                    
アップグレード: 0 個、新規インストール: 10 個、削除: 0 個、保留: 0 個。



◯ リモート接続時のパスワードを設定

# mkdir /etc/x11vnc
# touch /etc/x11vnc/passwd

# x11vnc -storepasswd /etc/x11vnc/passwd

Enter VNC password: 
Verify password:    
Write password to /etc/x11vnc/passwd?  [y]/n y
Password written to: /etc/x11vnc/passwd

 ここで、設定したパスワードを「共通VNCパスワード」と呼ぶことにする。



◯ Raspberry Pi 5に割り当てられているIPアドレスの確認

# ip a | grep inet

 ネットワーク環境に依るが、192.168.X.Xのようなアドレスが割り当てられていることが多い。これをメモしておく。リモート接続の際に使用する。



◯ (動作テスト) x11vncの起動(display 0にアタッチ)

 Linuxでは、X ServerというシステムがGUIの画面を取り扱う。(X Serverが、マウス、キーボード入力の受け取り、画面の描画などを担当する。)Linuxでは、このX Serverというシステムを複数起動させることができる。複数のX Serverのうちから一つを指定するための番号が、display番号と呼ばれるものである。

 通常、display番号「0」が参照するX Serverは、ローカルでGUIへのログインを担当する「ウインドウマネージャー」の画面を取り扱っている。そこで、後に示すコマンド(★)を用いて、display番号「0」が参照するX Serverに、x11vncをアタッチする。これによって、ログイン画面をVNC経由でミラーリングできるようになる

 また、この方法で、ログイン後のデスクトップ環境の画面も、引き続きVNC経由でミラーリングできる。つまり、display番号「0」が参照するX Serverは、最初はログインを担当するウインドウマネージャーの画面を取り扱っているが、ログインに成功すると、そのままそのユーザーのデスクトップ画面を取り扱うということである

 次の図の仕組みによって、ローカル側GUI画面と、リモート側画面がミラーリングされる。

(ローカル側画面)X Server(0) ← X11Vnc(5900) ← == ネット== ←Vnc Client (リモート側画面)

(★)

# x11vnc -auth guess -display :0 -rfbauth /etc/x11vnc/passwd -rfbport 5900 -forever -loop -xkb -noxdamage -repeat -shared

 --- x11vnc loop: 1 ---

 --- x11vnc loop: waiting for: 2622

24/06/2024 09:53:37 passing arg to libvncserver: -rfbauth
24/06/2024 09:53:37 passing arg to libvncserver: /home/user01/.vnc/passwd
24/06/2024 09:53:37 passing arg to libvncserver: -rfbport
24/06/2024 09:53:37 passing arg to libvncserver: 5900
24/06/2024 09:53:37 x11vnc version: 0.9.16 lastmod: 2019-01-05  pid: 2622
xauth:  file /root/.Xauthority does not exist
24/06/2024 09:53:37 -auth guess: using 'XAUTHORITY=/var/run/lightdm/root/:0' for disp=':0'
24/06/2024 09:53:37 Using X display :0
24/06/2024 09:53:37 rootwin: 0x39f reswin: 0x600001 dpy: 0x72803770
24/06/2024 09:53:37 
24/06/2024 09:53:37 ------------------ USEFUL INFORMATION ------------------
24/06/2024 09:53:37 
24/06/2024 09:53:37 Wireframing: -wireframe mode is in effect for window moves.
24/06/2024 09:53:37   If this yields undesired behavior (poor response, painting
24/06/2024 09:53:37   errors, etc) it may be disabled:
24/06/2024 09:53:37    - use '-nowf' to disable wireframing completely.
24/06/2024 09:53:37    - use '-nowcr' to disable the Copy Rectangle after the
24/06/2024 09:53:37      moved window is released in the new position.
24/06/2024 09:53:37   Also see the -help entry for tuning parameters.
24/06/2024 09:53:37   You can press 3 Alt_L's (Left "Alt" key) in a row to 
24/06/2024 09:53:37   repaint the screen, also see the -fixscreen option for
24/06/2024 09:53:37   periodic repaints.
24/06/2024 09:53:37 
24/06/2024 09:53:37 XFIXES available on display, resetting cursor mode
24/06/2024 09:53:37   to: '-cursor most'.
24/06/2024 09:53:37   to disable this behavior use: '-cursor arrow'
24/06/2024 09:53:37   or '-noxfixes'.
24/06/2024 09:53:37 using XFIXES for cursor drawing.
24/06/2024 09:53:37 GrabServer control via XTEST.
24/06/2024 09:53:37 
24/06/2024 09:53:37 Scroll Detection: -scrollcopyrect mode is in effect to
24/06/2024 09:53:37   use RECORD extension to try to detect scrolling windows
24/06/2024 09:53:37   (induced by either user keystroke or mouse input).
24/06/2024 09:53:37   If this yields undesired behavior (poor response, painting
24/06/2024 09:53:37   errors, etc) it may be disabled via: '-noscr'
24/06/2024 09:53:37   Also see the -help entry for tuning parameters.
24/06/2024 09:53:37   You can press 3 Alt_L's (Left "Alt" key) in a row to 
24/06/2024 09:53:37   repaint the screen, also see the -fixscreen option for
24/06/2024 09:53:37   periodic repaints.
24/06/2024 09:53:37 X FBPM extension not supported.
24/06/2024 09:53:37 X display is capable of DPMS.
24/06/2024 09:53:37 --------------------------------------------------------
24/06/2024 09:53:37 
24/06/2024 09:53:37 Default visual ID: 0x21
24/06/2024 09:53:37 Read initial data from X display into framebuffer.
24/06/2024 09:53:37 initialize_screen: fb_depth/fb_bpp/fb_Bpl 24/32/4096
24/06/2024 09:53:37 
24/06/2024 09:53:37 X display :0 is 32bpp depth=24 true color
24/06/2024 09:53:37 
24/06/2024 09:53:37 Listening for VNC connections on TCP port 5900
24/06/2024 09:53:37 Listening for VNC connections on TCP6 port 5900
24/06/2024 09:53:37 listen6: bind: Address already in use
24/06/2024 09:53:37 Not listening on IPv6 interface.
24/06/2024 09:53:37 fb read rate: 468 MB/sec
24/06/2024 09:53:37 fast read: reset -wait  ms to: 10
24/06/2024 09:53:37 fast read: reset -defer ms to: 10
24/06/2024 09:53:37 The X server says there are 10 mouse buttons.
24/06/2024 09:53:37 screen setup finished.
24/06/2024 09:53:37 

The VNC desktop is:      raspberrypi:0
PORT=5900

******************************************************************************
Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?

The scheme stores pixel data offscreen on the VNC viewer side for faster
retrieval.  It should work with any VNC viewer.  Try it by running:

    x11vnc -ncache 10 ...

One can also add -ncache_cr for smooth 'copyrect' window motion.
More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching



◯ (動作テスト) リモート接続

 他の端末から、先程確かめたRaspberry Pi 5のアドレス「192.168.X.X」にVNCで接続する。

 今回は、別のLinux端末のTigerVNCクライアントアプリケーションを使って接続した。このとき指定アドレスとポートを次のように指定した。

「192.168.X.X:0」もしくは「192.168.X.X:5900

 先程設定した「共通VNCパスワード」を入力すると、次のようにリモートの操作画面が開いた。

 ここで、ユーザー名(user01)、そのパスワードを入力した。


 すると、次のようにユーザー「user01」のMATEデスクトップ環境の画面に遷移した。



 さらに、ログアウト後、再びログインすることも問題なくできた。

 複数のVnc Clientを接続して、1対多でミラーリングすることもできた。



◯ システム起動時にリモート接続機能を自動起動させる設定

 以上で、手動でコマンドを実行することによって、ローカル画面をミラーリングしてリモートデスクトップを許可する仕組みを整えられたことを確認した。ここでは、このコマンドをシステム起動時に自動で起動するための設定を行う。

 まず、次のように設定ファイルを作成する。この設定ファイル名がサービス名として使用される。X Server(Display番号0)にアタッチするx11vncサービスということから「x11vnc_0」とした。

# nano /etc/systemd/system/x11vnc_0.service

[Unit]
Description=x11vnc (Remote access to X Server 0)
After=network-online.target

[Service]
Type=simple
ExecStart=x11vnc -auth guess -display :0 -rfbauth /etc/x11vnc/passwd -rfbport 5900 -forever -loop -xkb -noxdamage -repeat -shared
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=graphical.target


# systemctl daemon-reload
# systemctl enable x11vnc_0

Created symlink /etc/systemd/system/graphical.target.wants/x11vnc_0.service → /etc/systemd/system/x11vnc_0.service.

# reboot

 システムの再起動後、しばらく待つと、テスト動作と同様にしてVNCクライアントからユーザー「user01」のログインを経て、MATEデスクトップ環境を操作できた。



<参考>

● ディスプレイマネージャー
・What is the greeter?/A greeter is a graphical login interface. It's also often called the login screen.
< https://askubuntu.com/questions/1027145/what-is-the-greeter > 2024年6月17日

・LightDM/Greeter
< https://wiki.archlinux.org/title/LightDM > 2024年6月17日


● リモートアクセス
・【備忘録】Ubuntu20.04でx11vncセットアップ
< https://qiita.com/moootoko/items/a489279c26cae68d60d6 > 2024年6月24日


● HDMI出力
・Bullseye vncserver is very slow without display
< https://forums.raspberrypi.com/viewtopic.php?t=323294 > 2024年9月11日

・Extremely slow VNC response in Chromium - Bookworm (Raspberry 5 using X11)
< https://forums.raspberrypi.com/viewtopic.php?t=366262 > 2024年9月11日

投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad