[SOLVED] udev symbolically create link from sdf* to sdf
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I have some usb devices that have several internal partitions (I believe is due to the internal software for additional hidden partitions). But I want the top layer, that is either sdf1 or sdg1 rather than sdf or sdg. I have attempted to write this rule into /etc/udev/rules.d/local.rules:
Hi, I got udev to work finally, but now I am trying to customize the name in the dev rather than sdf, sdg...etc. I have the following in /etc/udev/rules.d/local.rules:
Aug 27 02:12:18 vector kernel: [ 73.146245] sd 7:0:0:0: [sdf] No Caching mode page present
Aug 27 02:12:18 vector kernel: [ 73.146252] sd 7:0:0:0: [sdf] Assuming drive cache: write through
Aug 27 02:12:19 vector udevd-work[2535]: exec of program '/mnt/main/script/udev.sh' failed
Aug 27 02:12:19 vector udevd-work[2539]: exec of program '/mnt/main/script/udev.sh' failed
Here is my script, I have tested it quite a few times and it gives the right response:
Code:
ted:$ cat /mnt/main/script/udev.sh
string="$1" ; name="${string:0:3}" ; number="${string:3}"
echo "$(date) $string" > "/mnt/main/report.log"
if [ -z "$number" ] && [ ! -e "/dev/${name}1" ] ; then
mname="$name"
elif [ ! -e "/dev/${name:0:3}$((number+1))" ] ; then
mname="${name:0:3}/${name:0:3}$number"
fi
if [ ! -z "$mname" ] ; then
size=$(udevadm info -a -p /sys/block/$mname | grep "ATTR{size}==")
size=$(echo "$size" | sed "s:\"::g")
size=$(echo "$size" | sed "s:ATTR{size}==::g")
if [ $size -lt 20000000 ] && [ $size != 0 ] ; then
for each in "/dev/pendrive"* ; do
max=$(echo "$each" | sed 's:/dev/pendrive::g')
done
if [ -z "$max" ] || [ "$max" == "*" ] ; then
echo "pendrive"
else
echo "pendrive$((max+1))"
fi
fi
fivector:/~
This is the error log for the debug mode, I don't understand why, my code runs perfectly, but it keeps give me error feedback:
Code:
.052872 [7141] udev_node_mknod: set permissions /dev/sdg1, 060660, uid=0, gid=83
1346012453.053078 [7141] node_symlink: preserve already existing symlink '/dev/block/8:97' to '../sdg1'
1346012453.053220 [7141] link_update: creating link '/dev/disk/by-id/usb-USB_Mass_Storage_Device_812320090519-0:0-part1' to '/dev/sdg1'
1346012453.053284 [7141] node_symlink: creating symlink '/dev/disk/by-id/usb-USB_Mass_Storage_Device_812320090519-0:0-part1' to '../../sdg1'
1346012453.053414 [7141] link_update: creating link '/dev/disk/by-path/pci-0000:00:1d.7-usb-0:4:1.0-scsi-0:0:0:0-part1' to '/dev/sdg1'
1346012453.053474 [7141] node_symlink: creating symlink '/dev/disk/by-path/pci-0000:00:1d.7-usb-0:4:1.0-scsi-0:0:0:0-part1' to '../../sdg1'
1346012453.053577 [7141] link_update: creating link '/dev/disk/by-uuid/F84E-1690' to '/dev/sdg1'
1346012453.053705 [7141] node_symlink: creating symlink '/dev/disk/by-uuid/F84E-1690' to '../../sdg1'
1346012453.054098 [7141] udev_device_update_db: created db file '/dev/.udev/db/b8:97' for '/devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4:1.0/host20/target20:0:0/20:0:0:0/block/sdg/sdg1'
1346012453.054247 [7141] util_run_program: '/mnt/main/script/udev.sh sdg1' started
1346012453.058529 [7141] util_run_program: '/mnt/main/script/udev.sh' (stderr) '1346012453.058372 [7161] util_run_program: exec of program '/mnt/main/script/udev.sh' failed'
1346012453.059124 [7141] util_run_program: '/mnt/main/script/udev.sh sdg1' returned with exitcode 1
1346012453.059236 [7141] udev_watch_begin: adding watch on '/dev/sdg1'
1346012453.059748 [7141] udev_device_update_db: created db file '/dev/.udev/db/b8:97' for '/devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4:1.0/host20/target20:0:0/20:0:0:0/block/sdg/sdg1'
1346012453.059900 [7141] udev_monitor_send_device: passed -1 bytes to netlink monitor 0x80756a0
I made it write into report.log file to make sure it was ran, but no luck.
I am not sure how I can pass the kernel variable to my script.
Thanks,
Ted
Last edited by ted_chou12; 08-26-2012 at 03:26 PM.
I guess no one has the idea,but I GOT it. I hope this helps someone someday somehow somewhere...anyway:
Code:
#!/bin/bash
string="$1" ; name="${string:0:3}" ; number="${string:3}"
if [ -z "$number" ] && [ ! -e "/dev/${name}1" ] ; then
mname="$name"
elif [ ! -e "/dev/${name:0:3}$((number+1))" ] ; then
mname="${name:0:3}/${name:0:3}$number"
fi
if [ ! -z "$mname" ] ; then
size=$(/sbin/udevadm info -a -p /sys/block/$mname | /bin/grep "ATTR{size}==")
size=$(echo "$size" | /bin/sed "s:\"::g")
size=$(echo "$size" | /bin/sed "s:ATTR{size}==::g")
if [ $size -lt 40000000 ] && [ $size != 0 ] ; then
if [ ! -e "/dev/pendrive" ] ; then
echo -n "pendrive"
else
i=1
while [ -e "/dev/pendrive$i" ] ; do
i=$((i+1))
done
echo -n "pendrive$i"
fi
fi
fi
I have no clue why shebang is so important here, cause I never added them in any of my scripts so far, in addition, adding absolute path to the function is for a additional measure to avoid errors.
in rules:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.