I want to create a symlink to a device.When i tried the command
ln -s /dev/sr0 /dev/scd0
it looked everything well.But when i restarted the server,i found /dev/scd0 is disappered. How can i create a permanent link?
Modern linux distros use udev device manager, so you need to create a udev rule to achieve this.
As a root
user create a new file named 99_sr0.rules
in /etc/udev/rules.d/
with the following contents
KERNEL=="sr0", SYMLINK+="scd0"
Reboot your PC or run
sudo udevadm control --reload-rules; sudo udevadm trigger
to re-run your udev rules and you will see your symlink
> ls -l /dev/sr0 /dev/scd0
lrwxrwxrwx 1 root root 3 May 22 18:54 /dev/scd0 -> sr0
brw-rw----+ 1 root cdrom 11, 0 May 22 18:54 /dev/sr0
>
/dev
. (-:
– JdeBP
May 23 '18 at 11:46
I just came across a solution described in proxmox wiki
If you have a good number of disks keep organized by using aliases. Edit /etc/zfs/vdev_id.conf to prepare aliases for disk devices found in /dev/disk/by-id/ : run 'udevadm trigger' after updating this file
alias a0 scsi-36848f690e856b10018cdf39854055206
alias b0 scsi-36848f690e856b10018cdf3ce573fdeb6
alias a1 scsi-36848f690e856b10018cdf40f5b277cbc
alias b1 scsi-36848f690e856b10018cdf43a5db1b99b
alias a2 scsi-36848f690e856b10018cdf4575f652ad0
alias b2 scsi-36848f690e856b10018cdf47761587cec
Seems it can solve OP's problem quite elegantly, I also think using /dev/disk/by-id/wwn-xxx is more appropriate, since is guaranteed not to changed even if the disk is moved to another system.
/dev/disk/by-id/xxxxxxxxxxxxxxxxxxxx
avoids any user created aliases.
– Jeremy Boden
Aug 14 '21 at 16:35
/dev
, like/proc
and/run
gets populated on boot and disappears into the aether on shutdown, so any symlinks made there will never stick. I worked around a similar issue (USB automount) by symlinking the automountpoint in/run/media/user/
to/home/user/usbstick
. – Mio Rin May 23 '18 at 01:44