Howto make permanent USB mount points with "udev"
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
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]
[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]
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 .
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 .
Re: Howto make permanent USB mount points with "udev"
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?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.
---
trying to learn puppylinux... :D
---
trying to learn puppylinux... :D
---
Re: Howto make permanent USB mount points with "udev"
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.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.
---
trying to learn puppylinux... :D
---
trying to learn puppylinux... :D
---
Re: Howto make permanent USB mount points with "udev"
sorry, please delete this.
---
trying to learn puppylinux... :D
---
trying to learn puppylinux... :D
---
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?rufwoof wrote:Labels are nice in that they remain consistent, under certain conditions for instance UUID's can change.
Doesn't work with CnMemory Spaceloop 64GB USB Stick
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?
Re: Doesn't work with CnMemory Spaceloop 64GB USB Stick
Post the rules file ( /etc/udev/rules.d/70-'YourDevice'.rules ) it created and the version of puppy involved. We'll see what happened.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?
udev is a standard unix/linux system utility.
UPDATE:
Please replace the line in the "unplug-template" & "unplug-YourDevice" files in your /root/udev directory that says:
with:
It will work better with device names that have hyphens in them.
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)
Code: Select all
MountDir=$(echo "$MyName" | cut -c 8-)
Re: Doesn't work with CnMemory Spaceloop 64GB USB Stick
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.jafadmin wrote:Post the rules file ( /etc/udev/rules.d/70-'YourDevice'.rules ) it created and the version of puppy involved. We'll see what happened.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?
udev is a standard unix/linux system utility.
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 125 times
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:
This is a USB3 device and might need some shoehorning ..
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"
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.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:This is a USB3 device and might need some shoehorning ..Code: Select all
SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This also doesn't answer why the rules file does not match the documentation.
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.3guesses wrote:Also, is it possible for the udev rules to match by UUID?
The whole point of udev is to wrangle the base hardware layer.
Consider that the documentation doesn't match udev ..3guesses wrote: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.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:This is a USB3 device and might need some shoehorning ..Code: Select all
SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This also doesn't answer why the rules file does not match the documentation.
Udev thinks it's a usb 3 device ..
.
OK, so if I want to automatically mount my USB partitions by UUID, how would I do that?jafadmin wrote: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.3guesses wrote:Also, is it possible for the udev rules to match by UUID?
The whole point of udev is to wrangle the base hardware layer.
OK, well I've connected it to the USB 2 port and exactly the same problem.jafadmin wrote:Consider that the documentation doesn't match udev ..3guesses wrote: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.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:This is a USB3 device and might need some shoehorning ..Code: Select all
SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{serial}=="12061907001113", SYMLINK+="CnM-%n", RUN+="/root/udev/mnt-CnM"
This also doesn't answer why the rules file does not match the documentation.
Udev thinks it's a usb 3 device ..
.
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.