Raspberry PiにUbuntuをインストールし、デスクトップ環境を構築する際のメモ。

本文章での前提条件・考慮事項は次のとおり。

初回起動までのインストール手順、個別のソフトウェアの設定等については省略しているため、適宜Ubuntu 22.04のインストールを参照のこと。

初期設定

必需ツール類のインストール

以下のコマンドで一括してインストールする。 インストール目的等については省略。

aptで必需ツール類をインストールする
$sudo apt install curl git rsync tree

ここでインストールする各パッケージの概要は次のとおり。

インストールするパッケージと概要
パッケージ名 概要
curl URL 文法でデータを転送するコマンドラインツール
git 速く、スケーラブルな分散型リビジョン管理システム
rsync 高速で多目的なリモート (兼ローカル) ファイル複製ツール
tree displays an indented directory tree, in color
パッケージ名 概要

dotfiles

これはごく個人的な設定をまとめたものであるため、そのまま使用することは推奨しない。

dotfilesを展開する
$git clone https://github.com/smdn/smdn.git smdn-dotfiles
$smdn-dotfiles/etc/home/smdn/deploy-dotfiles.sh

スワップ頻度の最小化

ここではスワップ頻度を0に設定する。 なお現在の設定値はcat /proc/sys/vm/swappinessで確認できる。

/etc/sysctl.confに以下の内容を追記する。

/etc/sysctl.conf
vm.swappiness = 0

sysctl -pで変更を反映させる。 また、正しく変更されたかを確認。

$cat /proc/sys/vm/swappiness 
60

$sudo sysctl -p
vm.swappiness = 0

$cat /proc/sys/vm/swappiness 
0

swapoffコマンドによるスワップの停止したあと/swapfileを削除することで、スワップを完全に無効化する方法については、再起動後に/swapfileが復活してしまうため、うまく行かなかった。 別の環境で試す際の参考として、左記を試行した際の手順を残す。


まず、swapon --showおよびfreeコマンドで、現在のスワップの状況を調べる。

スワップの状況を調べる
$sudo swapon --show
NAME      TYPE  SIZE USED PRIO
/swapfile file 1024M   0B   -2

$free -h
               total        used        free      shared  buff/cache   available
Mem:           7.8Gi       1.7Gi       4.9Gi       138Mi       1.5Gi       6.1Gi
Swap:          1.0Gi          0B       1.0Gi

続いて、swapoff -aコマンドでスワップを停止する。 freeコマンドでは、スワップのサイズが0となる。

スワップを停止する
$sudo swapoff -a

$free -h
               total        used        free      shared  buff/cache   available
Mem:           7.8Gi       2.5Gi       4.0Gi       184Mi       1.6Gi       5.3Gi
Swap:             0B          0B          0B

不要になったスワップファイルを削除する。

スワップファイルを削除する
$sudo rm /swapfile

ここまでの状態では、再起動後にスワップファイルが復元する場合がある。 そこで/etc/fstabを確認し、/swapfileをマウントするエントリがある場合は、削除しておく必要がある。

NTPサーバーの設定

systemd-timesyncdの設定を確認すると、初期設定ではntp.ubuntu.comと同期するようになっている。

(systemctl statusでStatusを確認すると、ntp.ubuntu.comに接続したことが確認できる)

systemd-timesyncdの状態を表示する
$systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-03-16 22:32:41 JST; 12min ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 557 (systemd-timesyn)
     Status: "Contacted time server 91.189.91.157:123 (ntp.ubuntu.com)."
      Tasks: 2 (limit: 9117)
     Memory: 1.4M
        CPU: 67ms
     CGroup: /system.slice/systemd-timesyncd.service
             └─557 /lib/systemd/systemd-timesyncd

/etc/systemd/timesyncd.confを編集して、NTPサーバーを設定する。 ここではNICTの公開NTPサーバーであるntp.nict.jpを使用する。

[Time]
NTP=ntp.nict.jp

設定を変更したら、再起動する。 少し時間が経過してからstatusを確認すると、設定を反映した動作になっているか確認することができる。

systemd-timesyncdを再起動し、状態を表示する
$sudo systemctl restart systemd-timesyncd.service

$systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-03-16 22:52:03 JST; 48s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 6407 (systemd-timesyn)
     Status: "Contacted time server 133.243.238.163:123 (ntp.nict.jp)."
      Tasks: 2 (limit: 9117)
     Memory: 1.2M
        CPU: 61ms
     CGroup: /system.slice/systemd-timesyncd.service
             └─6407 /lib/systemd/systemd-timesyncd

systemd timerユニットの停止

systemdのタイマーユニットのうち、不要なものを停止・無効化する。

まずは、登録・動作しているタイマーユニットを確認する。 systemctl list-timers --allで一覧表示できる。

systemdタイマーユニットを表示する
$systemctl list-timers --all

NEXT                        LEFT          LAST                        PASSED              UNIT                           ACTIVATES           >
Sat 2024-03-16 22:21:45 JST 7min left     -                           -                   systemd-tmpfiles-clean.timer   systemd-tmpfiles-cle>
Sat 2024-03-16 22:33:50 JST 19min left    Sat 2024-03-16 21:32:47 JST 41min ago           anacron.timer                  anacron.service
Sat 2024-03-16 22:37:35 JST 23min left    Sat 2024-03-16 16:02:17 JST 6h ago              fwupd-refresh.timer            fwupd-refresh.service
Sun 2024-03-17 00:00:00 JST 1h 45min left Sat 2024-03-16 13:43:41 JST 8h ago              dpkg-db-backup.timer           dpkg-db-backup.servi>
Sun 2024-03-17 00:00:00 JST 1h 45min left Sat 2024-03-16 13:43:41 JST 8h ago              logrotate.timer                logrotate.service
Sun 2024-03-17 00:40:45 JST 2h 26min left Sat 2024-03-16 14:46:16 JST 7h ago              apt-daily.timer                apt-daily.service
Sun 2024-03-17 03:10:42 JST 4h 56min left Sat 2024-03-16 13:43:41 JST 8h ago              e2scrub_all.timer              e2scrub_all.service
Sun 2024-03-17 03:57:52 JST 5h 43min left Sat 2024-03-16 14:32:25 JST 7h ago              motd-news.timer                motd-news.service
Sun 2024-03-17 06:00:06 JST 7h left       Sat 2024-03-16 13:49:20 JST 8h ago              apt-daily-upgrade.timer        apt-daily-upgrade.se>
Sun 2024-03-17 08:44:52 JST 10h left      Sat 2024-03-16 14:46:29 JST 7h ago              man-db.timer                   man-db.service
Sun 2024-03-17 11:12:54 JST 12h left      Thu 2023-10-12 08:06:21 JST 5 months 4 days ago update-notifier-motd.timer     update-notifier-motd>
Sun 2024-03-17 22:11:51 JST 23h left      Sat 2024-03-16 22:11:51 JST 2min 34s ago        update-notifier-download.timer update-notifier-down>
Mon 2024-03-18 01:15:48 JST 1 day 3h left Sat 2024-03-16 13:46:29 JST 8h ago              fstrim.timer                   fstrim.service
-                           -             -                           -                   apport-autoreport.timer        apport-autoreport.se>
-                           -             -                           -                   snapd.snap-repair.timer        snapd.snap-repair.se>
-                           -             -                           -                   ua-timer.timer                 ua-timer.service

16 timers listed.

ここでは、以下を停止する。

  • apt-daily.timer
  • apt-daily-upgrade.timer
  • motd-news.timer
  • man-db.timer
  • update-notifier-motd.timer

systemctl stopおよびsystemctl disableコマンドで、上記タイマーユニットを停止する。

systemdタイマーユニットを停止・無効化する
$sudo systemctl stop apt-daily.timer
$sudo systemctl disable apt-daily.timer

$sudo systemctl stop apt-daily-upgrade.timer
$sudo systemctl disable apt-daily-upgrade.timer

$sudo systemctl stop motd-news.timer
$sudo systemctl disable motd-news.timer

$sudo systemctl stop man-db.timer
$sudo systemctl disable man-db.timer

$sudo systemctl stop update-notifier-motd.timer
$sudo systemctl disable update-notifier-motd.timer

不要なaptパッケージの削除

以下のコマンドで一括して削除する。 削除理由等については省略。

不要なaptパッケージの削除
sudo apt purge \
  aisleriot \
  aspell aspell-en \
  '^avahi-.*' \
  brltty \
  cheese '^cheese-.*' \
  cups cups-browsed cups-bsd cups-client cups-common cups-core-drivers cups-daemon cups-filters* cups-ipp-utils cups-pk-helper cups-server-common foomatic-db-compressed-ppds ipp-usb \
  enchant-2 \
  '^espeak(-.*)?' \
  fonts-liberation '^fonts-liberation-.*' \
  ftp tnftp \
  gamemode gamemode-daemon \
  gnome-calendar gnome-mahjongg gnome-mines gnome-sudoku \
  hplip hplip-data '^printer-driver-.*' \
  '^libreoffice-.*' \
  modemmanager \
  mythes-en-au mythes-en-us \
  ntfs-3g '^libntfs-.*' \
  nano \
  openprinting-ppds \
  ppp pptp-linux \
  rygel \
  rhythmbox '^rhythmbox-.*' \
  sane-utils sane-airscan libsane-hpaio \
  simple-scan \
  shotwell '^shotwell-.*' \
  speech-dispatcher speech-dispatcher-audio-plugins \
  system-config-printer-common system-config-printer-udev \
  transmission-gtk transmission-common \
  totem totem-common totem-plugins \
  thunderbird thunderbird-gnome-support '^thunderbird-locale-.*' \
  wamerican wbritish

ここで削除する各パッケージの概要は次のとおり。

削除するパッケージと概要
パッケージ名 概要
aisleriot GNOME ソリティアカードゲーム集
aspell GNU aspell スペルチェッカ
aspell-en GNU Aspell 用英語辞書
'^avahi-.*' Avahi IPv4LL ネットワークアドレス設定デーモン
brltty 点字ディスプレイを使う視覚障害者のためのアクセスソフトウェア
cheese ウェブカムで写真や動画を撮影するツール
'^cheese-.*' Common files for the Cheese tool to take pictures and videos
cups Common UNIX Printing System(tm) - PPD/ドライバサポート、web インターフェース
cups-browsed OpenPrinting CUPS フィルター - cups-browsed
cups-bsd Common UNIX Printing System(tm) - BSD commands
cups-client Common UNIX Printing System(tm) - クライアントプログラム (SysV)
cups-common Common UNIX Printing System(tm) - common files
cups-core-drivers Common UNIX Printing System(tm) - driverless printing
cups-daemon Common UNIX Printing System(tm) - daemon
cups-filters* OpenPrinting CUPS フィルタ - メインパッケージ
cups-ipp-utils Common UNIX Printing System(tm) - IPP developer/admin utilities
cups-pk-helper cups の細かい権限設定を行なうための PolicyKit ヘルパー
cups-server-common Common UNIX Printing System(tm) - server common files
foomatic-db-compressed-ppds OpenPrinting プリンタサポート - データベースから派生した圧縮 PPD
ipp-usb Daemon for IPP over USB printer support
enchant-2 各種スペルチェッカエンジンへのラッパー (バイナリプログラム)
'^espeak(-.*)?' speech data files
fonts-liberation, ^fonts-liberation-.* Times, Arial および Courier と同等のメトリックのフォント群
ftp dummy transitional package for tnftp
tnftp enhanced ftp client
gamemode Optimise Linux system performance on demand
gamemode-daemon Optimise Linux system performance on demand (daemon)
gnome-calendar GNOME 用カレンダーアプリケーション
gnome-mahjongg classic Eastern tile game for GNOME
gnome-mines popular minesweeper puzzle game for GNOME
gnome-sudoku Sudoku puzzle game for GNOME
hplip HP Linux Printing and Imaging System (HPLIP)
hplip-data HP Linux Printing and Imaging - データファイル
'^printer-driver-.*' printer driver for HP-GDI printers
'^libreoffice-.*' office productivity suite -- word processor
modemmanager モデムを管理する D-Bus サービス
mythes-en-au Australian English Thesaurus for OpenOffice.org
mythes-en-us English (USA) Thesaurus for LibreOffice
ntfs-3g FUSE 用の読み書き可能な NTFS ドライバ
'^libntfs-.*' FUSE 用 NTFS 読み書きドライバ (ランタイムライブラリ)
nano Pico にヒントを得て作られた、コンパクトで使いやすいテキストエディタ
openprinting-ppds OpenPrinting printer support - PostScript PPD files
ppp Point-to-Point Protocol (PPP) デーモン
pptp-linux Point-to-Point Tunneling Protocol (PPTP) クライアント
rygel GNOME UPnP/DLNA services
rhythmbox GNOME 用音楽プレイヤーおよびオーガナイザー
'^rhythmbox-.*' data files for rhythmbox
sane-utils スキャナ用 API ライブラリ - ユーティリティ
sane-airscan SANE backend for AirScan (eSCL) and WSD document scanner
libsane-hpaio HP の複合機用 SANE バックエンド
simple-scan シンプルなスキャンユーティリティ
shotwell デジタル写真オーガナイザ
'^shotwell-.*' digital photo organizer - common files
speech-dispatcher Common interface to speech synthesizers
speech-dispatcher-audio-plugins Audio output plugins
system-config-printer-common backend and the translation files for system-config-printer
system-config-printer-udev プリンタの自動検出と設定を行う各種ユーティリティ
transmission-gtk lightweight BitTorrent client (GTK+ interface)
transmission-common 軽量な BitTorrent クライアント (共通ファイル)
totem GStreamer ベースで GNOME デスクトップ向けのシンプルなメディアプレイヤ
totem-common Totem メディアプレイヤーのデータファイル
totem-plugins Plugins for the Totem media player
thunderbird Email, RSS and newsgroup client with integrated spam filter
thunderbird-gnome-support Email, RSS and newsgroup client - GNOME support
'^thunderbird-locale-.*' Afrikaans language pack for Thunderbird
wamerican /usr/share/dict 用米国英語単語リスト
wbritish /usr/share/dict 用英国英語単語リスト
パッケージ名 概要

削除が完了したら、クリーンアップする。

aptパッケージのクリーンアップを行う
$sudo apt autoremove --purge
$sudo apt autoclean -y

デスクトップ設定

システムモニタアプレットのインストール

トップバーにシステムモニタアプレットを追加する。

GNOMEのバージョンによっては、 system-monitorは未対応で動作しない場合がある。 ここでは、オリジナルの代わりとしてsystem-monitor-nextをインストールする。

まずは、依存パッケージをインストールする。

gnome-shell-system-monitor-appletの依存パッケージをインストールする
gnome-shell-extension-managerがインストールされていない場合は、インストールする
$sudo apt install gnome-shell-extension-manager

gnome-shell-system-monitor-appletの依存パッケージをインストールする
$sudo apt install gir1.2-gtop-2.0

続いて、GNOME Shell Extension Managerを起動し、system-monitor-nextをインストールする。

インストールが完了し、トップバーにアプレットが表示されたら、設定を開いて表示内容の取捨選択・更新間隔の調整を行う。

起動時の自動ログイン

⏻メニューより⚙設定を開き、👥ユーザーを選択する。

まず、[ユーザーを追加]より、自動ログイン用の別ユーザーを作成する。 作成したら、「自動ログイン」をオンにする。 これにより、起動時に自動的にユーザーのログインが行われる。

パスワードレスのログイン

以下は未実施・未検証。 GDMのログイン画面から、パスワードレスでログインする方法について。

ロック時の認証画面の無効化

ロック時などに表示される認証画面を無効化して、パスワードレスでデスクトップに復帰できるようにする。

下記コマンドでロックスクリーンを無効化する。 これにより、⏻メニューから🔒ロックの項目も表示されなくなる。

$gsettings set org.gnome.desktop.lockdown disable-lock-screen true

サスペンド時・アイドル状態からの復帰時のロックを無効化する。

$gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false
$gsettings set org.gnome.desktop.screensaver idle-activation-enabled false