Last update: 29 November 2019
This article will guide you step by step to create a minimalist Ubuntu based image for your NVIDIA Jetson nano board that best suits your project.
First, for fun. It's always interesting to build stuff from scratch as you always learn something in the process. Second, the official image is large in size (over 5GB 😱) and it's filled with lot of unnecessary preinstalled packages (ubuntu-desktop, browser …) that takes lot of disk space and memory.
So, let's create a clean and minimalist image.
Before starting, let's first clone the repository where I put all the needed scripts.
$ git clone https://github.com/pythops/jetson-nano-image $ cd jetson-nano-image
We're gonna use the script
create-rootfs.sh to create a basic rootfs.
First, we define the location where we want to build it. This is done by defining the environment variable
$JETSON_ROOTFS_DIR. The path will be created if it does not exit.
$ export JETSON_ROOTFS_DIR=/path/to/rootfs
Then we build the rootfs by running the following command
$ sudo -E ./create-rootfs.sh ROOTFS_DIR: ~/jetson-rootfs Installing the dependencies... [OK] Creating rootfs directory... [OK] Downloading the base image... [OK] Run debootstrap first stage... [OK] Run debootstrap second stage... [OK] Success!
-E option for sudo preserve the environment variables
Now that we have a basic rootfs, we're gonna customize it using one of my favorite tool ever:
For this step you need to have Ansible installed in your workstation. if it's not the case, just run this command and you're ready to go
$ pip install --user ansible
This Ansible role is going to do 3 things:
You can run the playbook as follows
$ cd ansible $ sudo -E $(which ansible-playbook) jetson.yaml
Feel free to adapt this role to your needs.
Now that we customized the rootfs, we're gonna use the script
create-image.sh to create our final image.
We need to define a build directory using the environment variable
$JETSON_BUILD_DIR. This path will be created if it does not exist.
$ export JETSON_BUILD_DIR=/path/to/build_dir
Then we build the image as follows
$ sudo -E ./create-image.sh
If all goes well, you'll get this message at the end
Image created successfully Image location: /path/to/jetson.img
Finally we're gonna flash the image on the sdcard using the script
Insert your sdcard and run this command
$ sudo ./flash-image.sh /path/to/jetson.img /dev/mmcblk0 . . . Success ! Your sdcard is ready !
the sdcard path /dev/mmcblk0 may be different in your system.
This script will automatically resize the root partition to occupy all the available space in the sdcard.
Congratulations 🎉 Now you can boot your board with the new image !
To install nvidia libraries (cuda, libcudnn, tensorRT …) you need to use nvidia sdk manager.
With the new image only 200MB of RAM is used, which leaves you with 3.8 GB for your projects !