How to build a Jetson Nano SD card image containing specific software and libraries?

Hi,

We are preparing a Jetson Nano SD card image containing specific software and libraries for the event.After some searching, we decided to use Nvidia’s script called create-jetson-nano-sd-card.sh in the L4T install path to accomplish that.

# 这是我参考的链接
https://devtalk.nvidia.com/default/topic/1056595/jetson-nano/jetson-nano-sd-card-image/post/5357816/#5357816

Now we have some problems.

I successfully built the SD card image using the official Tegra_Linux_Sample-Root-Filesystem_R32.2.0_aarch64.tbz2.Successfully entered the configuration page and initialized the system

Next I tried to copy the contents of the configured SD card to /Linux_for_Tegra/rootfs to rebuild the image, but it failed.After completing all the system self-tests, he stuck in the initial configuration,.

How should I fix this problem?
Or how do I need to configure to build an image that contains other software and python libraries?

So, you won’t be able to copy the whole filesystem over directly from the sd card. You can probably, however, copy certain folders. For example, if you need python packages, those live in /usr/lib/python*/site-packages

basic idea:

  1. extract the sample filesystem tarball to the rootfs folder
  2. install your python packages by copying just them to the site-packages (from your sd card, for example). Make sure the permissions are correct when you do a ls -l inside the site-packages folder (drwxr-xr-x 3 root root ...). If you need they can be fixed by running this command inside the site-packages folder; ``` sudo chown -R root:root * && sudo chmod -R 755 * find . -type f -exec chmod 644 -- {} + ```
  3. if you need apt packages, one way is way to add them somewhere on the rootfs and have a script install them at the end of first boot (or at the beginning, you may have to troubleshoot when the script is run or wait for the apt lock to free). You can run the script with a systemd unit file (.service).

    In a file under rootfs/etc/systemd/system called “myfb.service”:

    [Unit]
    Description=MyFB - Install Extra Apt Packages
    After=nvfb.service
    
    [Service]
    Type=oneshot
    ExecStart=/etc/myfb/myfb.sh
    
    [Install]
    WantedBy=multi-user.target
    

    and the contents of rootfs/etc/myfb/myfb.sh would be something like:

    #!/usr/bin/env bash
    set -e
    
    dpkg -i /opt/myfb/apt/*.dpkg
    
    rm -- "$0"
    

    “set -e” ensures if anything fails, the script fails and systemd knows about the failure and it’s logged.

    The second line installs all the packages under /opt/myfb/apt/ (but you can put them anywhere), you can delete the packages after in the script if you want.

    That last line there deletes the script itself, since you want to make sure it doesn’t run twice.

    finally, since we can’t run systemctl directly, you can enable the service by creating a symlink like this from within the rootfs folder:

    ln -rs usr/lib/systemd/system/myfb.service etc/systemd/system/multi-user.target.wants/myfb.service
    

    Systemd enables and disables services by making symlinks so that command tells systemd that the “multi-user.target” runlevel wants to run myfb.service. Myfb.service says that it wants to run “After=nvfb.service” so it runs myfb.sh after nvfb.service runs it’s own first boot script.

    Please note that I’ve never tested installing apt packages this way, but it should work. If for some reason it fails (for example, if unattended upgrades has the apt lock), the script won’t self delete and you can run it manually with sudo /etc/myfb/myfb.sh

I may be forgetting something, but this should get you going. It’s not easy modifying the system directly from the rootfs without starting it up, but you can do most things.

Great, I will try it now. ヽ(≧∀≦)ノ

YW. Might I suggest making sure the image works without these modifications first just to make sure the SD card build is working. In other words: try to make the same image NVIDIA provides using unmodified files, just as a test, and then once you are sure that works, add the files progressively (first python packages for example, test those, then add the rest of the files).

Nevermind. I see you already did that. Have fun!