How to set TX2 otg usb as device mode?

Yes, package is “gparted”, I missed the “ed”…corrected now.

Looks like that loopback file is formatted for VFAT (a.k.a., “fat32”), and my instructions were for ext4. I think in theory if the right tools are installed, then gparted could work with VFAT, but a Jetson won’t have that by default (and several distributions won’t have that by default). The package which should provide that is “dosfstools” (related package “mtools”). To see if you have this:

dpkg -l | egrep -i '(dosfstools|mtools)'

If you don’t have this, then add via:

sudo apt-get install dosfstools
sudo apt-get install mtools

However, it looks like gparted only allows size reduction for VFAT/fat32. So instead I had to destroy the existing file system…meaning you could just as easily have started with a zero size file (e.g., from ‘touch newname.img’), and then done the truncate operation…truncate won’t care if the existing file starts at any particular size.

My testing is on “/opt/nvidia/l4t-usb-device-mode/filesystem.img” while the device is not used (meaning the script for making this available on the OTG port is off, and “losetup” has not bound any loop device to it). I’m testing with VFAT/fat32 with a size of 512MiB (51210241024…which happens to be divisible by 512, the block size):

<i><b>sudo -s</b></i>
cd /opt/nvidia/l4t-usb-device-mode
losetup -D
truncate ./filesystem.img --size=536870912
losetup --show --find ./filesystem.img 
# Indicates /dev/loop0 for my case...YMMV.
gdisk /dev/loop0
# "p" should show no existing partition.
<enter key three times to accept defaults to use full loopback file>
# You can see various types with "L", but for VFAT it'll be "Microsoft basic data", or "0700":
# gdisk will exit now.
mkfs.vfat /dev/loop0
# It'll complain it isn't the size of a floppy, ignore the warning. Now we test:
mount /dev/loop0 /mnt
df -H -T /mnt
# result using the 512MiB...note that the following is MB, multiples of 1000, not 1024, and so it looks larger than it really is...some space is lost in formatting inefficiencies:
    Filesystem     Type  Size  Used Avail Use% Mounted on
    /dev/loop0     vfat  537M     0  537M   0% /mnt
# Now umount and remove loop device from test location:
umount /dev/loop0
losetup -D
# Now start the script to see if it works for you:

Does this work for you?

So apparently gparted can only enlarge and preserve a file system of certain types, and VFAT/fat32 is not one of those (ext4 can be extended and preserved).