Startup Script in /etc/rcS.d/ can't access SD card on boot

I am trying to get a python program to run when the Jetson starts up. I have a bash script in the /etc/rcS.d/ directory which points the python interpreter to the target python file on the SD card. However, it appears that the SD card has not yet been mounted when the script is run when the jetson powers up. Thus, when the bash scripts run, it cannot find the file and will end the script without the python file being run.

I need the python file to be on an SD card because I am putting the Jetson in a car and i wont be able to interface easily with it to put new code on it.

Is there a directory that I can place the startup bash script in that will run once the OS has been initialized including mounting external directories like an SD card?

Thanks

Auto-mount won’t occur until the base system is running. Entries in “/etc/fstab” can be made to load at a standard point in the boot process.

Consider that when a partition is set to mount in the usual fashion (such as rootfs) this is typically marked as “mandatory”, and if it isn’t there, boot will halt forever. The simplest approach is to just mount like a hard disk, but it will interfere with boot if you don’t have the SD card there with the partition you named also existing in the SD card.

The basic “just always mount” goes something like this…I will assume “/dev/mmcblk1p1” is your SD card partition. This edit to “/etc/fstab” would be the basic “always there” edit for a mount point of “/usr/local”:

/dev/mmcblk1p1  /usr/local  ext4  defaults  1 2

To set this up as “not automatic” (or perhaps emphasizing “not required for normal boot”):

/dev/mmcblk1p1  /usr/local  ext4  noauto,user  1 2

The trailing “1 2” says file system checking is done, and this is the second device to check. The eMMC is rootfs, so this is actuall “1 1” even if the entry is automatic and not in fstab.

You may be interested in the “nofail” option (see “man fstab”) to allow boot if the SD card is not in place. One variation which tries to auto-mount but which won’t halt boot if missing:

/dev/mmcblk1p1  /usr/local  ext4  nofail,user  1 2

The “user” entry allows any user to mount. Remove this for something everyone shouldn’t have access to (it locks to whoever mounted it until it umounts).

This identifies a partition by device, but you can also use the UUID if one is set…this is “unique” and will only mount that exact partition. For example, run this to see:

lsblk -f

If you use a UUID then other SD cards won’t accidentally be mounted in this SD card’s place. The UUID is randomly generated during mkfs.ext4, but the e2label program can be used to manually set this. You could create a number of SD cards and label any partition with that label, and then regardless of which SD card and regardless of which partition that label occurs on fstab would do the right thing.