Clone SD card while Jetson Nano is running like on the Raspberry Pi

On the Raspberry Pi you can clone the SD card while the Raspberry Pi is running with the “SD Card Copy” menu option. This is very convenient because you don’t need room on a PC harddrive to clone the card, in fact you don’t need a PC at all. I didn’t think copying a running OS would be possible, but they made it work somehow (I tried it).

The SD card in my Jetson Nano is so large that there is no room on my PC to clone it, so I’m looking for a method to clone the SD card while it is running, just like on the Raspberry Pi. I don’t know enough about Linux to figure it out myself, so I looking for help from the experts here.

What would you clone the SD to if you don’t have a PC? I know you don’t really intend to copy a partition to itself, but as far as the math goes, cloning a partition to itself implies a need to double the original partition size. What will you clone to?

I would clone it to another SD card in a USB SD card holder, as a backup. Works great on the Raspberry Pi.

I haven’t tried this but if the extra SD card when it’s plugged into the USB port shows up as /dev/sda then it should be possible to clone the card by installing the following project:

It would then boot to the USB connected device, but then if you afterwards run:

cd sbts-bin
sudo ./make_orig.sh
sudo reboot

This should reboot to the original SD card with what is essentially a clone installed to the new card. To make it a real clone you would simply need to do the following:

mkdir /tmp/mnt

sudo mount /dev/sda1 /tmp/mnt
cp /tmp/mnt/boot/extlinux/orig_extlinux.conf /tmp/mnt/boot/extlinux.conf
umount /tmp/mnt
rmdir /tmp/mnt

This is rather a long winded way to do what is essentially an rsync command but it does take care of creating the partitions for you automatically as well and would do what you needed. And it’s super easy to carry out.

(The untested assumption here is that an SD card when mounted via a USB card holder shows up as /dev/sda). Which I think is likely as I’ve seen similar things on other Ubuntu systems.

Cheers,
Kim

There are many ways to do this. Have not tried @kimv9rqv’s method, but probably it is just a variant of what I’ll suggest.

The primary issue of a clone of a running system is that the filesystem might change during the clone. There is more than one way to put the filesystem into a read-only mode, but if you have a keyboard directly connected to the running Jetson, it is easy to put this into read-only with a “Magic SysRq” key combination. It is worth talking about this all by itself before talking about methods of clone…

If using a serial console, then there is a variant of this using the “echo” command. If this is the case for you, then let me know and I’ll provide that version. With a locally connected keyboard, and with as few programs as possible running, use this set of key combinations:

# The "s" will "sync" twice:
CTRL-ALT-SYSRQ s
CTRL-ALT-SYSRQ s
# This umount the filesystem, and then remount it read-only:
CTRL-ALT-SYSRQ u
# ...now do clone steps...
# Once done with clone steps this will reboot:
CTRL-ALT-SYSRQ b

Actual mount commands have ways of doing something similar as well. Once you are read-only you can use most any method to clone. In your case probably use of “dd” to create an exact duplicate of the whole partition would do well. Another variant is to use “rsync”.

Like @kimv9rqv I will assume your backup destination is “/dev/sda” for that SD card. If it is something else, then adjust accordingly. Assuming there is a partition ("/dev/sda1") mounted at “/mnt” here is an example to clone:
sudo dd if=/dev/mmcblk0p1 of=/mnt/clone.img bs=1M

Note that “bs=1M” for a 1 MB buffer is optional and is only for improved performance. If I were working on a data recovery project with a failing memory I’d use a BS of 512 (which is default) and some other options to deal with failing sectors.

The file clone.img could be used to create an SD card partition from another computer, or used as “system.img” during a flash.

Hm. If I have to stop the services before I can clone the SD card I would feel safer to use two SD card holders on my PC and clone from one to the other without storing the image on my PC. This would solve my problem that I don’t have enough room on the PC’s harddrive. If I understand it right I could use dd for this. That should work regardless of the size.

I have to wonder though how the Raspberry Pi is doing this, because you can clone the SD card to another SD card in a USB holder, while the Raspberry Pi is running. That means files may change, yet it works. Perhaps I should make inquiries in a Raspberry Pi forum for experts.

From the perspective of cloning a running system the issue would be if the filesystem changes during the clone. Many services can run which only alter RAM, and remounting the filesystem read-only is the best way to be certain it isn’t going to change.

The concept of adding extra storage to the PC is actually a very good way of dealing with this. A thumb drive on the PC, or an SD card on the PC, or an external USB SATA drive would all be good choices for a clone destination. “dd” can be used in combination with ssh to directly stream the dd output to the PC’s external storage media. Or you could plug a second USB media directly into the Jetson. Clone methods can simply be chosen which do not cross partition boundaries or filesystem boundaries and you’d get the correct content (using recursive cp would fail).

You can clone from one SD card to another directly on the Jetson, but again I must emphasize that it is best to have the rootfs mounted read-only during the process. This is nothing unique regardless of hardware or version of Linux, this is a general “should always do this if cloning”. If you suggest which destination you want, then more specific instructions can be added. Normally you will find the difference between methods to be how the filesystem is set to read-only during the clone.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.