Jetson Nano SD card image

Hi,

we have flashed the SD card for Nano with the jetpack and then installed our software on top.
Now, we’d like to create zip image from the SD card so that we could use it for balenaEtcher in production.

What tool do you use? Is there a manual/tutorial, please?

Cheers,
Martin

If you are using Linux, then this is trivial. The “dd” tool can copy and restore exact images from one SD to another. The image can be loopback mounted and edited if desired (for example, a pure clone would have the same user accounts and passwords…perhaps you don’t want that…or if there was a network customization based on MAC address, then you’d need a new MAC address for each Jetson).

As background, if you have a disk drive or other bulk storage device, then there will be a corresponding device special file for the disk (or SD card) as a whole, and for each partition. If we were speaking of an ordinary SATA drive, then you would see entries from this:

ls /dev/sd*

…where “sda” is the first disk, “sdb” is the second disk, so on. “sda1” is the first partition of the first disk, “sda2” is the second partition of the first disk. “lsblk -f” would give information about UUIDs and filesystem types of the whole list of detected block devices, “lslbk -f /dev/sda” would limit the response to the first SATA drive.

SD cards tend to have a naming convention like “/dev/mmcblk0” (first SD) or “/dev/mmcblk1” (second SD), or “/dev/mmcblk0p1” (first partition of first SD).

One could create a perfect bit-for-bit exact clone of the entire first SD via:

sudo dd if=/dev/mmcblk<b>0</b> of=clone_of_SD.img bs=512

(“bs” is block size, and isn’t critical, but can change how fast reads and writes go…512 is just the smallest block size of any disk, you could use a much larger value if it speeds things up)

This would restore the image to the second SD card:

sudo dd if=clone_of_SD.img of=/dev/mmcblk<b>1</b> bs=512

This would mount the clone for examination or editing:

sudo mount -o loop clone_of_SD.img /mnt
cd /mnt
# Examine, edit, whatever you like:
ls
# Exit the mount area, else you cant unmount (umount):
cd
umount /mnt

“dd” can be slow for production, but as mentioned the “bs” (block size) can speed things up somewhat. There isn’t much you can do about slow SD cards being slow.

NOTE: You do not want to clone a mounted filesystem which might be written to during the clone.

Hi @linuxdev,

thank you for your answer. The dd command is great for taking the image from the SD card.

I’m after post processing of that image. I’d like to end up with a zip file, sized as the software contant rather than SD card size.
The goal is to have image independent on the target SD card. if we decided to go from 16GB to 32GB card it shouldn’t matter.
I need to get the zip compatible with balenaEtcher just like the JetPack original image.

Cheers,
Martin

You can just zip the image. The “sparse” version is much smaller, but once you go that route it can’t be edited. The actual image can be resized the same as a hard disk partition with apps like “gparted” after covering the file with loopback, but you’d have to pick only correct sizes, and then truncate the original file (I consider it simple to do, but most people would have some things to learn to do so safely). If not already installed, then you can easily install the “zip” command.

You can use Nvidia’s script called create-jetson-nano-sd-card.sh (edit: this is now in the /tools/ folder and called jetson-disk-image-creator.sh) in the L4T install path to accomplish that. You add what you need to the rootfs and then assemble a flashable image using that script. The image will expand to any SD card on first boot using resize2fs just like on pi.

/etc/systemd/nvresize2fs.sh (iirc, on mobile) is where Nvidia put the script that is only run on first boot but I believe it self deletes so you will only find it on the unflashed rootfs folder in L4T home (under sdkm install path)

I would suggest, easiest way, is just to add your own first boot scripts, following Nvidia’s outline, to install packages and set up your own software. That way you can flash that image on to any system and it will just work. if you simply clone the image SSH keys and a whole bunch of other things like hostnames would be exactly the same and you’ll have network connectivity and security issues.

Edit:

Suggest using a unit file to launch a script to install stuff after Nvidia’s. Look at their unit files (.service) in /etc/systemd/system as a guide. Please ask if you need help. Systemd’s documentation is opaque.

Please be aware if you do this, it has the potential to include anything that might have ever been written to that particular sd card, so if you are publishing it, random people on the internet with hex editors might be able to recover passwords, wallet files, blackmail material, etc.