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 ..

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 ..

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

@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

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.)

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