LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


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.
Rate this Entry

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.

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
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.
Posted in Uncategorized
Views 628 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:28 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration