How does the kernel decide what device to create when a new drive is plugged in?
I have 1 permanent drive. I often plug in a USB drive. Usually it's assigned /dev/sdb . Sometimes it's assigned /dev/sdc even though sdb is available. Why? I have scripts that expect /dev/sdb.
|
sda, sdb, sdc and so on are not persistent names. I can't tell you what causes your particular disk to be sometimes sdb, sometimes sdc, but in any case it's risky (as you just learned :)) to believe that the disk will always get the same device name.
Your disk has various properties that your system uses to generate persistent names, such as UUIDs, filesystem or swap LABELs, hardware paths, SCSI addresses and so on. In most distros, udev creates symbolic links under /dev/disk whose names are guaranteed to always refer to the same disk. (not quite actually - when you clone a disk, the clone will receive all UUIDs and LABELs, and you can connect the same disk to different hardware paths. As long as you know what you are doing, though, the persistent naming mechanisms work reliably) Since I don't know your application, I don't have a full solution for your problem, but I suggest to educate yourself about persistent naming. |
you might see a switch from sdb to sdc if the status of the drive changed in some way.
You should not use scripts that require sda sdb etc. What if you have 2 usb drives , how does your script know you plugged the right one in? hint: [code] ls -l /dev/disk/* ]/code] /dev/disk/by-uuid Is probably what you want But I have no idea what you have scripted, so that is a complete guess. Code:
lsblk -O -J | jq . |
following the comments above...I get around this by creating a mount point and adding an entry to /etc/fstab with the mount point and the UUID of the drive. I use the mount point in my scripts. If the USB drive changes, change fstab to recognise this
The fact that my learned friends have not already mentioned this makes me wonder...am I missing the point |
Quote:
maybe it is putting a fs on the partition. all we know is some script needs /dev/sdb Which tells me said script needs to be re-written or at least fixed. |
Quote:
I don't know the root cause, but I can confirm the "issue". And personally I think it has something to do with inproper unmount of a device and device timeout. Quote:
|
Quote:
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
I don't have a problem, but a question. |
Your script doesn't work, the reason you started the thread proves that.
Edit: "is broken" is a better fit than "doesn't work" if you are going to troll, at least be smart about it. |
Quote:
|
Quote:
Code:
/dev/disk/by-id/ata-ST1000DM003-1ER162_S4Y0Y819 |
Quote:
Quote:
It turned out to be an orphaned entry in /etc/mtab. |
Quote:
Quote:
Quote:
If you want to carry on using error prone, flaky scripts on your slackware It won't make too much difference. |
Quote:
The issue here is the behavious of sdx IS NOT predictable despite using sdx in a way that it SHOULD be predictable. The question is why. I added my view and have experienced the same behaviour, and I think the conclusion of the thread is pretty much the same with "the orphan in /etc/mtab". The more important question is, why does that happen? My theory had to do with inproper unmount and timeout. After x time, you will be assigned sdb in either case, but factor y causes sdc "issue" before x time factor, due to cause z. Is cause z inproper unmount? I don't know. Is there an x timeout factor? I'm not sure. z=y? |
I don't know what the script does
it should not expect /dev/sdb since you can not guarantee that will exist or that it will be correct. see the OP ! The Script should either, rely on user input when running the script Code:
./script.sh /dev/sdb |
All times are GMT -5. The time now is 02:12 PM. |