You are not logged in.
Here's a rudimentary bash script I've been using to mount '/dev/sd*' devices since that's all I need to mount 99% of the time. I don't intend to add or change anything (works for me~) but feel free to fork it and post your changes here.
* source: https://gist.github.com/ledti/7eed3cb4356e20540c80.
* uses and requires udisks2 by default.
* by default it visually excludes '/dev/sda' from the listing. This can easily be changed by editing the following in the source, for example if you have two internal drives:
# visually exclude the following /dev/sd* device(s) from the listing:
# syntax example: "abc", to exclude drives a,b, and c.
# use "-" to show everything.
exclude="ab"
---
$ sd
Available devices:
/dev/sdc
/dev/sdd
/dev/sdd1
$ sd --help
Commands:
-m: mount drive or partition.
-u: unmount drive or partition.
--help: show this help dialogue.
Example usage:
sd # list devices.
sd -m c # mount /dev/sdc.
sd -m d1 # mount /dev/sdd1.
sd -u d # unmount /dev/sdd.
$ sd -m c
Mounted /dev/sdc at /run/media/user/VIMERA.
$ sd -u b1
Unmounted /dev/sdb1.
Last edited by Ledti (2014-08-15 19:53:30)
Offline
Shouldn't you check at line 19 that you are not trying to mount something from the excludes list, rather than just hardcoding "i will work on anything but a"?
Offline
I'm using
usm ()
{
DRIVE="/dev/sdb1";
if mount | grep -q $DRIVE; then
sudo umount $DRIVE;
else
sudo mount -o user,rw,umask=000 $DRIVE /media/usb;
fi
}
but my needs are dead simple.
Offline
Thanks Karol - I modified that slightly for my own use. I had been using udevil, but as of a week or so ago it's not been properly unmounting devices and it leaves a dot-file in the mountpoint so they cannot be removed and just accumulate.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Shouldn't you check at line 19 that you are not trying to mount something from the excludes list, rather than just hardcoding "i will work on anything but a"?
The excludes list was meant to be more about visually excluding certain block devices from the listing rather than preventing you from mounting/unmounting them at all. The bit at line 19 was just meant to make sure the syntax was correct-ish, but at the time I made it into another manual check just because my needs were static. I didn't remember until last night that it was even there.
I changed the wording to reflect that and I'll edit the original post now.
Offline
Thanks Karol - I modified that slightly for my own use. I had been using udevil, but as of a week or so ago it's not been properly unmounting devices and it leaves a dot-file in the mountpoint so they cannot be removed and just accumulate.
Did you try running udevil clean ?
edit: I have some functions for udevil here, it runs sync/udevil clean maybe 60 times.
Last edited by Alad (2014-08-15 21:13:54)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
Alad, thanks for the suggestion - I had not. I never needed to do that before, but recently it started leaving those junk files after every mount/unmount. While `udevil clean` might clean up the current mess, it wasn't immediately obvious how to prevent it from continuuing to make new messes. I quite likely am just missing a new configuration setting that is needed, but just using the mount command is simpler for me know anyhow.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Instead of a exclude list, it might be more sensible to check for the `HintSystem` attribute if the intension is to exclude system devices.
EDIT:
I wrote this to mount/unmount all external disks -- if I wanted to do it to a certain disk, I'd just use udisksctl.
(removed)
EDIT:
v2 (superseded)
EDIT:
v3 -- add "is filesystem" check; allow specifying a list of devices to (un)mount.
#!/bin/bash
set -o pipefail
shopt -s extglob globasciiranges nullglob
disk_info() {
udisksctl info -b "$1" | awk '
{
if ($1 == "IdUsage:" && $2 != "filesystem")
exit 1
if ($1 == "HintSystem:" && $2 == "true")
printf("s")
else if ($1 == "MountPoints:" && NF > 1)
printf("m")
}
'
}
cmd=$1
shift || { printf 'error: no command given\n' >&2; exit 1; }
(( $# )) || set -- /dev/sd[a-z]+([0-9])
case $cmd in
m*)
for disk in "$@"; do
if ! info=$(disk_info "$disk"); then
printf 'warning: not a filesystem: %s\n' "$disk"
continue
fi
if [[ $info != *[sm]* ]]; then
udisksctl mount -b "$disk"
fi
done
;;
u*)
for disk in "$@"; do
if ! info=$(disk_info "$disk"); then
printf 'warning: not a filesystem: %s\n' "$disk"
continue
fi
if [[ $info != *s* && $info == *m* ]]; then
udisksctl unmount -b "$disk"
fi
done
;;
esac
Last edited by lolilolicon (2014-08-17 13:26:36)
This silver ladybug at line 28...
Offline