Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 18 Feb 2018, 14:04
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Howto make permanent USB mount points with "udev"
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
jafadmin

Joined: 19 Mar 2009
Posts: 715

PostPosted: Thu 18 Jan 2018, 13:12    Post subject:  Howto make permanent USB mount points with "udev"
Subject description: Hotplugging, suspending, power loss, accidental disconnects, and reboots handled gracefully
 

Depending on what USB storage devices you have plugged in and in what order, the kernel is going to automatically assign a /dev/sd? descriptor to it. It may very well not always wind up with the same descriptor.

If we want to run cron jobs or scripts to backup or sync data, we need to have reliable, permanent device descriptors so our scripts don't break. What to do?

Udev, that's what. This is the tool sysadmins in datacenters use on the "bigiron". It guarantees that no matter what, your USB drive will always have a unique, permanent device descriptor. This will persist through hibernation or sleep modes. It will survive accidental unplugging or power loss.

And you can use it with puppy. It was tested on Precise 5.7.1 ram mode. Everything you need is in the "udev-mount.tar.gz" archive.

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.
udev-mount.tar.gz
Description 
gz

 Download 
Filename  udev-mount.tar.gz 
Filesize  1.66 KB 
Downloaded  24 Time(s) 

Last edited by jafadmin on Fri 19 Jan 2018, 16:23; edited 6 times in total
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 715

PostPosted: Thu 18 Jan 2018, 14:01    Post subject:  

What it does:

When a USB device is plugged into linux, the kernel looks to see if there is something on the system that has instructions on what to do with it. If there are no instructions, it just performs some default action.

So how do I instruct the kernel what to do with MY device? We make a rule that is associated with that device using udev/udevadm and put it in /etc/udev/rules.d/. Now every time my USB disk is hot plugged, the kernel will use that rule to see what I want done with it.

Our rule, "70-MyUSB.rules", tells the kernel to create custom device descriptors for all the partitions on my USB disk when plugged and put them in /dev. Next it tells the kernel to execute our script, "mnt-MyUSB", which handles the directories, mount points, and mounting everything.

The "trigger-udev" script in /root/Startup makes sure the device gets mounted properly if it was already plugged in at boot time, since it won't trigger a unique PnP event to process unless unplugged and re-plugged.

After a hibernate or sleep session, if the device triggers a PnP event, it just resets to normal.

Exceptions:

When using USB cradles, just remember that udev only sees the cradle metrics, not the disk metrics. This means the same rule will always be triggered regardless of which disk is in the cradle. This is actually a good thing if you are using the cradle to do daily backups to different disks.


[ A Cool Update .. ]
Below is an improvement in the form of a wizard. It is for folks that are juggling several USB disks and want each to mount by a "friendly" name. This one also processes the "unplug" event and performs cleanup in the newer puppies. (Older versions of udev don't generate "remove" 'ENV' events.)

In this implementation you put the wizard files in "/root/udev" which you will need to create.

Now just open a console in /root/udev and run: "./mkrule /dev/sd? FriendlyName"
where "sd?" is the device descriptor and "FriendlyName" is frequently the model name, i.e.: "WD-Mybook"

That's all you do. Now you can run it for each USB disk and you will have mountpoints for them in "/", i.e.: /WD-Mybook, etc ..
udev-wizard.tar.gz
Description 
gz

 Download 
Filename  udev-wizard.tar.gz 
Filesize  1.79 KB 
Downloaded  17 Time(s) 
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 4822
Location: Republic of Novo Zelande

PostPosted: Tue 13 Feb 2018, 04:55    Post subject:  

This sounds awesome. Do you have any idea if it should work with Slacko 5.6 and/or 5.7? (I would rather not fiddle yet if you think the utilities are only Precise compatible)

cheers!
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 715

PostPosted: Tue 13 Feb 2018, 16:16    Post subject:  

@greengeek

They should actually run on any Puppy that has udevadm installed, which I think is all since at least 3.12. Use the wizard version.

udev/udevadm are a standard part of linux ..

.

Last edited by jafadmin on Wed 14 Feb 2018, 08:53; edited 2 times in total
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 715

PostPosted: Tue 13 Feb 2018, 16:23    Post subject:  

PRO TIP:

If you have several USB drives of the same make/model that you use for backups, for instance, and you want them to all mount to the same mountpoint when connected (suppose you have a scheduled backup script, but want to change the USB disk every day), just open the /etc/udev/rules.d/ "71.ModelName.rules" file and delete the field for the serial number along with the comma, of course.

This one:
Code:
-> ATTRS{serial}=="4Z530722230610118279",<-


Then from a console type: "udevadm control --reload". From then on, it will mount any matching make/model, regardless of serial number, to your fixed mountpoint.

Last edited by jafadmin on Wed 14 Feb 2018, 08:51; edited 1 time in total
Back to top
View user's profile Send private message 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 651

PostPosted: Tue 13 Feb 2018, 20:52    Post subject:  

@jafadmin
Thanks for this. I have only been able to take a cursory look but I think I'll be spending some time with it. I have been seeking a way to use udev and uuid with flash drives when designations are changed on insertion and removal.
Take a look at my post from 2012. Not a single response in over 5 years. I think I may be able to make some progress now.

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 715

PostPosted: Tue 13 Feb 2018, 21:45    Post subject:  

@B.K. Johnson

Peruse the "mkrule" script and examine the "udevadm info" command. This is how we harvest the fields we want the udev rule to consider.

IMHO, you won't need the UUID filter to make your project work ..
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 3407
Location: King's Lynn, UK.

PostPosted: Wed 14 Feb 2018, 06:35    Post subject:  

Morning, all.

I can confirm that this works very well indeed.....at least for me.

As a full-time carer, although I get a lot of free time, I also have to go off at a moment's notice.....sometimes for a while. I don't want to leave the computer 'ticking-over' all that time, nor do I want repeated start/stop cycles; the big Compaq desktop is quite an elderly 'dowager duchess' of a machine, and I don't want to impose any more strain on the circuits than I have to.

I've been implementing the desktop 'suspend script' frenchiveruti posted about here, across the kennels. For some reason, whenever I do this in a 'buntu-based Pup, the external 3 TB Seagate USB 3.0 hard drive that I use for pretty much all my personal data insists on 're-mounting' (at 'wake-up') as the next set of mount-points up.

Example; currently in Upup Raring, I suspended last night with the mount-points for this at sdj1/sdj2. This morning, upon waking-up, they're now at sdk1/sdk2. (Normally, these mount as sdg 1/2; I know it seems rather high, but I have an internal multi-card reader, which occupies several of the lower mount-points.I have no idea why, but the Slackos seem to be immune to this; 560 & 570 're-mount' at wakeup with the same mount-points as before... (??))

---------------------------------------------
Be that as it may, this plays havoc when you have a lot of stuff sym-linked from a 'permanent' external (the way I do) into each Pup.....quite a bit of it needing to be executed at startup. Udev-rules neatly sidesteps all this, providing a set of permanent, stable mount-points in "/". Jafadmin's 'wizard' is especially handy, making the whole process much easier.

Now, I run all my sym-links from the directory in "/".....and everything works as it should. (I simply 'ignore' Pup's desktop drive icons for the Seagate; the 'step-up' of increasing mount-points is of no consequence any more.)





Cheers, jafa..!


Mike. Wink

_________________
If I've helped you.....please say 'Thanks'!
MY PUPPY PACKAGES
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
jafadmin

Joined: 19 Mar 2009
Posts: 715

PostPosted: Wed 14 Feb 2018, 15:02    Post subject:  

I've often wondered why Puppies don't have a similar script built into all the distros. It seems so completely organic, to me.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1514s ][ Queries: 12 (0.0181s) ][ GZIP on ]