To preserve the existing install when root access is gone would basically require cloning the root partition, mounting it on you host under loopback to repair the file system (you could copy the sample rootfs sudoers file on top of the loopback version if careful to maintain permissions), and then flash again reusing the clone instead of generating a new image. This takes significant time since a clone takes longer than a flash (perhaps hours depending on partition size).
Ubuntu by default locks the root account. Only sudo can access root. I tend to use ssh keys for automatic login among my Jetsons over ssh, for which I typically unlock the root account, set up keys, then lock it out again…leaving direct key access to root without local password login (part of the account is still locked). I advise to only do this on a private network with no outside world access.
If interested in cloning you first have to get a modified flash.sh. You can mouse copy-and-paste this version:
Actual clone command:
Note that the alternate flash.sh adds the “-G” option. Otherwise this flash script functions the same as the original (probably this version will be provided in the next L4T release).
More information about clones is here…this is for a TK1 instead of TX2, but mostly the information applies: