From 8c4e3a6ad2b46a1898bf5ccb446c093e5b3b9559 Mon Sep 17 00:00:00 2001 From: jetsonhacks Date: Tue, 16 Apr 2019 19:51:29 -0700 Subject: [PATCH] Add autoMount script --- README.md | 21 +++++++++-- autoMount.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++ installSwapfile.sh | 2 +- 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100755 autoMount.sh diff --git a/README.md b/README.md index 25535ba..6a2fed8 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ Install a swap file on the NVIDIA Jetson Nano Developer Kit. This should help wi ### Setup Swap File > installSwapFile.sh - Create a swap file ; Use on external media like USB drive or SSD -> usage: installSwapFile [[[-d directory ] [-s size] -a] | [-h]] +> usage: installSwapFile.sh [[[-d directory ] [-s size] -a] | [-h]] > > -d | --dir [directoryname] Directory to place swapfile (defaults to /mnt) > > -s | --size [gigabytes] (defaults to 6 ) > -> -a | --auto Enable swap on boot in /etc/fstab (defaults enabled) +> -a | --auto Enable swap on boot in /etc/fstab (default: "Y") > > -h | --help This message > @@ -18,8 +18,25 @@ Install a swap file on the NVIDIA Jetson Nano Developer Kit. This should help wi > > Note: If you enable swap on boot, you should also automount the drive that you're using +### Automount +Automount a device given the label +> autoMount.sh - Automount a device, useful for external media like USB drives + +> usage: autoMount.sh [ [-l label] | [-h]] +> -l | --label Label to lookup +> -h | --help This message +> +> Tool to help automount the device given from the label +> The script looks up the device, mounting point and UUID for the given label +> Optionally add it to /etc/fstab +

Release Notes

+v0.7 April 2019 +* Add Automount Support +* L4T 32.1.0 (JetPack 4.2) +* Tested on Jetson Nano + Initial Release April, 2019 * L4T 32.1.0 (JetPack 4.2) * Tested on Jetson Nano diff --git a/autoMount.sh b/autoMount.sh new file mode 100755 index 0000000..dad4658 --- /dev/null +++ b/autoMount.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# +DRIVE_LABEL="" +function usage +{ + echo "usage: autoMount.sh [ [-l label] | [-h]]" + echo " -l | --label Label to lookup" + echo " -h | --help This message" +} + +if [ $# -eq 0 ] + then + echo "No arguments supplied" + usage + exit 1 +fi + +while [ "$1" != "" ]; do + case $1 in + -l | --label | -L ) shift + DRIVE_LABEL=$1 + ;; + -h | --help ) usage + exit + ;; + * ) usage + exit 1 + esac + shift +done + +echo 'Looking up UUID from the Label:' "$DRIVE_LABEL" + +DEVICE_NAME="" +UUID_STRING="" +if [ "$DRIVE_LABEL" != "" ] ; then + DEVICE_NAME=$(findfs LABEL="$DRIVE_LABEL") + if [ "$DEVICE_NAME" != "" ] ; then + echo "Device: " $DEVICE_NAME + # Lookup UUID + UUID_STRING=$(findmnt $DEVICE_NAME -o UUID) + if [ "$UUID_STRING" != "" ] ; then + UUID_STRING=`echo "$UUID_STRING" | sed -n '1!p'` + echo "UUID: ""$UUID_STRING" + # Get the target name (mount path) + TARGET_STRING=$(findmnt $DEVICE_NAME -o TARGET) + if [ "$TARGET_STRING" != "" ] ; then + echo $TARGET_STRING + TARGET_STRING=`echo "$TARGET_STRING" | sed -n '1!p'` + echo "Mount Path: ""$TARGET_STRING" + echo "" + FSTAB_STRING=`echo "UUID=""$UUID_STRING" "$TARGET_STRING"" auto nosuid,nodev,nofail 0 0"` + echo "Proposed entry to add to /etc/fstab:" + echo "$FSTAB_STRING" + echo "" + echo "Adding this entry will automate the process of mounting the partion at boot:" + echo "Device: "$DEVICE_NAME + echo "UUID: ""$UUID_STRING" + echo "Path: ""$TARGET_STRING" + read -p "Would you like to add this entry to /etc/fstab (y/n)? " answer + case ${answer:0:1} in + y|Y ) + echo "" + echo "Appending to /etc/fstab" + echo "$FSTAB_STRING" | sudo tee -a /etc/fstab + # Mount for changes to take effect + sudo mount -a + ;; + * ) + echo "" + echo "No action taken" + ;; + esac + else + echo "Unable to locate target mount point" + fi + else + echo "Unable to match " $DEVICE_NAME " with UUID" + exit 1 + fi + else + echo "Unable to match drive label with a currently mounted device. Exiting" + exit 1 + fi +else + echo "Please enter a label" + usage + exit 1 +fi diff --git a/installSwapfile.sh b/installSwapfile.sh index 8b106aa..5b550fb 100755 --- a/installSwapfile.sh +++ b/installSwapfile.sh @@ -62,7 +62,7 @@ if [ "$AUTOMOUNT" = "Y" ]; then echo "Modifying /etc/fstab to enable on boot" SWAPLOCATION=$SWAPDIRECTORY"/swapfile" echo $SWAPLOCATION - sudo sh -c 'echo "'$SWAPLOCATION' none swap sw 0 0" >> /etc/fstab' + sudo sh -c 'echo "'$SWAPLOCATION' swap swap defaults 0 0" >> /etc/fstab' fi echo "Swap file has been created"