Automount USB drives January 02, 2014 04:12AM |
Registered: 11 years ago Posts: 162 |
Re: Automount USB drives January 02, 2014 06:05AM |
Admin Registered: 13 years ago Posts: 19,207 |
Re: Automount USB drives January 02, 2014 10:32AM |
Admin Registered: 13 years ago Posts: 19,207 |
Re: Automount USB drives January 02, 2014 06:32PM |
Registered: 11 years ago Posts: 162 |
Re: Automount USB drives January 02, 2014 06:50PM |
Registered: 11 years ago Posts: 162 |
Re: Automount USB drives January 03, 2014 12:44AM |
Registered: 11 years ago Posts: 93 |
Re: Automount USB drives January 03, 2014 01:07AM |
Registered: 11 years ago Posts: 162 |
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end" ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end" # Do not mount devices already mounted somewhere else to avoid entries for all your local partitions in /media ACTION=="add", PROGRAM=="/bin/grep -q ' /dev/%k ' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end" # Open LUKS partition if necessary PROGRAM=="/sbin/blkid -o value -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k" ENV{crypto}=="", ENV{device}="%N" ACTION=="add", ENV{crypto}!="", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /sbin/cryptsetup luksOpen %N %k'" ACTION=="add", ENV{crypto}!="", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end" # Global mount options ACTION=="add", ENV{mount_options}="noatime" # Filesystem-specific mount options ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002" ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="ntfs", ENV{mount_options}="%E{mount_options},utf8,big_writes,gid=100,umask=002" ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="ext4", ENV{mount_options}="%E{mount_options},data=writeback,barrier=0,nobh,errors=remount-ro" # Get label if present, otherwise assign one PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c" # Use basename to correctly handle labels such as ../mnt/foo PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c" ENV{dir_name}=="", ENV{dir_name}="hd-%k" # Mount the device ACTION=="add", ENV{dir_name}!="", RUN+="/bin/mkdir -p '/media/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '/media/%E{dir_name}'" # Clean up after removal ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'" ACTION=="remove", ENV{crypto}!="", RUN+="/sbin/cryptsetup luksClose %k" ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/rmdir '/media/%E{dir_name}'" # Exit LABEL="media_by_label_auto_mount_end"
Re: Automount USB drives January 03, 2014 01:53AM |
Admin Registered: 13 years ago Posts: 19,207 |
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="ntfs", ENV{mount_options}="%E{mount_options},utf8,big_writes,gid=100,umask=002"
Re: Automount USB drives January 03, 2014 01:56AM |
Registered: 11 years ago Posts: 162 |
Re: Automount USB drives January 03, 2014 02:00AM |
Admin Registered: 13 years ago Posts: 19,207 |
Re: Automount USB drives January 04, 2014 09:11PM |
Registered: 11 years ago Posts: 162 |
Re: Automount USB drives January 04, 2014 11:22PM |
Admin Registered: 13 years ago Posts: 19,207 |
root@Dockstar:~# cat /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. /root/block-storage.mount … exit 0
#!/bin/sh # Copyright © 2013 bodhi # # 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. # # block-storage.mount # # Mount all block devices to /media using its label. # # Assumption: - rootfs partition has label "rootfs" so it will be skipped # label_list=`ls -1 /dev/disk/by-label/` logger -s -i "Mounting all unmounted disks with label: $label_list (skip rootfs)" for disk_label in $label_list; do if [ $disk_label != "rootfs" ]; then if ! /bin/mountpoint /media/$disk_label -q ; then if [ ! -d /media/$disk_label ]; then mkdir /media/$disk_label fi FSTYPE=`udevadm info --query=property --name=/dev/disk/by-label/$disk_label | grep ID_FS_TYPE | cut -c 12-` if [ $FSTYPE = "ntfs" ]; then mount -L $disk_label -o noatime,big_writes /media/$disk_label logger -s -i Mounted $disk_label else mount -L $disk_label -o noatime /media/$disk_label logger -s -i Mounted $disk_label fi fi fi done logger -s -i "Done mounting disks with label" exit 0
Re: Automount USB drives January 04, 2014 11:39PM |
Registered: 11 years ago Posts: 162 |
Re: Automount USB drives January 05, 2014 01:07AM |
Admin Registered: 13 years ago Posts: 19,207 |
Re: Automount USB drives January 05, 2014 03:13AM |
Admin Registered: 13 years ago Posts: 19,207 |
Re: Automount USB drives January 19, 2014 11:53AM |
Registered: 14 years ago Posts: 161 |
#!/bin/bash # remove any stale pmount locations PMOUNT=".created_by_pmount" ROOT="/media" OLDIFS="$IFS" IFS=$'\n' for DIR in $( ls -d1 $ROOT/* ) do # a stale pmount location has exactly two entries # /media/foo # /media/foo/.created_by_pmount TEST=( `find "$DIR"` ) if [ ${#TEST[@]} = 2 ] && [ "${TEST[0]}" = "$DIR" ] && [ "${TEST[1]}" = "$DIR/$PMOUNT" ]; then # remove in the safest possible way # instead of using rm -fR $DIR echo "Removing stale pmount: $DIR" rm "${TEST[1]}" rmdir "${TEST[0]}" fi done # find pmount binary PMOUNT=`which pmount` if [ -z "$PMOUNT" ] then echo "Error: cant find pmount: $0" IFS="$OLDIFS" exit 1 fi pmount() { local IFS="$OLDIFS" echo "Attempting to pmount: $DEV" BLKID=( `/sbin/blkid "$ROOT/$DEV"` ) echo "${BLKID[@]}" for ITEM in ${BLKID[@]} do #echo "$ITEM" TEST=`expr match "$ITEM" 'TYPE=\"\(.*\)\"'` TYPE=${TEST//\"/} # only pmount partitions with a valid file system # which is not swap if [ -n "$TYPE" ] && [ "$TYPE" != "swap" ] then echo `$PMOUNT -t $TYPE $OPTIONS "$ROOT/$DEV" "$DEV"` break fi done } # pmount any usb storage devices attached at boot OPTIONS="--sync --noatime --umask 000" ROOT="/dev/usb-storage" for DEV in $( ls -1 $ROOT ) do pmount done IFS="$OLDIFS" exit 0
Re: Automount USB drives January 20, 2014 12:31PM |
Admin Registered: 13 years ago Posts: 19,207 |
Re: Automount USB drives January 20, 2014 02:55PM |
Registered: 14 years ago Posts: 161 |
Re: Automount USB drives January 20, 2014 11:31PM |
Admin Registered: 13 years ago Posts: 19,207 |