Skip to content

Commit

Permalink
Add autoMount script
Browse files Browse the repository at this point in the history
  • Loading branch information
jetsonhacks committed Apr 17, 2019
1 parent 348d50c commit 8c4e3a6
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,39 @@ 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
>
> Defaults to creating a 6GB Swapfile in the current directory
>
> 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 <labelname> 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
<h2>Release Notes</h2>

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
Expand Down
89 changes: 89 additions & 0 deletions autoMount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
#
DRIVE_LABEL=""
function usage
{
echo "usage: autoMount.sh [ [-l label] | [-h]]"
echo " -l | --label <labelname> 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
2 changes: 1 addition & 1 deletion installSwapfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8c4e3a6

Please sign in to comment.