Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Simple script-command to mount partitions by label
Posted 08-15-2021 at 02:43 PM by the dsc
Largely based on this answer on askubuntu. I hope nothing atrocious results from some situation where it ends up trying to mount something a given user should not, or something. May require tweaking either the script or one's sudo permissions for the commands doing the hard work, I don't know how "default" my settings are.
So, if you have a bunch of partitions of a disk that are like hdbrand1, hdbrand2, hdbrandsmall, you'd issue the command as:
$ this-very-mount-by-label-script.sh hdbrand*
and it would mount all those partitions starting with "hdbrand." If you want to be more selective, you'd name just the one you want, without the asterisk. It should be kind of obvious from the script itself, probably if one knows more of all the wildcards and whatnot they can even do some smarter stuff I don't even imagine, all depending on how bash handles "${@}," which may not even be the best thing to have there for this purpose, but it seems to be doing the job for me.
By default, udisksctl mounts partitions along the lines of /media/user/label, or so it seems to me.
Code:
#!/bin/bash echo ${@} | while read input ; do for label in /dev/disk/by-label/${input} ; do label=$(basename "${label}") DEVICE=$(sudo /usr/sbin/findfs LABEL="${label}") && udisksctl mount -b "$DEVICE" done ; done
$ this-very-mount-by-label-script.sh hdbrand*
and it would mount all those partitions starting with "hdbrand." If you want to be more selective, you'd name just the one you want, without the asterisk. It should be kind of obvious from the script itself, probably if one knows more of all the wildcards and whatnot they can even do some smarter stuff I don't even imagine, all depending on how bash handles "${@}," which may not even be the best thing to have there for this purpose, but it seems to be doing the job for me.
By default, udisksctl mounts partitions along the lines of /media/user/label, or so it seems to me.
Total Comments 0