Repository: JetsonHacksNano/installSwapfile Branch: master Commit: 838403c20561 Files: 4 Total size: 7.4 KB Directory structure: gitextract_7379u4fh/ ├── LICENSE ├── README.md ├── autoMount.sh └── installSwapfile.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2019 JetsonHacksNano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # installSwapfile Note: While you can still use this method to add a swap file, note that newer versions of L4T/JetPack have swap memory as part of the default distribution, implemented through zram. You may choose to use both a swapfile, as implemented here, and the zram swap memory at the same time. Original article on JetsonHacks: https://wp.me/p7ZgI9-1ac Install a swap file on the NVIDIA Jetson Nano Developer Kit. This should help with memory pressure issues. ### Setup Swap File > installSwapFile.sh - Create a swap file ; Use on external media like USB drive or SSD > 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 (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 > > Example usage: > > $ ./shellScript.sh -l RaceUSB > > where RaceUSB is the label of the device mounted at /media/jetsonhacks/RaceUSB > > 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 ================================================ FILE: autoMount.sh ================================================ #!/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 ================================================ FILE: installSwapfile.sh ================================================ #!/bin/bash # Copyright 2017-2019 JetsonHacks # MIT License # Create a swap file and set up permissions # If a parameter is passed, it should be the place to create the swapfile set -e SWAPDIRECTORY="/mnt" # Ubuntu recommends 6GB for 4GB of memory when using suspend # You can use 1 or 2 if need be SWAPSIZE=6 AUTOMOUNT="Y" function usage { echo "usage: installSwapFile [[[-d directory ] [-s size] -a] | [-h]]" echo " -d | --dir Directory to place swapfile ( default: /mnt)" echo " -s | --size (default: 6)" echo " -a | --auto Enable swap on boot in /etc/fstab (default: Y)" echo " -h | --help This message" } while [ "$1" != "" ]; do case $1 in -d | --dir ) shift SWAPDIRECTORY=$1 ;; -s | --size ) shift SWAPSIZE=$1 ;; -a | --auto ) shift AUTOMOUNT=$1 ;; -h | --help ) usage exit ;; * ) usage exit 1 esac shift done echo "Creating Swapfile at: " $SWAPDIRECTORY echo "Swapfile Size: " $SWAPSIZE"G" echo "Automount: " $AUTOMOUNT #Create a swapfile for Ubuntu at the current directory location sudo fallocate -l $SWAPSIZE"G" $SWAPDIRECTORY"/swapfile" cd $SWAPDIRECTORY #List out the file ls -lh swapfile # Change permissions so that only root can use it sudo chmod 600 swapfile #List out the file ls -lh swapfile #Set up the Linux swap area sudo mkswap swapfile #Now start using the swapfile sudo swapon swapfile #Show that it's now being used swapon -s if [ "$AUTOMOUNT" = "Y" ]; then echo "Modifying /etc/fstab to enable on boot" SWAPLOCATION=$SWAPDIRECTORY"/swapfile" echo $SWAPLOCATION sudo sh -c 'echo "'$SWAPLOCATION' swap swap defaults 0 0" >> /etc/fstab' fi echo "Swap file has been created" echo "Reboot to make sure changes are in effect"