コンテンツへスキップ

NVIDIA Jetson Nano

VNCなどリモートからのグラフィカルログインに困っている方が、他にもいらっしゃるかなと思い、自分向けでもありますが、リモートデスクトップの利用方法、設定方法を残しておきます。

リモートデスクトップに必要なパッケージのインストール

xrdpとxfceをインストールします。

#XRDPのインストール
sudo apt-get install xrdp

#xfceのインストール
sudo apt-get install xfce4

初期設定

xrdpとxfceの設定を行います。

echo xfce4-session >~/.xsession

/etc/xrdp/startwm.shファイルに以下の変更を行います。
ファイル下部の2行をコメントアウトし、「startxfce4」の1行を追加します。

#test -x /etc/X11/Xsession && exec /etc/X11/Xsession
#exec /bin/sh /etc/X11/Xsession
startxfce4

リモートデスクトップ接続

Windowsパソコンより、リモートデスクトップクライアントより、NVIDIA Jetson Nanoにログインします。

created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

7000円以下NVIDIA Jetson Nano 2GB 開発者キット

関連記事:NVIDIA Jetson Nano B01 導入

NVIDIAの「Jetson Nano」に安価な2GBモデルが出ていました。
AIや機械学習のEdgeデバイスとしてシングルボードコンピューターを利用したい人は、この製品一択になるのではないでしょうか。
すごいとしか言いようがありません。

外出自粛の年末年始にAIを始めるのも良いと思います。

created by Rinker
NVIDIA
¥24,800 (2024/04/24 06:55:43時点 Amazon調べ-詳細)
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

Jetson Nano B01との比較

十分の使用で半額。魅力的な製品です。

開発者キット
技術仕様
Jetson Nano B01
2G廉価版
価格(2020.12時点)1,5500円7,000円
GPU128 コア NVIDIA Maxwell™左同
CPUクアッドコア ARM A57 @ 1.43 GHz左同
メモリ4GB 64 ビット LPDDR4 25.6GB/秒2 GB 64 ビット LPDDR4 25.6 GB/秒
ストレージmicroSD (カードは含まれていません)左同
ビデオ エンコーダー4Kp30 | 4x 1080p30 | 9x 720p30 (H.264/H.265)左同
ビデオ デコーダー4Kp60 | 2x 4Kp30 | 8x 1080p30 | 18x 720p30 (H.264/H.265)左同
コネクティビティギガビット イーサネット、M.2 Key Eギガビット イーサネット、802.11ac ワイヤレス*
カメラ2x MIPI CSI-2 コネクタ1x MIPI CSI-2 コネクタ
ディスプレイHDMI と DPHDMI
USB4x USB 3.0, 1x USB 2.0 Micro-B1x USB 3.0 タイプ A、2x USB 2.0 タイプ A、1x USB 2.0 Micro-B
その他40 ピン ヘッダー (GPIO、I2C、I2S、SPI、UART)左同
12 ピン ヘッダー (電力および関連信号、UART)左同
4 ピン ファン ヘッダー左同
機械的構造100 mm x 80 mm x 29 mm左同
備考日本モデルWIFIなし
電源端子変更

次のJetson Nano C01 などでは、USB-Cも標準となり、Edgeデバイスとして先進的なアーキテクチャになって出てきそうですね。それにしても、大きさに機能、性能と美しすぎます。

このでJetson Nanoを、マイク音源に挟んで、ノイズキャンセルを実施してほしい。
そのためには、オーディオ端子やPCと外部接続して認識出来るようなインターフェースがほしいです。

Ubuntu 18.04.5 LTS に ffmpeg を導入

Jetson Nano の Ubuntu にffmpegをインストールします。
FFmpeg(エフエフエムペグ)は、動画と音声を記録・変換・再生するための非常に優秀なフリーソフトウェアです。マルチプラットフォームで利用できます。
コマンドラインから使用することができる。対応コーデックが多く、多彩なオプションを使用可能であり、バッチ処理にも向いています。

$ sudo apt update
$ sudo apt -y upgrade
$ sudo apt install ffmpeg

ffmpeg利用

ffmpegは、非常に多くの機能とオプションが準備されております。
以下のコマンドで、ヘルプの全体を見ることが出来ます。

$ ffmpeg -h full

今回は、めざましじゃんけんシステムの、めざましじゃんけん時の画像を用いて、AIによる画像認識結果を動画化しました。
その際に利用したコマンドは、以下となってます。

ffmpeg -y -framerate 3 -i ffmpeg_%4d.jpg -c:v libx264 -r 60 jankensystem.mp4

サンプル動画

ちょうど、めざましテレビでHELLOチャレンジが実施されていたので、
AIでめざましじゃんけんにチャレンジっていう感じで、Official髭男dismの「HELLO」を動画に組み合わせました。

#ハローチャレンジ

撮影テーマは「〇〇にチャレンジしよう!」

NVIDIA Jetson Nanoからのメール送信

NVIDIA Jetson Nanoの利用を開始すると、Jetson Nanoの各種プログラムからメール通知を利用したくなるケースがあります。
既に、同一環境内にSMTPサーバが導入済みである場合を全体として、Jetson NanoにSSMTPを導入し、Jetson Nanoからメール送信が出来るように設定します。
パッケージのアップデートやログのローテーション処理時のエラーなどもメール通知することが可能です。

以前の関連記事: Jetson Nano で SSMTP を利用してPHPからメール送信

ssmtpインストールおよび設定

ssmtpをインストールします。

$ sudo apt install ssmtp

ssmtp.confを編集。

root@jetson:~# vi /etc/ssmtp/ssmtp.conf
  • mailhub=@@mail_server@@
    環境内のメールサーバを指定
  • rewriteDomain=miki-ie.com
    ドメイン名を指定
  • hostname=jetson01.miki-ie.com
    ホスト名を指定
  • FromLineOverride=YES
    メール送信元より、メールのFromを指定出来るように設定
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=@@mail_server@@

# Where will the mail seem to come from?
#rewriteDomain=
rewriteDomain=miki-ie.com

# The full hostname
#hostname=jetson01
hostname=jetson01.miki-ie.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES
FromLineOverride=YES
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

NVIDIA Jetson Nanoのセキュリティ対策

Ubuntuの自動アップデートを設定します。
再起動が必要な際は、指定した時間で再起動するように設定します。
自動アップデートの結果をメール送信するように設定します。

「unattended-upgrades」をインストールと有効化

「unattended-upgrades」をインストールします。

sudo apt install -y unattended-upgrades

インストールした「unattended-upgrades」を有効化します。
以下のコマンドを実行し、表示される画面で<Yes>を選択します。

sudo dpkg-reconfigure -p low unattended-upgrades

<Yes>を選択します。

 

「unattended-upgrades」設定

利用する設定ファイルは、以下の2つのファイルとなります。

  • /etc/apt/apt.conf.d/20auto-upgrades  : 自動アップデートとアップグレードを設定。
  • /etc/apt/apt.conf.d/50unattended-upgrades :詳細設定

「20auto-upgrades」設定

  • APT::Periodic::Update-Package-Lists "1";
    アップグレードの確認間隔
    Daily=1 / Every two days = 2 / Weekly = 7 / Every two weeks = 14 / Never = 0
  • APT::Periodic::Download-Upgradeable-Packages "1"
    セキュリティーアップデートがある場合の動作
    Download and install automatically = 1 / Download automatically = 1 / Display immediately = 0
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

「50unattended-upgrades」設定

以下の設定変更を加えました。

  • Unattended-Upgrade::Mail "aaa@bbbl.com";
    メール通知先の設定
  • Unattended-Upgrade::MailOnlyOnError "true";
    メール通知のタイミングをエラー発生時のみに変更
  • Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
    未使用となったカーネル関連パッケージの自動削除
  • Unattended-Upgrade::Remove-Unused-Dependencies "true";
    未使用となったパッケージの自動削除(apt-get autoremove)
  • Unattended-Upgrade::Automatic-Reboot "true";
    自動再起動が実施されるように設定(自動再起動ON)
  • Unattended-Upgrade::Automatic-Reboot-Time "02:00";
    再起動時の時間を指定
// Automatically upgrade packages from these (origin:archive) pairs
//
// Note that in Ubuntu security updates may pull in new dependencies
// from non-security sources (e.g. chromium). By allowing the release
// pocket these get automatically pulled in.
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}";
        "${distro_id}:${distro_codename}-security";
        // Extended Security Maintenance; doesn't necessarily exist for
        // every release and this system may not have it installed, but if
        // available, the policy for updates is such that unattended-upgrades
        // should also install from here by default.
        "${distro_id}ESMApps:${distro_codename}-apps-security";
        "${distro_id}ESM:${distro_codename}-infra-security";
//      "${distro_id}:${distro_codename}-updates";
//      "${distro_id}:${distro_codename}-proposed";
//      "${distro_id}:${distro_codename}-backports";
};

// List of packages to not update (regexp are supported)
Unattended-Upgrade::Package-Blacklist {
//      "vim";
//      "libc6";
//      "libc6-dev";
//      "libc6-i686";
};

// This option will controls whether the development release of Ubuntu will be
// upgraded automatically.
Unattended-Upgrade::DevRelease "false";

// This option allows you to control if on a unclean dpkg exit
// unattended-upgrades will automatically run
//   dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
//Unattended-Upgrade::AutoFixInterruptedDpkg "false";

// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGTERM. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "false";

// Install all unattended-upgrades when the machine is shutting down
// instead of doing it in the background while the machine is running
// This will (obviously) make shutdown slower
//Unattended-Upgrade::InstallOnShutdown "true";

// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you
// have a working mail setup on your system. A package that provides
// 'mailx' must be installed. E.g. "user@example.com"
//Unattended-Upgrade::Mail "root";
Unattended-Upgrade::Mail "aaa@bbb.com";

// Set this value to "true" to get emails only on errors. Default
// is to always send a mail if Unattended-Upgrade::Mail is set
//Unattended-Upgrade::MailOnlyOnError "true";
Unattended-Upgrade::MailOnlyOnError "true";

// Remove unused automatically installed kernel-related packages
// (kernel images, kernel headers and kernel version locked tools).
//Unattended-Upgrade::Remove-Unused-Kernel-Packages "false";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";

// Do automatic removal of new unused dependencies after the upgrade
// (equivalent to apt-get autoremove)
//Unattended-Upgrade::Remove-Unused-Dependencies "false";
Unattended-Upgrade::Remove-Unused-Dependencies "true";

// Automatically reboot *WITHOUT CONFIRMATION*
//  if the file /var/run/reboot-required is found after the upgrade
//Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Automatic-Reboot "true";

// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
//  Default: "now"
//Unattended-Upgrade::Automatic-Reboot-Time "02:00";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

// Use apt bandwidth limit feature, this example limits the download
// speed to 70kb/sec
//Acquire::http::Dl-Limit "70";

// Enable logging to syslog. Default is False
// Unattended-Upgrade::SyslogEnable "false";

// Specify syslog facility. Default is daemon
// Unattended-Upgrade::SyslogFacility "daemon";

// Download and install upgrades only on AC power
// (i.e. skip or gracefully stop updates on battery)
// Unattended-Upgrade::OnlyOnACPower "true";

// Download and install upgrades only on non-metered connection
// (i.e. skip or gracefully stop updates on a metered connection)
// Unattended-Upgrade::Skip-Updates-On-Metered-Connections "true";

動作確認

以下のコマンドで、動作確認を実施しておきます。

$ sudo unattended-upgrade --dry-run --debug
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

OPENCV 4.2の DNN が NVIDIA Cuda に対応

OpenCV の4.2より、OpenCVのdnnが、NVIDIA のGPUに対応していたようです。
しかも、NVIDIAのJetson Nanoでも利用可能でした。

とても驚きのトピックでした。
早速、NVIDA Jetson Nanoに導入し、YOLO / Darknet の推論を動作させてみました。
少し、導入に癖があったので、導入時のメモを公開しておきます。

Led by dlib’s Davis King, and implemented by Yashas Samaga, OpenCV 4.2 now supports NVIDIA GPUs for inference using OpenCV’s dnn module, improving inference speed by up to 1549%!

Pythonから、NVIDIA GPUのCUDAを用いた、OpenCVのDNNを利用する際のコードはBackendとTargetを以下のようにCUDAに設定します。

net.setPreferableBackend(cv.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv.dnn.DNN_TARGET_CUDA)

導入した環境

2020/08/20追記:
JetPack4.4とOPENCV4.4.0でインストールできました。

  • JetPack 4.3 (4.4では、OPENCVコンパイル時に、CuDNNがうまくコンパイルできず)
    Jetpack 4.3 Archive
  • OPENCV 4.3.0 (4.2.0でもインストール出来ました)
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

導入方法

NVIDIA Jetson NanoのOpencvコンパイル用のスクリプトは、公式が公開したこともあり、各種エンハンスされ公開されています。
今回は、結構最近に公開されたとみられる、4.3.0向けのスクリプトを利用します。

Build OpenCV on Nvidia Jetson Nano

ポイントは、コンパイルオプションに以下を追加します。

  • WITH_CUDA
  • WITH_CUDNN

インストールスクリプト

コンパイルオプションを追加した、スクリプトを公開しておきます。

./Build_OpenCV.sh でインストールは完了します。
./Build_OpenCV.sh <version> で、指定したバージョンのOPENCVがインストール出来るようです。

実際にコンパイルした際の構成も公開しておきます。

NVIDIA CUDA: YES (ver 10.0, CUFFT CUBLAS FAST_MATH)
NVIDIA GPU arch: 53 62 72 -- NVIDIA PTX archs:
cuDNN: YES (ver 7.6.3)

-- General configuration for OpenCV 4.3.0 =====================================
--   Version control:               4.3.0
--
--   Extra modules:
--     Location (extra):            /tmp/build_opencv/opencv_contrib/modules
--     Version control (extra):     4.3.0
--
--   Platform:
--     Timestamp:                   2020-05-25T01:56:52Z
--     Host:                        Linux 4.9.140-tegra aarch64
--     CMake:                       3.10.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
--
--   CPU/HW features:
--     Baseline:                    NEON FP16
--       required:                  NEON
--       disabled:                  VFPV3
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed
--     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv java js matlab ovis sfm ts viz
--     Applications:                apps
--     Documentation:               NO
--     Non-free algorithms:         YES
--
--   GUI:
--     GTK+:                        YES (ver 3.22.30)
--       GThread :                  YES (ver 2.56.4)
--       GtkGlExt:                  NO
--     OpenGL support:              NO
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
--     JPEG 2000:                   build Jasper (ver 1.900.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      YES (2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (57.107.100)
--       avformat:                  YES (57.83.100)
--       avutil:                    YES (55.78.100)
--       swscale:                   YES (4.8.100)
--       avresample:                YES (3.7.0)
--     GStreamer:                   YES (1.14.5)
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Lapack:                      YES (/usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so)
--     Eigen:                       YES (ver 3.3.4)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   YES (ver 10.0, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             53 62 72
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 7.6.3)
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /tmp/build_opencv/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.17)
--     Libraries:                   /usr/lib/aarch64-linux-gnu/libpython2.7.so (ver 2.7.17)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)
--     install path:                lib/python2.7/dist-packages/cv2/python-2.7
--
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.6.9)
--     Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9)
--     numpy:                       /usr/local/lib/python3.6/dist-packages/numpy/core/include (ver 1.16.1)
--     install path:                lib/python3.6/dist-packages/cv2/python-3.6
--
--   Python (for build):            /usr/bin/python2.7
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    /usr/local
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

参考サイト

前提条件

JetsonにJenkins向けユーザー作成

別にセットアップされた、Jenkinsシステムより、NVIDIA Jetson Nanoを管理対象と資するために、Jetson NanoにJenkinsから操作する用のユーザーを作成します。

  1. Jetson Nanoに新規ユーザー作成
  2. Jenkins向けユーザーのsudoコマンド設定 パスワード
  3. Jenkins向けユーザーでのGitHubからのPull設定

1. Jenkins向けユーザーを作成

NVIDIA Jetson NanoにJenkinsユーザーを作成します。

$ sudo useradd -m -s /bin/bash jenkins
$ sudo passwd jenkins
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

2. Jenkins向けユーザーのSudoコマンド設定

Jenkinsユーザーで、各種スクリプトを実行するので、sudoが簡単に実行出来るように設定します。
※ 全体的にパスワードなしでのsudoを許可しているので、利用するコマンドごとの設定や、各種設定ファイルのアクセス権などを環境に合わせて設定し、セキュリティ対策を行って下さい。

$ cd /etc/sudoers.d/
$ sudo vi jenkins

作成するjenkinsファイルへの記載内容

Defaults:jenkins !requiretty
jenkins ALL=(ALL) NOPASSWD:ALL

3. Jenkins向けユーザーでのGitHubからのPull設定

Jenkinsを利用して、Githubに新しいソースコードがコミットされた際に、Githubより新規ソースコードの通知をトリガーとして、Jenkinsのタスクを実行させます。

Githubへの新規コミットをトリガーに、ジャンケンシステムを構成するメインのIntel NUC Ubuntuサーバー、Raspberry Pi、NVIDIA Jetson Nanoに最新のソースコードが自動的にデプロイ(Pull)される環境を構築しました。
デプロイ前に、簡単なテストなども自動化することが出来ます。

設定には、Jenkinsユーザー向けのSSHキーをNVIDIA Jetson Nanoで作成し、作成したSSHキーをGithubに登録します。GithubにSSHキーが登録出来たら、NVIDIA Jetson NanoからGithubへのアクセスを確認します。

Jetson NanoでSSHキー作成

Jenkinsユーザー向けのSSHキーを作成します。
このSSHキーをGithubに登録します。
Githubに登録することにより、Jenkinsユーザーを用いて、Githubの操作が可能になります。

$ sudo su jenkins
$ cd /home/jenkins/
$ mkdir .ssh
jenkins@jetson02:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jenkins/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jenkins/.ssh/id_rsa.
Your public key has been saved in /home/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:
The key's randomart image is:

GithubへSSHキーの登録と接続確認

https://github.com/settings/keys で id_rsa.pub の内容を登録します。

NVIDIA Jetson NanoからGithubへ接続確認

最後に、対象のサーバーより接続確認を行います。

ssh -T git@github.com
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

SU コマンドの有効化

セキュリティ対策ですが、利用したくなる「su -」コマンド、最近のUbuntsなどのLinux OSでは、初期設定時にrootのパスワードを設定しないので、suコマンドは利用できない状態となります。

以下が、suコマンドを実施して、失敗した際の例です。

$ su -
Password:
su: Authentication failure

SU コマンド有効化(rootユーザーのパスワード設定)

SUコマンドが利用できるように、rootユーザーのパスワードを設定します。
sudo su コマンドは利用できるので、自分のアカウントパスワードを用いて、rootユーザに切り替えを行います。

$ sudo su

rootユーザーになり、パスワードコマンドでパスワードを設定します。
この状態で、suコマンドでのrootユーザーへの変更は可能となります。

動作確認のため、rootユーザーから抜けて、su -コマンドを実行し、パスワード入力後にrootユーザーに変更されることを確認します。

 

Jetson Nanoに Tensorflow-gpu、Keras などを導入

NVIDIA Jetsonへの各種ツールインストールは、NVIDAより公開されているOSイメージを利用することで、一通りのツールは導入済みとなります。
JETSON NANO DEVELOPER KIT(JetPack)と呼ばれています。

  • NVIDIA提供のtensorflow-gpu
  • Keras
  • その他ツール
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

導入パッケージのアップデート

インストールパッケージを最新にアップデートします。

sudo apt update
sudo apt upgrade -y

各種パッケージ導入

NVIDIAが提供する、JetPackを導入してください。
(NVIDIAが提供するイメージを用いたOSを導入して下さい)
以前は、OpenCVなどをコンパイルして導入しておりましたが、JetPack 4.3では、必要そうなツールは、事前に導入済みでした。

JetPack 4.3 components:

  • L4T R32.3.1 (K4.9)
  • Ubuntu 18.04 LTS aarch64
  • CUDA 10.0
  • cuDNN 7.6.3
  • TensorRT 6.0.1
  • VisionWorks 1.6
  • OpenCV 4.1 (4.1.1)
  • Nsight Systems 2019.6
  • Nsight Graphics 2019.5
  • Nsight Compute 2019.3
  • SDK Manager 1.0.0

TensorFlow-GPU導入

NVIDIAの開発者コミュニティに記載されている内容で、インストールを行います。

https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html#install

  1. TensorFlow導入の前提ソフトウェアをインストールします。
    $ sudo apt-get update
    $ sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
    
  2. 導入済みのPip3コマンドを最新版に更新します。
    $ sudo apt-get install python3-pip
    $ sudo pip3 install -U pip testresources setuptools
    
  3. 前提となるPythonパッケージをPip3コマンドで導入します。
    $ sudo pip3 install -U numpy==1.16.1 future==0.17.1 mock==3.0.5 h5py==2.9.0 keras_preprocessing==1.0.5 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11
最後に、NVIDIAより公開されている媒体を用いて、tensorflow-gpuのインストールを実施します。
$ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 tensorflow

以下のパッケージ群が導入されます。

Successfully installed absl-py-0.9.0 astor-0.8.1 cachetools-4.1.0 google-auth-1.14.1 google-auth-oauthlib-0.4.1 google-pasta-0.2.0 grpcio-1.28.1 keras-preprocessing-1.1.0 markdown-3.2.1 oauthlib-3.1.0 opt-einsum-3.2.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.23.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 six-1.14.0 tensorboard-2.1.1 tensorflow-2.1.0+nv20.4 tensorflow-estimator-2.1.0 termcolor-1.1.0 werkzeug-1.0.1 wrapt-1.12.1

keras導入

以下が、導入したTensorflowや、導入されているOpenCVのバージョン確認結果となります。
created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

Apache 2、PHP、DB関係モジュールを導入

apt installで必要なパッケージを導入します。
# apt install apache2
# apt install php
# apt install mysql-server
# apt install php-mysql
# apt install php-mbstring
# apt install php-curl

NVIDIA Jetson NanoのUSB接続のHDD/SSDルート構成

NVIDIA Jetson NanoのルートディスクをUSB接続したHDDやSSD構成にする方法の最新版です。/dev/sda1を/(ルート)ディレクトリ構成にします。

以前に、同様の記事を投稿しましたが、よりスマートな導入方法が公開されていましたので、今回は、そちらの方法で、USBブート構成を作成しました。
根本原因となっていたブートシーケンスの変更により、USBブートが可能になっております。

※ ブート時にSDカードへアクセスします。
よって、SDカードの利用も必要となります。

以前の記事: Jetson Nano DeveloperをUSB 接続HDD/SSDルート構成

  1. 通常のブート用SDカード作成
  2. USBルートディスク構成作成ツールをダウンロード
  3. USB接続HDD/SSDにデータコピー
  4. ブートシーケンス変更

通常のブート用SDカード作成

SDカードイメージダウンロード

以下のURLに従い、利用するOSの手順でSDカードを準備しJetson Nano Developer Kit SD Card Imageを作成すれば、SDカードを用いてJetson Nanoの起動は可能となります。Write Image to the microSD Card

(Windows)SDカードフォーマット

SDカードをフォーマットします。SD Memory Card Formatter for Windows Download

SDカードへOSイメージを焼き付け

EtcherでダウンロードしたSDカードイメージをSDカードにコピーします。

最新のSDカードイメージと同様のバージョンで、SDカード用とUSB接続のHDD/SSD用のイメージが公開されています。

USBルートディスク構成作成ツールをダウンロード

利用する外部接続のHDDやSSDを準備

  1. fdisk -l で状況を確かめます。
    % sudo fdisk -l
  2. パーティションを削除します(ここでは、/dev/sda1とします)。
    % sudo fdisk /dev/sda
    .....
    コマンド (mでヘルプ): d (削除コマンド)
    選択した領域 1 (/dev/sda1を削除指定)コマンド (m でヘルプ): w (書き込み)
  3. 新たにパーティションを作成します。
    % sudo fdisk /dev/sda
    ...
    コマンド (mでヘルプ): n (作成コマンド)
    コマンドアクション
    e 拡張
    p 基本パーティション (1-4)
    p
    パーティション番号 (1-4): 1
    ....... コマンド (m でヘルプ): w (書き込み)

    ここでは、基本パーティションを選んで、 パーティション番号1(つまり/dev/sda1)を作りました。

  4. フォーマットする。
    sudo mkfs.ext4 /dev/sda1

最後に、適当なマウントポイントにマウントしておきます。

Githubより必要ツールを導入

Githubに、rootOnUSBプロジェクトとして公開されております。

作成したSDカードで、Jetson Nanoを起動させ、Githubレポジトリをダウンロード(クローン)します。

$ git clone https://github.com/JetsonHacksNano/rootOnUSB
Cloning into 'rootOnUSB'...
remote: Enumerating objects: 87, done.
remote: Total 87 (delta 0), reused 0 (delta 0), pack-reused 87
Unpacking objects: 100% (87/87), done.
$ cd rootOnUSB/
$ ls
LICENSE    addUSBToInitramfs.sh  data         sample-extlinux.conf
README.md  copyRootToUSB.sh      diskUUID.sh  scripts

USB接続HDD/SSDにデータコピー

ブートシーケンスにUSB接続を追加するツールを実行します。

~/rootOnUSB$ ./addUSBToInitramfs.sh
Adding USB to initramfs
[sudo] password :
Warning: couldn't identify filesystem type for fsck hook, ignoring.
I: The initramfs will attempt to resume from /dev/zram3
I: (UUID=bfeedab2-3ada-4cb1-924c-bf1df42d9e3e)
I: Set the RESUME variable to override this.
/sbin/ldconfig.real: Warning: ignoring configuration file that cannot be opened: /etc/ld.so.conf.d/aarch64-linux-gnu_EGL.conf: No such file or directory
/sbin/ldconfig.real: Warning: ignoring configuration file that cannot be opened: /etc/ld.so.conf.d/aarch64-linux-gnu_GL.conf: No such file or directory

次に、SDカードのルートディレクトリの内容を、利用するUSB接続のHDDやSSDにコピーを実施します。copyRootToUSB.sh というコマンドが準備されております。

copyRootToUSBコマンドリファレンス:

usage: ./copyRootToUSB.sh [OPTIONS]

  -d | --directory     Directory path to parent of kernel

  -v | --volume_label  Label of Volume to lookup

  -p | --path          Device Path to USB drive (e.g. /dev/sda1)

  -h | --help  This message

外部接続した、HDD/SSDのパーティションをオプションしてして、コマンド実行を実施しました。

このコマンドを実行する前に、/dev/sda1を適当な場所にマウントしておく必要があります。マウントしていないと、コマンドは失敗します。

$ ./copyRootToUSB.sh -p /dev/sda1

ブートシーケンス変更

/boot/extlinux/extlinux.confファイルを変更し、ルート領域を外部USB接続のHDD/SSDに変更します。

  1. ブート時にUSBをロードするイメージファイルを登録します
  2. ブートするDiskパスをUUIDを用いて指定します

DiskのUUIDを調べるツールも、rootOnUSBより提供されています。

~/rootOnUSB$ ./diskUUID.sh
UUID of Disk: /dev/sda1
0c378dce-319c-46cc-827b-06a990231f48

Sample for /boot/extlinux/extlinux.conf entry:
APPEND ${cbootargs} root=UUID=0c378dce-319c-46cc-827b-06a990231f48 rootwait rootfstype=ext4

また、extlinux.confファイルのサンプルも、sample-extlinux.confとして、提供されています。

もとのextlinux.confファイルのバックアップを準備し、以下の変更を加えます。

INITRD /boot/initrd-xusb.img

USBファームウェアを読み込んだイメージがロードされます。

UUIDでルートディスクを指定します。

APPEND ${cbootargs} root=UUID=0c378dce-319c-46cc-827b-06a990231f48 rootwait rootfstype=ext4

最後に再起動して、ルートフォルダーが、指定した外部接続のHDDやSSDになっていることを確認します。

created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

以下のサイトが情報源となります。詳細に書かれています。

Jetson Nano – Run From USB Drive