Xavier Cloning

hi @Andrey1984

may i know usually which method do you use?
i found these from internet around 4 methods.
which way is clean and efficient?

# losetup offset
** partition layout
$ sudo fdisk -lu sda.img
Device Boot      Start         End      Blocks   Id  System
sda.img1   *          56     6400000     3199972+   c  W95 FAT32 (LBA)
56*512=28672
** mount loop
$ sudo losetup -o 28672 /dev/loop0 sda.img
** file system check
$ sudo fsck -fv /dev/loop0
** mount
$ sudo mount /dev/loop0 /mnt
** unmount
$ sudo umount /mnt
$ sudo losetup -d /dev/loop0

# kpartx
$ sudo apt-get install kpartx
$ sudo losetup -Pf disk_image.raw
$ sudo kpartx -av disk_image.raw
add map loop0p1 (252:2): 0 3082240 linear /dev/loop0 2048
add map loop0p2 (252:3): 0 17887232 linear /dev/loop0 3084288
$ sudo mount /dev/mapper/loop0p2 /mnt
$ sudo umount /mnt
$ sudo kpartx -d disk_image.raw

# gnome
$ gnome-disk-image-mounter sda.img

# losetup
$ sudo losetup /dev/loop2 sda.img
$ sudo losetup --show -f -P my.img
$ sudo mkdir -p /mnt/diskname
$ sudo mount /dev/loop1 /mnt/diskname
$ sudo umount /mnt/diskname
$ sudo losetup -d /dev/loop1

typically I ask google how to mount raw image in a loop and pick something from search results;
eventually one or another command works
e.g. LMGTFY - Let Me Google That For You
from search results I would pick smething like:
What is the difference between mount and mount -o loop - Unix & Linux Stack Exchange
dd - Can I mount a partition from a full drive image? - Unix & Linux Stack Exchange
command line - Mounting Disk Image in Raw format - Unix & Linux Stack Exchange
linux - How can I mount partitions in a full disk image (i.e. image with partition table) with fuse? - Unix & Linux Stack Exchange
How can I mount a partition from dd-created image of a block device (e.g. HDD) under Linux? - Super User
However, as far as I remember the three-steps-method is depreciated in current linux releases, as the procedure can be done in 1 step. The Offset also doesn’t not require calculation anymore. When I am accessing computer with raw images next time I can try to retrieve the command.

please create a github… highly recommended ;)
for new comer is really pain in the back…

which of the command you listed above did not work for your for mounting?
there is a procedure defined here for dumping: Jetson/AGX Xavier Alternative II For Cloning - eLinux.org

next step…

i hope to make system.img work. the sparse version.
i still not sure why it failed and how to fix it.

you made the system raw of the entire mmcblk0;
it needs to be converted to be compliant with flash.sh or mksparse;
as defaults presume that images are created from mmcblk0p1
in the latter case it would be possible to use it with flash.sh / mksparse as is
looped mmcblk0 will also have the parftition mmcblk0p1
so that it can be extacted separately and processed by flash.sh
the reason why it did not work at once was that
mmcblk0 & mmcblk0p1 are differnt images;
while the former is supported for entire disc recovery, the latter is only APP partition recovery;
so when the flash.sh script for APP partition recovery finds an entire disk image with dozen of partitions it fails, as it doesn’t have instrucitons for that use case. It is only good for one partition recovery.

sudo ./mksparse -v --fillpattern=0 /data/image.raw system.img
system.img size is 15GB
sudo ./flash.sh -S 15GiB -r jetson-xavier mmcblk0p1
fail. any idea?

how exactly did you create the raw image? which exactly command did you use to create the raw image?
is it raw image of APP partition mmcblk0p1 or of the entire disk? mmcblk0?

sudo dd if=/dev/mmcblk0 of=’/media/nvidia/Data/backup/jetpack_4.2/Disk Image of mmcblk0 (2020-08-11).img’ status=progress

whole process is here
https://forums.developer.nvidia.com/t/xavier-cloning/65159/71?u=albert.a

as I mentioned before; there is a differenrce between mmcblk0 & mmcblk0p1

  • you made full disk dump;

  • mksparse&flash.sh support single partition dump only,

as is the full disk dump is supported by dd recovery method only, [experimental live rewrite of underlying eMMC]
so that it will override the whole disk- dozen of partitions on eMMC,
it is why it is required to extract from the full disk dump only one app partition mmcblk0p1;
or at once just do raw from the mmcblk0p1 if you are concerned in using mksparse & flash.sh method

1 Like

will try this. thanks.
let say the target still bootable, are we still able to overwrite the mmcblk0p1 even thought it is mounted?
in ubuntu pc, usually we boot from thumb drive to overwrite the sda image for restore.

i think i missed out this point. it make sense why it fail now.

However, the full disk dump still contains all partitions as components, as the entire disk structure has been dumped.,
so that mmcblk0p1 [ APP partition] can be dumped from within the existent full disk dump,
given the latter is mounted via the loop device so it will get into a form of disk structure from that the single partition raw image can be dumped and further processed by default scripts like flash sh etc.
Experemental method - steps for live disk rewrite from booted OS I shared previously, as a respond to your earlier post in the current thread. it uses magic keys/ system triggers to get it possible to rewrite system disc been booted from it, via unmounting all drives, and then remounting them as readwrite. Or even without remounting dd might sork. For me from 20 uses it failed in 0 cases., but it might be considered safer for your use case to extract partition from full raw disk dump, probably, then to override disc with Os running from it?

may i know this patch fix which particular problem? for example?
thanks in advanced

cheers

This is a sparse image, not a raw image. The size is invalid for a raw image. In the case of using “-S size” during a flash it depends on the raw size, not sparse. “-S 15GiB” is far too small for the expanded size.

Hi @Andrey1984

dd the APP image back to mmcblk0p1 seems like sure win solution. Thanks for your recommendation.

Might this be coming in Jetpack 4.5? I’m homebrewing some scripts, and will gladly wait a month or so if this is on the docket.

Did this already happen ?

we have got the documentation updated pertaining cloning

@Andrey1984 Thnks Just Saw that !!