How to clone TX2 to SD Card as it is?

Hi. I’m currently trying to clone my TX2 image to SD Card because it has no space left to work on it anymore. How can i clone this whole 30 GB TX2 system image to SD card without any change and flash from that card everytime i open the TX2?

Is this R28.1? clone differed in some of the earlier releases, e.g., R27.1 required flash.sh patch.

Generally speaking you can clone the rootfs from a host by putting the Jetson in recovery mode and connecting the micro-B USB cable. You then run this from the driver package (which JetPack has as a subdirectory if you used JetPack):

sudo ./flash.sh -r -k APP -G clone.img jetson-tx2 mmcblk0p1

The above would produce clone.img and clone.img.raw. It is the clone.img.raw you need…the non-raw is a sparse image and can be used for flash but cannot be mounted or converted back to non-sparse without actually flashing. I’d recommend delete the clone.img, and if you want to save host disk space (it is about 30GB), then something like a very long “bzip2 -9 clone.img.raw”). If you don’t expect to make changes and will only use this clone for exact restore of the rootfs, then you can just use the “clone.img” file (which is smaller and much faster to flash).

If you use either the clone.img or clone.img.raw by placing it in the “bootloader/” directory with name “system.img”, and then use the “-r” re-use flag to flash.sh, it will use that clone for the flash.

sudo flash.sh -r jetson-tx2 mmcblk0p1

A non-sparse (raw) clone can be viewed via something like this (a good way to validate the clone):

sudo mount -o loop clone.img.raw /mnt
cd /mnt
ls
cd -
sudo umount /mnt

Normally system.img is generated from the “rootfs/” subdirectory after applying some boot configuration edits. You could also mount or copy the clone into rootfs (instead of the sample rootfs), but expect some edits to items in “rootfs/boot/”…if you loopback mount a clone on rootfs, then the clone will get those edits to “rootfs/boot/”. If you re-use system.img the “boot/system.img” is directly used and no edits and no file copies ever occur. Other partitions (e.g., dtb and things not normally customized) get flashed and you keep everything in the root partition constant.

Life is easier if you have a serial console and can pick optional boot entries at boot. I’d suggest using this for your eMMC (mmcblk0p1) version of “/boot/extlinux/extlinux.conf”:

TIMEOUT 30
<b>DEFAULT primary</b>

MENU TITLE p2771-0000 eMMC boot options

LABEL primary
      MENU LABEL primary kernel
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk<b>0</b>p1 rw rootwait rootfstype=ext4

LABEL sdcard
      MENU LABEL sdcard mmcblk1p1
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk<b>1</b>p1 rw rootwait rootfstype=ext4

I’ll suggest the inverse of this on the SD card (mmcblk1p1):

TIMEOUT 30
<b>DEFAULT sdcard</b>

MENU TITLE p2771-0000 eMMC boot options

LABEL primary
      MENU LABEL primary kernel
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk<b>0</b>p1 rw rootwait rootfstype=ext4

LABEL sdcard
      MENU LABEL sdcard mmcblk1p1
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk<b>1</b>p1 rw rootwait rootfstype=ext4

When no SD card is connected you may want to do this to mark it:

sudo touch /this_is_eMMC.txt

If you mount the SD card somewhere and mount it, then you might want to do this to mark it:

sudo touch /where/ever/this_is_SD_card.txt

After boot you’ll know which is on the root mount with “ls /*.txt”.

It is Jetpack 3.2 so I think it is R28.2. Do you think there will be a problem with your solution?

Many partitions will differ in R28.1 versus R28.2, but the rootfs (“APP”) partition should remain mmcblk0p1. Could someone with R28.2 verify the rootfs is still mmcblk0p1?

You won’t be able to mix a cloned rootfs of R28.1 with R28.2. But if everything is R28.2 (or if everything is R28.1), then there probably is not any difference in how cloning and restoring works. You’d have to try it to be certain.

You can see what the partition labels are on your TX2 via (“APP” is rootfs):

sudo gdisk -l /dev/mmcblk0

Yes, on R28.2-DP, APP is still partition1 (https://devtalk.nvidia.com/default/topic/1005599/how-to-get-usb-3-0-at-a-custom-connecttech-orbity-carrier-board-at-5gb-speed-/?offset=37#5235526)

Sorry but I have no experience about flashing a TX2 so it’s a bit complicated to me. I’ve cloned the image to my host pc (it is inside a file named Jetpack). Should I do these steps? Copy that whole Jetpack file to sd card and mount it to TX2 then open a terminal from the Jetpack file and run:

sudo flash.sh -r jetson-tx2 mmcblk0p1
sudo mount -o loop clone.img.raw /mnt
cd /mnt
ls
cd -
sudo umount /mnt

Then configure these on TX2’s own /boot/extlinux/extlinux.conf file with:

TIMEOUT 30
DEFAULT primary

MENU TITLE p2771-0000 eMMC boot options

LABEL primary
      MENU LABEL primary kernel
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4

LABEL sdcard
      MENU LABEL sdcard mmcblk1p1
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk1p1 rw rootwait rootfstype=ext4

and also configure these inside Jetpack file (/boot/extlinux/extlinux.conf):

TIMEOUT 30
DEFAULT sdcard

MENU TITLE p2771-0000 eMMC boot options

LABEL primary
      MENU LABEL primary kernel
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4

LABEL sdcard
      MENU LABEL sdcard mmcblk1p1
      LINUX /boot/Image
      APPEND ${cbootargs} root=/dev/mmcblk1p1 rw rootwait rootfstype=ext4

Then reboot the TX2 with mounted SD card.

Cloning is described here:
https://elinux.org/Jetson/TX2_Cloning

Verify “Jetpack” is a clone. Run this command from its directory:

file ./Jetpack

…it should have “ext4 filesystem data” in the description.

Copy this to the “Linux_for_Tegra/bootloader/” directory with the name “system.img” (this will take a lot of time).

With the micro-B USB connected to the Jetson, and the Jetson in recovery mode, run this from the “Linux_for_Tegra/” directory:

sudo ./flash.sh -r -K APP jetson-tx2 mmcblk0p1

Note: The “-r” says to re-use the system.img instead of generating a new one. The “-K APP” names the rootfs partition as the partition to flash.

The technique I described in the following blog post works for JTX2 too.

https://jkjung-avt.github.io/sd-rootfs-on-tx1/

You simply:

  • copy the whole root filesystem from eMMC to SD card
  • modify /boot/extlinux/extlinux.conf (root=/dev/mmcblk1p1)
  • modify /lib/init/fstab (mount /dev/mmcblk1p1 as /)
  • reboot and verify the JTX2 system has booted using the SD card as root device

I followed linuxdev’s way and it succeeded. But I would choose your(easy) way at the beginning.