Skip to content

Instantly share code, notes, and snippets.

@kcoyner
Created March 3, 2016 19:01
Show Gist options
  • Save kcoyner/413466c10aaab3dfe763 to your computer and use it in GitHub Desktop.
Save kcoyner/413466c10aaab3dfe763 to your computer and use it in GitHub Desktop.
remount an SD card with different privileges
#!/bin/bash
# Simple script to remount an already mounted SD card
# Also sets the readahead speed to 1024
# Kevin Coyner
# 2016-02-26
# # Parameters to be set
# #--------------------------------------------------------------------
# Where is the SD card mounted presently?
SDMOUNT="/var/host/media/removable/Kevin"
# How do you want the card remounted? [comma separated list of valid mount options]
REMOUNTOPTIONS="rw,exec,suid"
# Set to 1 to debug, otherwise 0
DEBUG=1
# # End parameters
# #--------------------------------------------------------------------
set -e
set -o nounset
if [[ ${DEBUG} -eq 1 ]]; then
set +e
fi
if [[ -d $SDMOUNT ]]; then
# see if there is a device at the SDMOUNT mount point
# if so, then get its address
# #--------------------------------------------------------------------
CARDMOUNT=`mount | /bin/grep "${SDMOUNT}"` 2>&1
if [[ -z "${CARDMOUNT}" ]]; then
# Abort: There is no card mounted at ${SDMOUNT}
if [[ ${DEBUG} -eq 1 ]]; then
echo "Abort: There is no card mounted at ${SDMOUNT}"
fi
exit 0
else
# There is a card mounted at ${SDMOUNT}, get its address
SDDEVICE=`echo ${CARDMOUNT} | cut -f1 -d' '`
# Remount the card with different options
sudo umount ${SDDEVICE} 2>&1
sudo mount -t ext4 -o ${REMOUNTOPTIONS} ${SDDEVICE} ${SDMOUNT} 2>&1
if [[ ${DEBUG} -eq 1 ]]; then
echo "SD device is ${SDDEVICE}"
echo "SD mount is ${SDMOUNT}"
fi
# set readahead on SD card
sudo blockdev --setra 1024 ${SDDEVICE}
READAHEAD=`sudo blockdev --getra ${SDDEVICE}`
if [[ ${DEBUG} -eq 1 ]]; then
echo "Readahead for ${SDDEVICE} is now: ${READAHEAD}"
fi
fi
else
# there is no directory mount point at SDMOUNT; exit
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment