Symlinks to Removable Media

If it doesn't relate to Debian, but you still want to share it, please do it here
Message
Author
KitchM
Posts: 124
Joined: 2019-06-11 18:11

Symlinks to Removable Media

#1 Post by KitchM »

What is the preferred method for creating a symlink to a removable USB drive?

peter_irich
Posts: 1327
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Re: Symlinks to Removable Media

#2 Post by peter_irich »

Through udev rule. Udev-rule must be placed in /etc/udev/rules.d.

Peter.

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#3 Post by KitchM »

What would be the appropriate format? How does one identify a removable device to be recognized by next insertion? Does one use device or partition name?
Last edited by KitchM on 2020-05-22 15:15, edited 1 time in total.

arzgi
Posts: 792
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 1 time

Re: Symlinks to Removable Media

#4 Post by arzgi »

KitchM wrote:What would be the appropriate format? How does one identify a removable device to be recognized by next insertion? Does on use device or partition name?
http://reactivated.net/writing_udev_rules.html

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#5 Post by KitchM »

Thank you for that link. I will read it and see if I can figure out how to make it apply in my particular situation.

Dai_trying
Posts: 960
Joined: 2016-01-07 12:25

Re: Symlinks to Removable Media

#6 Post by Dai_trying »

I found

Code: Select all

udevadm monitor
really useful when writing udev rules.

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#7 Post by KitchM »

Thanks. I'll give that a look. Maybe I can figure out how it will help me.

cuckooflew
Posts: 681
Joined: 2018-05-10 19:34
Location: Some where out west

Re: Symlinks to Removable Media

#8 Post by cuckooflew »

KitchM wrote:Thank you for that link. I will read it and see if I can figure out how to make it apply in my particular situation.
Probably if you gave better details and explained exactly what your particular situation is, you might get more specific instruction,... :D
by KitchM » 2020-05-22 20:04
Thanks. I'll give that a look. Maybe I can figure out how it will help me.
The document that is linked to seems pretty detailed, and straight forward, I see where it answers this:
How does one identify a removable device to be recognized by next insertion?
Have you gotten that far ? Can you now identify the device ?
My question is why you feel you need to make symlinks to removable media, and use udev , I have never needed it myself, in my particular situation,..which does include making bootable usb drives, and storage drives, also usb devices such as printers, optical drives, maybe if I understood why you need to use udev and what the "usb drive" is , eg : a bootable drive, perhaps with a "live" Debian, etc...
Does one use device or partition name?
Err, I do not understand, you would need to use the device, but if a particular partition on a certain device was what you want to make a symlink to , I think you would need to include that,.. this is something that would be easier to answer clearly if we knew more about what exactly you are doing or want to accomplish.
In my situation, I need to use the device name, and include the specific partition I want to mount, but I do not need or use "udev" or any symlinks to do this. But if I did need to create symlinks, I would say. the best way to do this is with the 'ln ' terminal command , and now we seethe problem with asking "what is the prefered method, to do something", you may get various opinions on what the best way is, just because "udev" was the first response, does not mean others prefer or use it. It would be better if you just decide, what method you want to use, and then ask for detailed instruction, if you need it. I am not going to go any further with using the 'ln' command, since you all ready have started asking for details on udev. I guess for now that is all. Ahh, there is plenty of tutorials, on both "udev" and the "ln" command
methods, there also are a few graphical file managers that can create symbolic links too, something I did not know until just now.
Please Read What we expect you have already Done
Search Engines know a lot, and
"If God had wanted computers to work all the time, He wouldn't have invented RESET buttons"
and
Just say NO to help vampires!

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#9 Post by KitchM »

Much thanks for the info; all good.

I will say that the way we all think is different and assumptions get in the way. For instance, I read thru the document and found it has a lot of good detail, but it leaves out a lot as well. In point of fact, I have written the author with three messages full of tweaks which need to be made.

Here are a couple. First, there appears to be a difference in the way different media is handled. In other words, one size does not fit all. The examples are fairly good, but fail to give details about USB flash drives; the very thing I wanted to focus upon, and quite ubiquitis today.. Second, there is little information about how to identify an inserted device so as to apply that “label” to the ln command.

I am wanting the information so as to add to my general knowledge of Linux. As such, learning all the basic stuff is necessary.

However, I do have an ulterior motive. I have need of getting a USB flash drive to be recognized by TailsOS while it is running from another USB port. As you know, Tails is based upon Debian; the same Debian I use on my daily and test systems.

In particular, I want to use the Wasabi Wallet with Tails. It installs in, or is extracted to, WasabiLinux-1.1.11.1. It will run from that directory wherever it is found. But upon first run, it creates .walletwasabi in the home directory.

While this all sounds well and good, when Tails is shut down, everything is wiped clean. This is good since one does not want to leave personal information around when desiring to remain anonymous. The user can simply throw the OS drive away if desired.

Tails offers a way to create a hidden and encrypted folder they call a Persistent Storage. However, to access it, one must stop and enter a password every time. Then one must navigate to the program’s directory to run it. Just that bit is a PITA and unacceptable time-wise.

That leaves a separate USB disk. And so the need for a simply symlink to get the two directories recognized and start the program, if the disk is inserted. (Encryption is a side issue. The same ability to throw it away is needed, as well as taking the drive to another computer.)


I’ll bet you didn’t expect you’d be stepping into this mess when you asked, did you? :lol:

User avatar
Head_on_a_Stick
Posts: 13450
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Symlinks to Removable Media

#10 Post by Head_on_a_Stick »

KitchM wrote:how to identify an inserted device so as to apply that “label” to the ln command
Dai_trying already told you how to do that. I thought you read all of the replies in your threads?

EDIT: and Tails isn't supported here.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#11 Post by KitchM »

No, actually he didn't.

Also, this has nothing to do with Tails, as I clearly implied. And since Tails is based upon Debian, any solution should work just fine. That is, unless you know of any specific reason why it would not. Do you?

User avatar
Head_on_a_Stick
Posts: 13450
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Symlinks to Removable Media

#12 Post by Head_on_a_Stick »

KitchM wrote:No, actually he didn't.
Yes, they did. The command they posted is the best way to find out how to identify devices for use in udev rules.

And why do you assume that Dai_trying identifies as male?
KitchM wrote:Also, this has nothing to do with Tails, as I clearly implied.
Not sure about "clearly", your posts are too prolix. Please endeavour to be more concise, it will help you get better replies.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support

cuckooflew
Posts: 681
Joined: 2018-05-10 19:34
Location: Some where out west

Re: Symlinks to Removable Media

#13 Post by cuckooflew »

Dai_trying wrote:I found

Code: Select all

udevadm monitor
really useful when writing udev rules.
I decided to do some searches on this, since I don't really know much, as mentioned earlier, found several links that seem to be educational, :
https://www.tecmint.com/udev-for-device ... -in-linux/
To find the name assigned to your USB disk, use the lsblk utility which reads the sysfs filesystem and udev db to gather information about processed devices.
But the above also gives some details about udevadm monitor as well.
===================
https://sites.google.com/site/itmyshare ... e-examples
============================================================
https://linux.die.net/man/8/udevadm
======================
This below also , mentions all of the above methods :
https://unix.stackexchange.com/question ... mmand-line
======
Summary
Second, there is little information about how to identify an inserted device so as to apply that “label” to the ln command.

I am wanting the information so as to add to my general knowledge of Linux. As such, learning all the basic stuff is necessary.
The four links posted will definitely help add to your general knowledge, and should keep you busy for a while.
My suggestion is to try the various commands and options, then decide what is the best way for your particular situation, (Did I all ready say that ?, I think I did, sorry)
However, I do have an ulterior motive. I have need of getting a USB flash drive to be recognized by TailsOS while it is running from another USB port. As you know, Tails is based upon Debian; the same Debian I use on my daily and test systems.
Really don't know here, I have never used Tails, so no I did not know it is based on Debian, it does seem like the same commands could be applied, but maybe not, however the commands are standard Linux commands and tools, so go figure, suppose you just need to try them.
Please Read What we expect you have already Done
Search Engines know a lot, and
"If God had wanted computers to work all the time, He wouldn't have invented RESET buttons"
and
Just say NO to help vampires!

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#14 Post by KitchM »

@ Head_on_a_Stick,
Yes, they did. The command they posted is the best way to find out how to identify devices for use in udev rules.
It would have been nice if the individual had stated what it is, what it does, how to use it and what to expect as output. So the suggestion remains incomplete.

Here’s what I got in my terminal:

~$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

and then nothing.

And no way to get out of it either.
And why do you assume that Dai_trying identifies as male?
No assumption made or intended. It is the default of the English language for literally hundreds of years.
Not sure about "clearly", your posts are too prolix. Please endeavour to be more concise, it will help you get better replies.
That’s humorous. First, I’m not being clear enough, then I’m being too wordy.

Why did you think that your objections had anything to do with the basis of this thread?

@cuckooflew,
Thanks, as always. Very interesting stuff. (I didn’t know about the Hotplug relationship.)

You found some good ones; sometimes it just takes the right phraseology in the search.

You are quite correct; should take me a while to digest all that. Looking forward to it. Thanks again.

User avatar
Head_on_a_Stick
Posts: 13450
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Symlinks to Removable Media

#15 Post by Head_on_a_Stick »

KitchM wrote:It would have been nice if the individual had stated what it is, what it does, how to use it and what to expect as output
That's what man pages are for...
KitchM wrote:Here’s what I got in my terminal:

Code: Select all

~$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
and then nothing.
Hint: plug a device in ;)

And please use code tags when posting terminal output, as I have done above. It greatly aids readability, especially for longer listings.
KitchM wrote:And no way to get out of it either.
<ctrl>-c exits most things in a terminal.
KitchM wrote:
And why do you assume that Dai_trying identifies as male?
No assumption made or intended. It is the default of the English language for literally hundreds of years.
How very woke of you :roll:
KitchM wrote:First, I’m not being clear enough, then I’m being too wordy.
Yes indeed, balance is the key. Thank you for understanding.
KitchM wrote:Why did you think that your objections had anything to do with the basis of this thread?
Why do you think I care?
Black Lives Matter

Debian buster-backports ISO image: for new hardware support

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#16 Post by KitchM »

Head_on_a_Stick, Please PM me if you have further comments on my post.

Dai_trying
Posts: 960
Joined: 2016-01-07 12:25

Re: Symlinks to Removable Media

#17 Post by Dai_trying »

KitchM wrote:It would have been nice if the individual had stated what it is, what it does, how to use it and what to expect as output. So the suggestion remains incomplete.
does this help?
the man page wrote:udevadm monitor [options]
Listens to the kernel uevents and events sent out by a udev rule and prints the devpath of the event to the console. It can be
used to analyze the event timing, by comparing the timestamps of the kernel uevent and the udev event.

-k, --kernel
Print the kernel uevents.

-u, --udev
Print the udev event after the rule processing.

-p, --property
Also print the properties of the event.

-s, --subsystem-match=string[/string]
Filter kernel uevents and udev events by subsystem[/devtype]. Only events with a matching subsystem value will pass. When
this option is specified more than once, then each matching result is ORed, that is, all devices in the specified subsystems
are monitored.

-t, --tag-match=string
Filter udev events by tag. Only udev events with a given tag attached will pass. When this option is specified more than
once, then each matching result is ORed, that is, devices which have one of the specified tags are monitored.

-h, --help
Print a short help text and exit.
Hint:

Code: Select all

 man udevadm

KitchM
Posts: 124
Joined: 2019-06-11 18:11

Re: Symlinks to Removable Media

#18 Post by KitchM »

As you should know, man pages are almost useless to the newbie. As such, they leave a lot of questions unanswered. In this case, here are some:
What is a uevent?
What sort of format should I expect to see?
How do I know if it is working correctly?
How do I get out of it, since this one, unlike most commands, does not return to the prompt on its own.
How does this help a person wishing to create a symlink?

Do not think that your efforts are not appreciated, because they are (regardless of any indication to the contrary by anyone). I raised no criticism of your efforts.

Thank you for your help and contributions.

Dai_trying
Posts: 960
Joined: 2016-01-07 12:25

Re: Symlinks to Removable Media

#19 Post by Dai_trying »

Your questions have mostly been answered in the previous posts by HOAS and cuckooflew, but one reason I have used udev rules is to get particular devices (either USB or SD Card) recognised and then back up the contents to a preferred location automatically, but you could also do what you want which in your case would be to create a symlink (and remove it on release I presume?) you can find more information in the Debian Wiki for writing them, HTH.
https://wiki.debian.org/udev

cuckooflew
Posts: 681
Joined: 2018-05-10 19:34
Location: Some where out west

Re: Symlinks to Removable Media

#20 Post by cuckooflew »

As you should know, man pages are almost useless to the newbie
Offtopic, but I strongly disagree, first off, they show all the options, and what the options do, a newbie probably does not know , and it can save you a lot of grief to check the manual pages when some one shows some code, make sure the options they have in the code are really what you want to do. It is very foolish to blindly copy/paste code into a terminal if you do not fully understand what the options/switches mean and do. Please try to find the answers, after you have tried and if you don't find a answer, then ask,
EG: What is a uevent?
Also: 'man uevent' =
DESCRIPTION top

udev supplies the system software with device events, manages
permissions of device nodes and may create additional symlinks in the
/dev directory, or renames network interfaces. The kernel usually
just assigns unpredictable device names based on the order of
discovery. Meaningful symlinks or network device names provide a way
to reliably identify devices based on their properties or current
configuration.

The udev daemon, systemd-udevd.service(8), receives device uevents
directly from the kernel whenever a device is added or removed from
the system, or it changes its state. When udev receives a device
event, it matches its configured set of rules against various device
attributes to identify the device. Rules that match may provide
additional device information to be stored in the udev database or to
be used to create meaningful symlink names.

All device information udev processes is stored in the udev database
and sent out to possible event subscribers. Access to all stored data
and the event sources is provided by the library libudev
And if you do not have the manual in your system: https://www.man7.org/linux/man-pages/man7/udev.7.html=====edited=======
Apology for the confusion, I posted the wrong link, but both are related, this is what I meant to post:
https://www.man7.org/linux/man-pages/ma ... adm.8.html
===============end edit=====
The next question :
What sort of format should I expect to see?
Is not clear, do you mean for uevent or udev ? or what, ?
Be specific with your questions, I took a guess, that you mean for uevent:
Logic for the key words:

Code: Select all

uevent examples and format 
https://www.kernel.org/doc/html/latest/ ... event.html
An example of the uevents generated as captured by udevmonitor is shown below

1.) Path failure:

Code: Select all

UEVENT[1192521009.711215] change@/block/dm-3
ACTION=change
DEVPATH=/block/dm-3
SUBSYSTEM=block
DM_TARGET=multipath
DM_ACTION=PATH_FAILED
DM_SEQNUM=1
DM_PATH=8:32
DM_NR_VALID_PATHS=0
DM_NAME=mpath2
DM_UUID=mpath-35333333000002328
MINOR=3
MAJOR=253
SEQNUM=1130 
----snip--
No, I am not going to copy/paste all of the examples here.
Last edited by cuckooflew on 2020-05-30 16:03, edited 2 times in total.
Please Read What we expect you have already Done
Search Engines know a lot, and
"If God had wanted computers to work all the time, He wouldn't have invented RESET buttons"
and
Just say NO to help vampires!

Post Reply