2

I want to make a script to mount an external device to a particular mount point e.g say /mnt. Let me elaborate my question, suppose I run fdisk -l in terminal I would get this output

Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         493     3956672    6  FAT16

so I want to write a script so that when I run that script it checks for where external device is mounted(in my case sdb1) and automatically takes that partition and mount it to /mnt

I have scientific linux 6.4(32 bit) .

  • 2
    How would you know which device you want? That's not the entire fdisk output, you also have sdaN. Will it always be sdbN? Will it always be an external device? What else defines it? What if you have an external device with multiple partitions? – terdon Jun 20 '14 at 12:25
  • 1
    Refer this link. linuxconfig.org/… – Ramesh Jun 21 '14 at 2:13
0

I guess udev could help.

First you need to get serial of your device:

udevadm info -a -p $(udevadm info -q path -n /dev/sdb) | grep -i serial

then add the rule to /etc/udev/rules.d/

SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="sd?1", ATTRS{serial}=="HARDDRIVESERIAL", RUN+="/bin/mount /dev/%k /mnt/",OPTIONS="last_rule"
  • When I run "udevadm info -a -p $(udevadm info -q path -n /dev/sdb) | grep -i serial" I got two serial numbers which one to use ? ATTRS{serial}=="82HRQHIY" ATTRS{serial}=="0000:00:1d.7" @dchirikov – Rahul Jun 24 '14 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.