Jetson/Cloning

Like with all x86 host operations performed on the Jetson, you will need the Jetson TK1 Development Pack.

NOTE: If you are only interested in flashing and cloning, then you can download a subset of packages instead of the full Development Pack ("JetPack")...the driver package provides the "Linux_for_Tegra" directory shown below, and the sample rootfs provides the rootfs directory when flashing without a reused clone. The advantage of this is that less host space is required, and the host requirement of running Ubuntu x86_64 Linux is reduced to any x86_64 Linux (Ubuntu is not required for the driver package, but is required for the Development Pack).

Reading partition table
cd into the /opt/JetPackTK*/Linux_for_Tegra/bootloader directory.

You can then get a list of the partitions available by doing:

./nvflash --getpartitiontable table --bl ardbeg/fastboot.bin --go

This will create a text file called table with the partitions listed inside.

Cloning the image
To make a carbon copy of an existing Jetson install, first connect the Jetson's micro-B USB flash port to the Linux machine that you originally flashed L4T from. Then enter the Jetson into recovery mode by holding RECOVERY and pressing RESET.

About the Root Partition and System.img
During normal flash the rootfs subdirectory, along with boot loader option customization, is used to create a file which will become the root file system. This file is loopback mountable as type ext4 (mount -t ext4 -o loop). The original Jetson flash.sh (L4T versions R19.x) uses this file directly, naming it "bootloader/system.img". This file is a bit-for-bit copy of the entire rootfs, and so if Jetson's root file system is 15GB, so is this file. This takes significant time to install, and so a compressed version of this file is generated in L4T versions R21.x and higher.

The application "bootloader/mksparse" creates a compressed version of the root file system using the "0" fill pattern. flash.sh moves the uncompressed system.img to the new name system.img.raw, and mksparse then generates the new "bootloader/system.img". The "raw" file is the loopback mountable image, the "sparse" file is used for actual flash, making flash time significantly shorter. A cloned root partition is a raw loopback mountable image (optionally converted to a sparse format).

flash.sh in R21.x works with either a sparse image or a raw image at "bootloader/system.img". If you desire a faster flash or smaller system.img size, mksparse can be used (this assumes "bootloader/system.img" was created via cloning and is a raw, uncompressed image): cd bootloader sudo mv system.img system.img.raw sudo mksparse -v --fillpattern=0 system.img.raw system.img

During flash to restore a clone of the root partition the size parameter corresponds to the size of the raw image in units of 1024. For example, if the original flash.sh parameter "-S" is chosen as 14580MiB, then the valid system.img.raw will be exactly 14580 * 1024 * 1024 bytes, or 15288238080 bytes. For an original "-S 14GiB", the resulting raw image would be 14 * 1024 * 1024 * 1024 = 15,032,385,536 bytes (slightly smaller than 14580MiB).

Old Jetson TK1 Development Pack
cd into the Linux_for_Tegra/bootloader directory that you used when originally flashing the Jetson. Inspect flash.cfg to obtain the partition id of system.img (in this case, 9)

[partition] name=APP id=9 type=data allocation_policy=sequential filesystem_type=basic size=15288238080 file_system_attribute=0 partition_attribute=0 allocation_attribute=8 percent_reserved=0 filename=system.img

Next, remove the old system.img built from the initial flashing and download the new image from the Jetson. If the id of your system.img partition is different than 9, substitute that in the nvflash command.

sudo rm system.img sudo ./nvflash --read 9 system.img --bl fastboot.bin --go

(On more recent Jetson TK1 Development Pack releases, fastboot.bin has been moved to ardbeg/fastboot.bin)

(downloading the image can take a while)

Recent Jetson TK1 Development Pack
A partition can be read by name or number. APP is the partition of the root filesystem. You can check you have an APP partition in the partition table. It will probably be partition 9.

You can then clone the partition to a file called system.img by doing:

sudo ./nvflash --read APP system.img --bl ardbeg/fastboot.bin --go

(downloading the image can take a while)

You can also clone the whole flash by doing:

sudo ./nvflash --rawdeviceread 0 3849216 all.img --bl ardbeg/fastboot.bin --go

(downloading the image can take a while)

Mounting
To mount the backed-up image to your system, execute the following command: sudo mount -t ext4 -o loop system.img /mnt

You can now inspect the Jetson's filesystem in /mnt and make edits, perform cross-compiling, ect. When finished, unmount the image with: sudo umount /mnt

Restoring
The image can be restored to a Jetson by flashing it with the -r 'skip building and reuse existing system.img' flag. Substitute the size of your partition if you originally flashed with a size different than 14580MiB.

cd ../ sudo ./flash.sh -r -S 14580MiB jetson-tk1 mmcblk0p1

Reboot the Jetson when it's done flashing and the system should be restored to the state at the time of cloning.

Likewise the following restores a full image clone. sudo ./nvflash --rawdevicewrite 0 3849216 all.img --bl ardbeg/fastboot.bin --go

Packaging
Keep the Linux_for_Tegra directory used during the cloning process to successfully restore the image. Linux_for_Tegra/rootfs can be removed as it's no longer needed. However the other L4T files should be transported along with the system.img to use during restoration.

sudo rm -r -f rootfs cd ../ tar -zcvf my_backup.tar.gz Linux_for_Tegra

tar.gz can significantly compress the size of system.img and will retain the access privileges and is now convenient to copy/FTP/ect.

Re-Package system.img
It is sometimes quicker to modify the content of the device system partition and flash it back to the Jetson board.

Latest version of Jetpack script for rootfs assembly/uploading (flash.sh) creates in your Linux_for_Tegra directory both system.img and system.img.raw files.

Those files can be used to access content of the system partition, modify it, and the upload the modified content to the board. Before doing anything of this, you may want to back-up both of them to able to restore the original content later.

It's fairly easy to loop-mount the raw system image file, then modify its content. Once done with modifications, it can be re-packed nicely and uploaded to Jetson using the -r option of flash.sh script.

First, mount the currently deployed system.img file

Linux_for_Tegra$ sudo losetp -d /dev/loop0 Linux_for_Tegra$ sudo losetup /dev/loop0 bootloader/system.img.raw Linux_for_Tegra$ sudo mount /dev/loop0 /mnt/

You can now access content of rootfs under /mnt/. Once done with modification unmount it and proceed with packaging the system image and upload that to Jetson

Linux_for_Tegra$ sudo umount /mnt/ Linux_for_Tegra$ sudo losetp -d /dev/loop0 Linux_for_Tegra$ bootloader/mksparse -v --fillpattern=0 bootloader/system.img.raw bootloader/system.img Linux_for_Tegra$ sudo ./flash.sh -r jetson-tk1 mmcblk0p1