Howto make permanent USB mount points with "udev"

How to do things, solutions, recipes, tutorials
Message
Author
User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#21 Post by rufwoof »

The device naming lottery can be a pain when some hard code device names into scripts and the kernel decides that after another reboot to swap those names all around. Personally I tend to manually mount things

mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb

where usually I use fdisk -l to quickly review devices

In some cases I do script based mounting and when so I tend to include a identity file on devices, where the script loops through mounting things and looking for a particular unique filename that I've pre-created on that device, and when found it creates a /mnt/xxx folder and mounts the device to that mount point.

Other approaches are to use UUID, or device label (disk label), or device name. For instance in gparted there's a option to set a partitions label and once you've done that, such as setting a usb with a single partition to have a label of 'whiteusb' (perhaps for a white coloured usb stick), then you can mount that using

mkdir /mnt/whiteusb
mount -L whiteusb /mnt/whiteusb

If you use that consistently, then your scripts can reference that reliably

cd /mnt/whiteusb
.... etc.

Mount points don't have to be under the /mnt folder. You could for instance mount it to a folder within /root

mkdir /root/whiteusb
mount -L whiteusb /root/whiteusb

To umount when done ... umount /root/whiteusb

Labels are nice in that they remain consistent, under certain conditions for instance UUID's can change.

/etc/fstab is the list of devices that get mounted at bootup. For mounting using labels the format is something like

LABEL=whiteusb /mnt/whiteusb ext3 defaults 0 0
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#22 Post by jafadmin »

UPDATE NOTE

Older versions of udev are more problematic when implementing the unplug event. The 'MkRule' wizard
doesn't produce a 'remove' rule that works.

It is necessary to run the command: 'udevadm monitor --environment --udev | grep PRODUCT' with the usb
device plugged in, then removing the device and looking for the "PRODUCT=xxx/xxxx/x' line, then use that
information to change the 'remove' rule.

Change the 'ENV{ID_SERIAL_SHORT}==?????????' to read: 'ENV{PRODUCT}==xxx/xxxx/x' as revealed by the
command you ran.

Unfortunately, this environment variable can only be revealed by running the udev monitor in realtime which
makes it difficult to script .

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#23 Post by jafadmin »

.

User avatar
gychang
Posts: 414
Joined: Sat 29 Nov 2008, 20:30
Location: San Diego, CA

Re: Howto make permanent USB mount points with "udev"

#24 Post by gychang »

jafadmin wrote:
It assumes you have a /root/bin directory. if you don't, create one. Put the "mkrule" and "mnt-MyUSB" files in that directory. Put the "trigger-udev" file in /root/Startup. Make sure they are all executable.

Now just plug in the USB disk you want to use for this, then open a console in /root/bin and type: "./mkrule /dev/sdX" (where X is your usb device). This will create the udev rule and put it where it needs to go.

At this point all partitions on your USB disk should be mounted at: /MyUSB

From now on, that, and only that USB disk, will always mount as /MyUSB/MyUSB-1, /MyUSB/MyUSB-2, etc ..

Drag a link to /MyUSB to your desktop.

Prosper.

That is all.
I am trying to follow this since my BionicPup64 v8.0 is not recognizing my internal SD card reader. I am unclear how to get/create "mnt-MyUSB" file to place in bin directory... Does it automatically get created after reboot?
---
trying to learn puppylinux... :D
---

User avatar
gychang
Posts: 414
Joined: Sat 29 Nov 2008, 20:30
Location: San Diego, CA

Re: Howto make permanent USB mount points with "udev"

#25 Post by gychang »

jafadmin wrote: It assumes you have a /root/bin directory. if you don't, create one. Put the "mkrule" and "mnt-MyUSB" files in that directory. Put the "trigger-udev" file in /root/Startup. Make sure they are all executable.

Now just plug in the USB disk you want to use for this, then open a console in /root/bin and type: "./mkrule /dev/sdX" (where X is your usb device). This will create the udev rule and put it where it needs to go.

At this point all partitions on your USB disk should be mounted at: /MyUSB

From now on, that, and only that USB disk, will always mount as /MyUSB/MyUSB-1, /MyUSB/MyUSB-2, etc ..

Drag a link to /MyUSB to your desktop.

Prosper.

That is all.
I am trying to follow this to get my internal SD card working in BionicPup64, v8.0. Recognizes and works fine on XenialPup64. When I boot with SD card in BP64, I see it /dev/sdf. But does not work properly when removed and reinserted. Anyway I am confused how the "mnt-MyUSB" file in root/bin directory is created, since I don't see it as the part of downloaded zip file.
---
trying to learn puppylinux... :D
---

User avatar
gychang
Posts: 414
Joined: Sat 29 Nov 2008, 20:30
Location: San Diego, CA

Re: Howto make permanent USB mount points with "udev"

#26 Post by gychang »

sorry, please delete this.
---
trying to learn puppylinux... :D
---

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#27 Post by jafadmin »

@gychang

Greg, go to the SECOND post in this thread, download the wizard, and follow the instructions in the README file on how to install the wizard. That should work better for you.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#28 Post by greengeek »

rufwoof wrote:Labels are nice in that they remain consistent, under certain conditions for instance UUID's can change.
Hi Rufwoof - obviously if a partition is manually reformatted the UUID will change - but are there other circumstances beyond the user's control where UUID may change without user's knowledge or intervention?

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

Doesn't work with CnMemory Spaceloop 64GB USB Stick

#29 Post by 3guesses »

For some reason, this doesn't work with my CnMemory Spaceloop 64GB USB memory stick (it works fine with a Kingston Datatraveller 8GB USB memory stick and a WD MyPassport X 2TB USB HDD). So I ran "man rules.d" from within Puppy, which led me to https://linux.die.net/man/8/udev. However, the .rules files created by this wizard do not seem to correspond to the documentation I found, so does Puppy use a proprietary version of udev and where is the documentation for it?

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

Re: Doesn't work with CnMemory Spaceloop 64GB USB Stick

#30 Post by jafadmin »

3guesses wrote:For some reason, this doesn't work with my CnMemory Spaceloop 64GB USB memory stick (it works fine with a Kingston Datatraveller 8GB USB memory stick and a WD MyPassport X 2TB USB HDD). So I ran "man rules.d" from within Puppy, which led me to https://linux.die.net/man/8/udev. However, the .rules files created by this wizard do not seem to correspond to the documentation I found, so does Puppy use a proprietary version of udev and where is the documentation for it?
Post the rules file ( /etc/udev/rules.d/70-'YourDevice'.rules ) it created and the version of puppy involved. We'll see what happened. :?

udev is a standard unix/linux system utility.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#31 Post by jafadmin »

UPDATE:
Please replace the line in the "unplug-template" & "unplug-YourDevice" files in your /root/udev directory that says:

Code: Select all

MountDir=$(echo $MyName | cut -d'-' -f2)
with:

Code: Select all

MountDir=$(echo "$MyName" | cut -c 8-)
It will work better with device names that have hyphens in them. :o

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

Re: Doesn't work with CnMemory Spaceloop 64GB USB Stick

#32 Post by 3guesses »

jafadmin wrote:
3guesses wrote:For some reason, this doesn't work with my CnMemory Spaceloop 64GB USB memory stick (it works fine with a Kingston Datatraveller 8GB USB memory stick and a WD MyPassport X 2TB USB HDD). So I ran "man rules.d" from within Puppy, which led me to https://linux.die.net/man/8/udev. However, the .rules files created by this wizard do not seem to correspond to the documentation I found, so does Puppy use a proprietary version of udev and where is the documentation for it?
Post the rules file ( /etc/udev/rules.d/70-'YourDevice'.rules ) it created and the version of puppy involved. We'll see what happened. :?

udev is a standard unix/linux system utility.
OK, here are the rules files created for my Kingston DataTraveller (KDT) and CnMemory (CnM) memory sticks, and the output from "udevadm info -a /dev/sdc1" for each.

The rules files simply don't have lines like the examples given in the documentation (eg. BUS="scsi", SYSFS{vendor}="IBM", SYSFS{model}="ST336", etc).
Attachments
udevfiles.zip
Rules and output from "udevadm info" for Kingston DataTraveller, CnMemory
(4.04 KiB) Downloaded 122 times

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#33 Post by jafadmin »

Yeah, the output from the "info" command has a bagillion times more data than matters. Kinda like running 'dmesg' ..

Anyways, try this and see what happens. First, back up, then edit the 'rules' file first line to read:

Code: Select all

SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This is a USB3 device and might need some shoehorning .. :roll:

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

#34 Post by 3guesses »

Also, is it possible for the udev rules to match by UUID?

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

#35 Post by 3guesses »

jafadmin wrote:Yeah, the output from the "info" command has a bagillion times more data than matters. Kinda like running 'dmesg' ..

Anyways, try this and see what happens. First, back up, then edit the 'rules' file first line to read:

Code: Select all

SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This is a USB3 device and might need some shoehorning .. :roll:
No, it's a USB 2.0 device, but I might have connected it to a USB 3 port rather than a USB 2 port. I think I have the same problem in a USB 2 port.

This also doesn't answer why the rules file does not match the documentation.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#36 Post by jafadmin »

3guesses wrote:Also, is it possible for the udev rules to match by UUID?
Udev doesn't do that simply for the reason that when you wipe the device by creating a new partition table, the UUID changes. In fact, you can use GPartEd to directly change the UUID of a device.

The whole point of udev is to wrangle the base hardware layer.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#37 Post by jafadmin »

3guesses wrote:
jafadmin wrote:Yeah, the output from the "info" command has a bagillion times more data than matters. Kinda like running 'dmesg' ..

Anyways, try this and see what happens. First, back up, then edit the 'rules' file first line to read:

Code: Select all

SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This is a USB3 device and might need some shoehorning .. :roll:
No, it's a USB 2.0 device, but I might have connected it to a USB 3 port rather than a USB 2 port. I think I have the same problem in a USB 2 port.

This also doesn't answer why the rules file does not match the documentation.
Consider that the documentation doesn't match udev ..
Udev thinks it's a usb 3 device ..
.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#38 Post by jafadmin »

At the end of the day, I strongly doubt there is a problem with 'udev'. It has been around as long as PnP.

If there is any weirdness, we should probably look at your hardware.

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

#39 Post by 3guesses »

jafadmin wrote:
3guesses wrote:Also, is it possible for the udev rules to match by UUID?
Udev doesn't do that simply for the reason that when you wipe the device by creating a new partition table, the UUID changes. In fact, you can use GPartEd to directly change the UUID of a device.

The whole point of udev is to wrangle the base hardware layer.
OK, so if I want to automatically mount my USB partitions by UUID, how would I do that?

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

#40 Post by 3guesses »

jafadmin wrote:
3guesses wrote:
jafadmin wrote:Yeah, the output from the "info" command has a bagillion times more data than matters. Kinda like running 'dmesg' ..

Anyways, try this and see what happens. First, back up, then edit the 'rules' file first line to read:

Code: Select all

SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This is a USB3 device and might need some shoehorning .. :roll:
No, it's a USB 2.0 device, but I might have connected it to a USB 3 port rather than a USB 2 port. I think I have the same problem in a USB 2 port.

This also doesn't answer why the rules file does not match the documentation.
Consider that the documentation doesn't match udev ..
Udev thinks it's a usb 3 device ..
.
OK, well I've connected it to the USB 2 port and exactly the same problem.

So where do I find the correct documentation for udev?

EDIT: it would also appear that udev thinks my Kingston DT is USB 3 too, so I don't see how that is the cause of the problem.

Post Reply