An often asked question is “How do I backup the SD card for a Jetson Nano or Jetson Xavier NX?” Here’s an answer, “Let’s use the dd tool”! Looky here:
Background
According to Wikipedia, dd is a command line utility, the primary purpose of which is to convert and copy files. With dd, you can easily copy a partition or an entire drive.
The dd command is the oldest disk imaging tool on Linux still in use. Why? Because it works! dd is a powerful tool. We will use it to create a clone of a Jetson µSD card into an image file using an Ubuntu host computer. Then we will use the image file to create a clone image on another card.
Careful Icarus!
The dd utility will copy every byte on your µSD card (even unused space). We will use a file compression tool, gzip, to help reduce the size of the µSD card image.
Note: Naturally, you will need enough drive space on your host computer to store the card image. If you do not use file compression, the size of the image file will be the size of the µSD card. For example, if you have a 64GB SD card, then you will need a little more than 64GB in free drive space on the host to create the image file.
Here are some SD cards and drives we use here at JetsonHacks:
SD Cards
- Samsung EVO 64 GB micro SD card: https://amzn.to/2Z39qBc
- SanDisk 64GB Extreme: https://amzn.to/30DFzzu
External USB Drives
- SAMSUNG T7 Portable SSD 500GB (other sizes available): https://amzn.to/3gFBxw8
- Western Digital 8TB (other sizes available): https://amzn.to/2ZLSijf
- Seagate 8TB (other sizes available): https://amzn.to/2OLXtZW
By using file compression the resulting image file may be much smaller, but you still need a significant amount of free space.
Let’s Clone!
The first step is to figure out which drive is our µSD card. Plug the card into the host computer. You can then check for the device name using the command line:
$ sudo parted -l
You will see an entry similar to:
Model: Generic- SD/MMC/MS PRO (scsi) Disk /dev/sdc: 63.9GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 2 1049kB 68.2MB 67.1MB kernel 3 68.2MB 135MB 67.1MB kernel_b 4 135MB 136MB 459kB kernel-dtb 5 136MB 137MB 459kB kernel-dtb_b 6 137MB 203MB 66.1MB recovery 7 203MB 204MB 524kB recovery-dtb 8 204MB 205MB 262kB kernel-bootctrl 9 206MB 206MB 262kB kernel-bootctrl_b 10 207MB 311MB 105MB RECROOTFS 11 311MB 311MB 18.4kB UDA 1 312MB 63.9GB 63.6GB ext4 APP
You can also use the Disks GUI application to identify the µSD card:
The device name should be similar to /dev/sdX where the X represents a letter. In the examples above the µSD card is /dev/sdc
The Jetsons have several partitions on the µSD card. These partitions serve a variety of purposes, mostly to do with machine configuration and startup. You will need to copy all of the partitions for your Jetson to work properly with the card.
Note: A number following the device name indicates a partition on the drive. Because we are copying the entire drive, we only need to use the device name, and do not include a partition identifier.
Clone the Drive
The second step is to create the clone of the card:
Make sure that the card is not mounted:
$ sudo umount /dev/sdX
Replace sdX with the actual device. Then:
$ sudo dd if=/dev/sdX conv=sync,noerror bs=64K | gzip -c > ~/backup_image.img.gz
Naturally, you can name the image file and place it where you want. The above will place the backup_image.img.gz file in the home directory. As an example, if the card is /dev/sdc
$ sudo dd if=/dev/sdc conv=sync,noerror bs=64K | gzip -c > ~/backup_image.img.gz
The arguments sets the block size (bs) to 64K (you can experiment with this, larger block sizes are faster), noerror ignores read errors, and sync fills blocks with zeros if there are read errors.
Once the command starts, it may take a long while to complete depending on the size of the card. There is no progress indicator. This may take a while, in the example copying a 64GB card with 15GB in use took around 45 minutes. The amount of time varies widely depending on the usual factors, such as disk speeds, transfer speeds, size of the card and so on. When the copy is done and the Terminal prompt returns, you can remove the SD card from the host computer.
Restore the Drive
Once the image has been created, you are ready to test it out. Using a different µSD card that is the same size or larger than the original, insert the new card into the host computer. Typically we try to use the same type/brand of card, if only for good luck. The card does not have to be formatted, as dd makes a bit for bit copy of the drive.
Then, go for it. Again, make sure that the card is not mounted, and start the restore. Depending on how your system is set up, you may not need to be in super user mode to do the restore. In other words, ignore the sudo su command. To restore:
$ sudo su
$ gunzip -c ~/backup_image.img.gz | dd of=/dev/sdX bs=64K
Where ~/backup_image.img.gz is the path and name of your clone image. For example:
$ sudo su
$ gunzip -c ~/backup_image.img.gz | dd of=/dev/sdc bs=64K
Once this process is complete, you should go check it out in your Jetson! Pop the card in, start it up, and you should be right where you left off with the master disk.
Another Big Fat Warning
You should only use these clones in the same machine. This is a quite wonderful method for creating a backup for your Jetson once you have it setup the way you like it. However, you do not want these clones to run on more than one Jetson due to security reasons. Here’s a more comprehensive NVIDIA Jetson forum thread on the subject: https://forums.developer.nvidia.com/t/jetson-nano-cloning-and-deployment-of-the-image-to-other-devices/74904
Conclusion
The actual process of creating a clone of a µSD for the Jetson is simple. Having a backup (or several) provides quite a bit of comfort when things go bad. Takes a while, but then doesn’t everything?
The post Clone SD Card – Jetson Nano and Xavier NX appeared first on JetsonHacks.