2023년 3월 6일 월요일

Jetson Xavier NX - JetPack 5.1 headless setup

 In July 2020 I explained in this article how to install Jetpack 4.4 in headless mode on Xavier NX.

Now, more than two years later, JetPack has been updated to version 5.1. Today, I will explain how to install JetPack 5.1 in headless mode and how to utilize NVME SSD. 

First, download SD card image for Xavier NX from https://developer.nvidia.com/embedded/jetpack .

As of March 2023, the latest version is JetPack 5.1. JetPack upgrades to the new version frequently, so always check the latest version on the homepage. Then, use the Etcher tool to create an SD card image. Since this process has a lot of help materials, the explanation is omitted. Etcher supports zip compressed files, so you don't have to decompress it on purpose.

Tips: There is no big problem if you install JetPack 5.1 on the SD card, but if you want to upgrade from JetPack 4.X to Jetpack 5.1, you need to install the QSPI image first. If you are upgrading from JetPack 4.X to Jetpack 5.1, please do not refer to this article, but refer to NVidia's QSPI installation documentation.


Headless Setup

Now insert the SD card into Xavier NX. And before connecting the power, connect the USB cable as shown in the picture. Connect the other end of the USB cable to your PC.





Then connect the Xavier NX's 19V power supply. When Xavier NX boots, the device connected to COM5 is shown in the device manager of the PC as shown in the following figure. The COM port number will change depending on your PC.

<check COM port using Windows device manager>

You can now connect Xavier NX using putty. Connect using the COM port number checked in the PC device manager. System Configurationon putty screen as follows. Now follow the instructions on the screen to set up.

<putty Serial setup>


If Xavier NX is normally booted and the USB cable is normally connected, the following license screen should be displayed.



Serial connection using putty can be used at any time. Therefore, when a monitor, keyboard, etc. are not ready, serial connection using a USB cable is a useful connection method. Once connected, it provides the same console environment as using ssh. 
Now, you can set the language, user, network, etc. according to the contents of the screen. And when the setting is finished, reboot the system. Now, you can access via ssh using the network information set earlier.

However, you can still connect using the serial port as shown in the following picture. If ssh connection is not available even after setting the network, you can connect the USB again and then connect the serial port as shown in the following figure to perform remote work.




Install useful software

After installing the OS, install software that helps you use Xavier NX.

NVIDIA Jetson Linux 35.2.1 (previously called L4T), the operating system of JetPack 5.1, has Python 3.8 installed, but the Python package manager pip is not installed. So first install the pip.

sudo apt-get install python3-pip


jtop

The jet-stats package is a great package for monitoring jetson series systems. Install it 
using the pip command. 

sudo pip install -U jetson-stats
sudo jtop

The jet-stats package installs the jtop service. It starts automatically with package installation, so you can use it right away. If the jtop service is running, you can get a nice screen with the jtop command:

<jtop command>

Menus 1 to 7 below can also be selected with the mouse.
<Various screens of jtop>

As the name jtop suggests, this program is very similar to the htop program. However, since it is specialized for the jetson series, it is much more useful than htop when looking at the jetson system.




Boot from SSD


Xavier NX can be only booted using eMMC or SD card. There are articles introducing the SSD booting on the Xavier NX and then booting the SSD using a service script that changes the rootfs.
The typical article is https://www.jetsonhacks.com/2020/05/29/jetson-xavier-nx-run-from-ssd/ introduced by JetsonHacks. However, even in this case, the boot does not start from the SSD. After booting the kernel using the SD card, the rootfs are changed to SSD. Therefore, SD card must be used together. It is not a complete SSD boot.

JetsonHacks' Youtube video explains how to use SSDs with Xavier NX




How to set up an SSD

SD cards are not only less stable and less faster than SSDs, but also have less capacity, so let's find a way to properly utilize SSDs.

I plan to use Xavier NX primarily for edge AI computing. And the programming language will mainly use Python. Probably many people are similar to me.

Since the Jetson Nano can only use SD cards, I have created several SD card images and then installed and used the packages needed for a specific purpose on the SD card. For example, the A SD card is used for PyTorch and the B SD card is used for Tensorflow. However, if you want the SSD to take advantage of the large storage capacity, you may prefer to use the Python virtual environment rather than this method.
After creating a Python virtual environment on an SSD, install most of the necessary Python packages in the virtual environment to utilize the SSD efficiently.

1. Power off the Xavier NX and install NVME SSD at the bottom of Xavier NX M.2 slot.

<image from jetsonhacks>


2.Power on the system and format the SSD drive.

You can check the device name of the NVME disk by using the fdisk -l command. In my case it is nvme0n1.

spypiggy@spypiggy-NX:/$ sudo fdisk -l
[sudo] password for spypiggy:
Disk /dev/nvme0n1: 119.25 GiB, 128035676160 bytes, 250069680 sectors
Disk model: SAMSUNG MZVLW128HEGR-00000
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
......


Now create an ext4 file system on the NVME disk using the mkfs.ext4 command.

spypiggy@spypiggy-NX:/$ sudo mkfs.ext4 /dev/nvme0n1
mke2fs 1.45.5 (07-Jan-2020)
Found a gpt partition table in /dev/nvme0n1
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 31258710 4k blocks and 7815168 inodes
Filesystem UUID: 9ae59d1d-e451-4a69-aced-eba90c69e148
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done


3. Create a mount point for the drive

I will mount /home/spypiggy directory to ssd and use it. So in the future, most of the work on Xavier NX will be done in /home/spypiggy. 

#First, copy the existing files on the /home/spypiggy to /dev/nvme0n1
sudo mount /dev/nvme0n1 /mnt
sudo rsync -avhr /home/spypiggy/.* /mnt
sudo rsync -avhr /home/spypiggy/* /mnt
sudo umount /mnt


Add the following to the fstab file to use the /home/spypiggy directory as an NVME disk upon booting.

</etc/fstab>


Then reboot the system and check the file system.

spypiggy@spypiggy-NX:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1   59G   15G   41G  27% /
none            3.4G     0  3.4G   0% /dev
tmpfs           3.4G     0  3.4G   0% /dev/shm
tmpfs           685M   19M  667M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.4G     0  3.4G   0% /sys/fs/cgroup
/dev/nvme0n1    117G   79M  111G   1% /home/spypiggy
tmpfs           685M   16K  685M   1% /run/user/124
tmpfs           685M  8.0K  685M   1% /run/user/1000

You can see that the NVME disk is mounted as /home/spypiggy.


Power Mode

There are 4 cpus checked with the jtop command above. It can be seen that CPUs 5 and 6 are disabled. This is the default value set to reduce Xavier's power usage. You can use all six CPUs by changing the Power mode. If you want to use the Edge AI function that requires quick response while running an AI application, it is better to change the mode to get the maximum performance.

The current power usage mode can be checked with the "nvpmodel -q" command.

spypiggy@spypiggy-NX:~$ sudo nvpmodel -q
NV Power Mode: MODE_10W_DESKTOP
5

You can see that the NVME disk is mounted as /home/spypiggy. It is currently mode 5 and the amount of power is limited to 10W. The power modes available in Xavier NX are:


Tips:Mode 5 is not present in the table above. Mode 5 is a new addition. In the previous Jetpack, mode id 3 was the default (2 CPUs active), but with the addition of mode 5, the mode with 4 CPUs activated became the default.

If you want to maximize the performance of Xavier NX, use mode 2.

spypiggy@spypiggy-NX:~$ sudo nvpmodel -m 2
spypiggy@spypiggy-NX:~$ sudo nvpmodel -q
NV Power Mode: MODE_15W_6CORE
2

Now run jtop and you should see 6 cores.

If you normally use 4 cores and up to 10W of power in Mode ID 5, which is the default mode, and you need to perform machine learning, etc., you can change the mode to 2 for maximum performance.

For reference, since the GPU is used regardless of the Mode ID, the machine learning execution performance, which is highly dependent on the GPU usage, does not depend heavily on the Mode ID.


Wrapping up

So far, we have seen how to install JetPack in Headless mode on Jetson Xavier NX and how to use SSD. Next time, I will look at using the Python virtual environment to utilize SSD effectively. 

In the next article, we will learn how to update the latest version of OpenCV in Jetpack 5.1, how to install and use YOLO V8.





댓글 없음:

댓글 쓰기