How to clone Jetson Nano SD Card?

So, I haven’t heard back @sarthak.srivastava14apr (ninja’d) but for the benefit of others (if there are any interested in this), let’s continue. I’m roughly following the guide from nvidia here for flashing, if anybody is curious as to where these instructions are coming from.

So the next step is to download and extract the BSP tarball and the rootfs tarball. This will unpack what SDK manager installs ( only without SDK manager :P ). For platforms other than Nano, or if you’re reading this when 32.4.3 is not the current release, you’ll want to use a different tarballs available here.

downloading:

ubuntu@tegra-image-maker:~$ wget https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/t210ref_release_aarch64/Tegra210_Linux_R32.4.3_aarch64.tbz2
--2020-07-15 11:13:46--  https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/t210ref_release_aarch64/Tegra210_Linux_R32.4.3_aarch64.tbz2
Resolving developer.nvidia.com (developer.nvidia.com)... 152.199.0.24
Connecting to developer.nvidia.com (developer.nvidia.com)|152.199.0.24|:443... connected.
HTTP request sent, awaiting response... 302 Found
...
Tegra210_Linux_R32.4.3_aarch 100%[==============================================>] 230.84M  79.8MB/s    in 2.9s    

2020-07-15 11:13:50 (79.8 MB/s) - â saved [242054516/242054516]

ubuntu@tegra-image-maker:~$ wget https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/t210ref_release_aarch64/Tegra_Linux_Sample-Root-Filesystem_R32.4.3_aarch64.tbz2
--2020-07-15 11:14:00--
...
Tegra_Linux_Sample-Root-File 100%[==============================================>]   1.25G  89.8MB/s    in 16s     

2020-07-15 11:14:17 (80.6 MB/s) - â saved [1342963536/1342963536]

extraction:

ubuntu@tegra-image-maker:~$ tar -xf Tegra210_Linux_R32.4.3_aarch64.tbz2
ubuntu@tegra-image-maker:~$ sudo chown root:root Linux_for_Tegra/rootfs/
ubuntu@tegra-image-maker:~$ sudo rm Linux_for_Tegra/rootfs/README.txt 
ubuntu@tegra-image-maker:~$ cd Linux_for_Tegra/rootfs/
ubuntu@tegra-image-maker:~/Linux_for_Tegra/rootfs$ sudo tar -xpf ../../Tegra_Linux_Sample-Root-Filesystem_R32.4.3_aarch64.tbz2 

Next step will be to mount your sd card, or a live nano, and copy your software into the rootfs. Let me know when you’re ready.

So, the next step it so enter an environment where it’s possible to edit the rootfs. The easiest way to install a python package globally is with either apt-get or pip. Assuming your project is on pypi or GitHub and has a setup.py, it can be installed this way.

First, let’s download a chroot script which will let us enter the rootfs.

ubuntu@tegra-image-maker:~$ git clone https://github.com/mdegans/enter_chroot.git
ubuntu@tegra-image-maker:~$ sudo cp enter_chroot/enter_chroot.sh /usr/bin/

Now that the script is installed, let’s enter the rootfs and run the arch command to test we can execute aarch64 binaries.

ubuntu@tegra-image-maker:~$ sudo enter_chroot.sh Linux_for_Tegra/rootfs/
+ cp /usr/bin/qemu-aarch64-static Linux_for_Tegra/rootfs//usr/bin
+ mount -t sysfs -o ro none Linux_for_Tegra/rootfs//sys
+ mount -t proc -o ro none Linux_for_Tegra/rootfs//proc
+ mount -t tmpfs none Linux_for_Tegra/rootfs//tmp
+ mount -o bind,ro /dev Linux_for_Tegra/rootfs//dev
+ mount -t devpts none Linux_for_Tegra/rootfs//dev/pts
+ mount -o bind,ro /etc/resolv.conf Linux_for_Tegra/rootfs//run/resolvconf/resolv.conf
+ chroot Linux_for_Tegra/rootfs/
root@tegra-image-maker:/# arch
aarch64
root@tegra-image-maker:/# 

You’re now in a “virtual nano” of sorts you can use to install software from apt repositories or from pip as if you were on the device itself. There are some limitations to what you can do (example, using the GPU is not possible), however simple things like apt or pip will usually work fine. As a example, I’m going to install one of my own python packages, mce.

Apt update and apt install pip3 since it’s not installed by default:

Note: sudo is not needed since we’re already root (in fact it may cause warnings/errors in this case).

root@tegra-image-maker:/# apt update
...
144 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@tegra-image-maker:/# apt install python3-pip
...
Setting up python3.6-dev (3.6.9-1~18.04ubuntu1) ...
Setting up libpython3-dev:arm64 (3.6.7-1~18.04) ...
Setting up python3-dev (3.6.7-1~18.04) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

Then install the python package itself, which, since we’re root will install to a system python path.

root@tegra-image-maker:/# pip3 install mce
Collecting mce
  Downloading https://files.pythonhosted.org/packages/cc/34/017ffa686b1e5f1e35e4828400bb406c5d57188c978be86f11512aff833f/mce-0.1.3.tar.gz
Building wheels for collected packages: mce
  Running setup.py bdist_wheel for mce ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/65/93/26/6ca68cc28171db6639be1dfd917e2747c8d64e76bbf83d28c9
Successfully built mce
Installing collected packages: mce
Successfully installed mce-0.1.3

Note: If a package is available in the apt repos, you should usually prefer that, since they’re tested to play nice with other system pakages.
Note2: For reasons, pip created a /home/ubuntu folder. that sould be deleted with rm -rf /home/ubuntu (from within the chroot)
Note3: Mce will not actually work for several reasons, (deepstream is not installed and it hasnt’ been updated to work with DS 5.0)

When you’re done, just type exit to exit the chroot.

root@tegra-image-maker:/home# exit
exit
+ umount Linux_for_Tegra/rootfs//sys
+ umount Linux_for_Tegra/rootfs//proc
+ umount Linux_for_Tegra/rootfs//tmp
+ umount Linux_for_Tegra/rootfs//dev/pts
+ umount Linux_for_Tegra/rootfs//dev
+ umount Linux_for_Tegra/rootfs//run/resolvconf/resolv.conf
+ rm Linux_for_Tegra/rootfs//usr/bin/qemu-aarch64-static

@sarthak.srivastava14apr Let me know if that helps, or if you need any help creating a setup.py so you can package and pip install your thing. Alternatively you can just copy your files to a python path of choice, but you won’t be able to as easily uninstall/upgrade your software that way.

Note on apt-get and nvidia software: if you need to apt install any Nvidia software from their apt repos on a custom rootfs (not the one you extracted), you will need to install nvidia’s apt key and create a nvidia sources.list. If anybody is needs help with that, please ask.

Tomorrow, I’ll write a post on mastering a .img from this prepared rootfs. If you’re going to make an image for multple platforms, now might be a good time to tarball up your rootfs since the next step will apply board specific changes to the rootfs. Right now the rootfs should work on any Tegra device. Also, if something goes wrong, you have a backup.

that is a great approach that is defined above;
it is ipmortant, however, to make sure that if an image is taken from the entire sdcard [!not from a single partition], then it will need to be restored to the entire sdcard, not to a partition. Doing otherwise would cause e.g partitioning error. Typically an entire sdcard is something like mmcblk0 and partition is smth. like mmcblk0p1.

somre reference reading

upd: running dd from virtual machine doesn’t seem correct;
ubuntu usblive drive should do better

@_av

I don’t plan on dd’ing from the VM, but it should work fine so long as a block device is passed through. I wouldn’t trust it without some sort of verification pass (i don’t anyway).

So. The next step once you’ve setup your rootfs the way you like it is to follow these instructions here. to apply binaries (kernel, modules, optional debian packages) to the rootfs. All we have to do at this point is to run apply_binaries.sh:

ubuntu@tegra-image-maker:~/Linux_for_Tegra$ sudo ./apply_binaries.sh 
Using rootfs directory of: /home/ubuntu/Linux_for_Tegra/rootfs
/home/ubuntu/Linux_for_Tegra/nv_tegra/nv-apply-debs.sh
Root file system directory is /home/ubuntu/Linux_for_Tegra/rootfs
Copying public debian packages to rootfs
Start L4T BSP package installation
QEMU binary is not available, looking for QEMU from host system
Found /usr/bin/qemu-aarch64-static
Installing QEMU binary in rootfs
~/Linux_for_Tegra/rootfs ~/Linux_for_Tegra
Installing BSP Debian packages in /home/ubuntu/Linux_for_Tegra/rootfs
Selecting previously unselected package nvidia-l4t-core.
(Reading database ... 122305 files and directories currently installed.)
Preparing to unpack .../nvidia-l4t-core_32.4.3-20200625213809_arm64.deb ...
Pre-installing... skip compatibility checking.
Unpacking nvidia-l4t-core (32.4.3-20200625213809) ...
Setting up nvidia-l4t-core (32.4.3-20200625213809) ...
Selecting previously unselected package jetson-gpio-common.
(Reading database ... 122349 files and directories currently installed.)
Preparing to unpack .../jetson-gpio-common_2.0.8_arm64.deb ...
Unpacking jetson-gpio-common (2.0.8) ...
Selecting previously unselected package python-jetson-gpio.
Preparing to unpack .../python-jetson-gpio_2.0.8_arm64.deb ...
Unpacking python-jetson-gpio (2.0.8) ...
Selecting previously unselected package python3-jetson-gpio.
Preparing to unpack .../python3-jetson-gpio_2.0.8_arm64.deb ...
Unpacking python3-jetson-gpio (2.0.8) ...
Selecting previously unselected package nvidia-l4t-3d-core.
Preparing to unpack .../nvidia-l4t-3d-core_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-3d-core (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-apt-source.
Preparing to unpack .../nvidia-l4t-apt-source_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-apt-source (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-camera.
Preparing to unpack .../nvidia-l4t-camera_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-camera (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-configs.
Preparing to unpack .../nvidia-l4t-configs_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-configs (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-cuda.
Preparing to unpack .../nvidia-l4t-cuda_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-cuda (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-firmware.
Preparing to unpack .../nvidia-l4t-firmware_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-firmware (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-graphics-demos.
Preparing to unpack .../nvidia-l4t-graphics-demos_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-graphics-demos (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-gstreamer.
Preparing to unpack .../nvidia-l4t-gstreamer_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-gstreamer (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-init.
Preparing to unpack .../nvidia-l4t-init_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-init (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-initrd.
Preparing to unpack .../nvidia-l4t-initrd_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-initrd (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-jetson-io.
Preparing to unpack .../nvidia-l4t-jetson-io_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-jetson-io (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-multimedia-utils.
Preparing to unpack .../nvidia-l4t-multimedia-utils_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-multimedia-utils (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-multimedia.
Preparing to unpack .../nvidia-l4t-multimedia_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-multimedia (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-oem-config.
Preparing to unpack .../nvidia-l4t-oem-config_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-oem-config (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-tools.
Preparing to unpack .../nvidia-l4t-tools_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-tools (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-wayland.
Preparing to unpack .../nvidia-l4t-wayland_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-wayland (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-weston.
Preparing to unpack .../nvidia-l4t-weston_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-weston (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-x11.
Preparing to unpack .../nvidia-l4t-x11_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-x11 (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-xusb-firmware.
Preparing to unpack .../nvidia-l4t-xusb-firmware_32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-xusb-firmware (32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-kernel-dtbs.
Preparing to unpack .../nvidia-l4t-kernel-dtbs_4.9.140-tegra-32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-kernel-dtbs (4.9.140-tegra-32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-kernel-headers.
Preparing to unpack .../nvidia-l4t-kernel-headers_4.9.140-tegra-32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-kernel-headers (4.9.140-tegra-32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-kernel.
Preparing to unpack .../nvidia-l4t-kernel_4.9.140-tegra-32.4.3-20200625213809_arm64.deb ...
Unpacking nvidia-l4t-kernel (4.9.140-tegra-32.4.3-20200625213809) ...
Selecting previously unselected package nvidia-l4t-bootloader.
Preparing to unpack .../nvidia-l4t-bootloader_32.4.3-20200625213809_arm64.deb ...
Pre-installing bootloader package, skip flashing
Unpacking nvidia-l4t-bootloader (32.4.3-20200625213809) ...
Setting up jetson-gpio-common (2.0.8) ...
Setting up python-jetson-gpio (2.0.8) ...
Setting up python3-jetson-gpio (2.0.8) ...
Setting up nvidia-l4t-apt-source (32.4.3-20200625213809) ...
Pre-installing... skip changing source list.
Setting up nvidia-l4t-configs (32.4.3-20200625213809) ...
Setting up nvidia-l4t-firmware (32.4.3-20200625213809) ...
Setting up nvidia-l4t-init (32.4.3-20200625213809) ...
Setting up nvidia-l4t-multimedia-utils (32.4.3-20200625213809) ...
Setting up nvidia-l4t-oem-config (32.4.3-20200625213809) ...
Setting up nvidia-l4t-tools (32.4.3-20200625213809) ...
Setting up nvidia-l4t-wayland (32.4.3-20200625213809) ...
Setting up nvidia-l4t-weston (32.4.3-20200625213809) ...
Setting up nvidia-l4t-x11 (32.4.3-20200625213809) ...
Setting up nvidia-l4t-xusb-firmware (32.4.3-20200625213809) ...
Pre-installing xusb firmware package, skip flashing
Setting up nvidia-l4t-kernel (4.9.140-tegra-32.4.3-20200625213809) ...
Setting up nvidia-l4t-bootloader (32.4.3-20200625213809) ...
Pre-installing bootloader package, skip flashing
Setting up nvidia-l4t-3d-core (32.4.3-20200625213809) ...
Setting up nvidia-l4t-cuda (32.4.3-20200625213809) ...
Setting up nvidia-l4t-graphics-demos (32.4.3-20200625213809) ...
Setting up nvidia-l4t-initrd (32.4.3-20200625213809) ...
Setting up nvidia-l4t-jetson-io (32.4.3-20200625213809) ...
Setting up nvidia-l4t-multimedia (32.4.3-20200625213809) ...
Setting up nvidia-l4t-kernel-dtbs (4.9.140-tegra-32.4.3-20200625213809) ...
Setting up nvidia-l4t-kernel-headers (4.9.140-tegra-32.4.3-20200625213809) ...
Unpacking kernel headers...
Setting up nvidia-l4t-camera (32.4.3-20200625213809) ...
Setting up nvidia-l4t-gstreamer (32.4.3-20200625213809) ...
Processing triggers for nvidia-l4t-kernel (4.9.140-tegra-32.4.3-20200625213809) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
~/Linux_for_Tegra
Removing QEMU binary from rootfs
Removing stashed Debian packages from rootfs
L4T BSP package installation completed!
Rename ubuntu.desktop --> ux-ubuntu.desktop
Copying USB device mode filesystem image to /home/ubuntu/Linux_for_Tegra/rootfs
Disabling NetworkManager-wait-online.service
Disable the ondemand service by changing the runlevels to 'K'
Installing extlinux.conf into /boot/extlinux in target rootfs
Success!

Bam. And Nvidia’s kernel, modules, and debian packages get installed using the same techinque as we used above (the script runs dpkg in a chroot). At the above link there are detailed instructions on customizing those bits if you need to.

The last step is to master the card image.

Apparently, python needs to be installed or it’ll complain about a missing “signed” dir so we’ll

sudo apt install python

and finally, to create the image itself:

ubuntu@tegra-image-maker:~/Linux_for_Tegra/tools$ sudo ./jetson-disk-image-creator.sh -o sdcard.img -b jetson-nano -r 200

You’ll find a sdcard.img in the path you ran that script.

If your board revision is not 200, or you have a Xavier NX, you will need to adjust the above command accordingly. Help (currently) is as folows, but if you’re reading this in the future you should check with --help anyway.

ubuntu@tegra-image-maker:~/Linux_for_Tegra/tools$ ./jetson-disk-image-creator.sh --help
********************************************
     Jetson Disk Image Creation Tool     
********************************************
ERROR: This script requires root privilege
Usage:
jetson-disk-image-creator.sh -o <sd_blob_name> -b <board> -r <revision>
        sd_blob_name    - valid file name
        board           - board name. Supported boards are:
                           jetson-nano
                           jetson-xavier-nx-devkit
        revision        - SKU revision number
                           jetson-nano: 100/200/300 for A01/A02/B00
                           jetson-xavier-nx-devkit: default
Example:
jetson-disk-image-creator.sh -o sd-blob.img -b jetson-nano -r 300
jetson-disk-image-creator.sh -o sd-blob.img -b jetson-xavier-nx-devkit

And there you have it. You can copy sdcard.img to your host (or wherever) and flash it on a SD card with Etcher, and it will include your software pre-installed.

1 Like

Hope that helps, @sarthak.srivastava14apr

If you need help customizing the kernel or modules, lmk. There’s another thread that I did on that but it’s a bit out of date.

1 Like

I am trying to back up Jetson nano image files but failed because of permission errors. I was facing permission problem when copy proc folder, I tried to change permissions using
sudo chmod -R u+rw /proc
command, but giving error
error: operation not permitted
so please suggest me how to solve this problem and its necessary copy proc folder or not while backup the image? Thank you

could you detach the microsdcard and backup it at some other device e… using card reader?

I tried this but without format sd card we can’t use in other device like laptop… Please suggest

if your laptop hhas ubuntu you should be able to see the sdcard in lsblk or df -h outputs;
it doesn’t need to be recognized as a mounted folder in order to be dumped with dd

1 Like

@shankarjadhav232
/proc is a virtual filesystem, so you can’t back it up. It’s created by the kernel and the files inside are not real files. I wouldn’t recommend trying to back up an entire sd card or live Nano. Rather, create a script to install your necessary things and apply that either in a chroot as above or on a live system. Packaging your app or or writing such a script so this is possible will save you time and headaches later, so the inital cost is more than worth it.

You can copy other files or even python packages, but be aware that doing so will require an understanding of unix permissions and the basic filesystem structure. You may find this handy cheat-sheet helpful:

I take backup of jetson nano image successfully and i flash this image in same jetson nano again but he take same user id and password. my Question is can i use this image for another jetson nano ? please reply…

I take backup of jetson nano image successfully and i flash this image in same jetson nano again but he take same user id and password. my Question is can i use this image for another jetson nano ? please reply…

@shankarjadhav232

No, it’s not safe.

As @mdegans says, it is not safe. I will qualify though that if you are flashing the exact same install to another Nano using the same exact flash software release, and if there are no “/etc/udev” entries depending on specific MAC addresses or serial numbers, then it stands a chance of working (but is definitely not a guarantee). As soon as you use different eMMC versus microSD variants, you are guaranteed a fail. As soon as you mix across a different release of flash software versus the clone source, you are guaranteed a fail.

yes, while it might perfectly work for a development test trial;
it is not possible to make sure if a rocket launched under control of such device wouldn’t blow up in the air as Airane 5 did back in 1996. ref: ARIANE 5 Failure - Full Report
Well, to be honest it neither would be possible to make sure the rocket wouldn’t explode given no prior cloning takes place at all. So it is more like about a complex structure that with some odds might fail or might not fail. Taking safety & security risks we increase useability, typically, but also increase odds that the system will fail due to some internal or external factor.
So in short : it depends, on policies, constraints, requirements & resources. From a technical prospective an exact clone of one nano will work on another nano - you may like to insert sdcard from one nano device to another to test it. On the other hand security policies might reqest to isolate resources of user of nano 1 & user of nano 2 so that it would require extra effort to address these concerns.
As far as I remember mksparse method would address to certain extend the issue of deployability of OS to many devices in a more meaningfull manner than a full dump does. However, it also might make sense to consider other options, including flashing of default rootfs that yet doesn’t contain any specific to hardware identifiers data, etc.

1 Like

when i run this command i got this error please check

chroot: failed to run command ‘/bin/bash’: Exec format error

please suggest what can i do next…
Thanks

@shankarjadhav232
Try this, and try again:

sudo apt install binfmt-support qemu-user-static

You may have to reboot your VM.

I am not using VM ,i have linux system i used this one . i Explain what i am doing exactly ,when i run

sudo cp enter_chroot/enter_chroot.sh /usr/bin/

i didn’t find enter_chroot.sh file in usr/bin/ then i try with
sudo nautilus
and copy manually enter_chroot.sh to user/bin/
it is okay ?

then i tried

sudo enter_chroot.sh Linux_for_Tegra/rootfs/

but i got
chroot: failed to run command ‘/bin/bash’: Exec format error.

Now i tried your solution also but i am getting same error…please help