1

I have an external USB drive which is always plugged in. I have modified fstab and created a folder in media so that the drive is mounted at media/drive_name. However, is automount is enabled, every time I restart the system the drive get remounted in media/user_name/drive name. I would like to keep automount on for other devices, but for this specific one have my own mount point. Is there any way to do this?

  • Would you settle for running a script? – TheWanderer Apr 21 '15 at 00:16
  • What modifications did you make to fstab? – muru Apr 21 '15 at 00:18
  • http://askubuntu.com/questions/214646/how-to-configure-the-default-automount-location. Read that. It might explain some stuff. – TheWanderer Apr 21 '15 at 00:24
  • I would settle for a script. – Steve Kiss Apr 21 '15 at 00:40
  • I added the following to my fstab: /dev/sdb1 /media/drive_name defaults 0 2.. However, when I restart the system it will appear as /dev/sdc1 and be mounted as /media/user_name/drive_name. If I then unmount it, edit fstab to use sdc1, and remount it, on reboot it appears as sdb1 again.. I have to go through this process each time I reboot. – Steve Kiss Apr 21 '15 at 00:43
  • @Zacharee1: Thank you for the link, but I would like this to apply only to this drive. Other plugged in drives can be automounted to the user's home folder. – Steve Kiss Apr 21 '15 at 00:45
  • @SteveKiss I was referring more to the accepted answer. Would you mind mounting it manually, though? – TheWanderer Apr 21 '15 at 00:48
  • @Zacharee1, I see. I guess I will have to mount it manually with a script each time? Is that the right direction? I don't mind this as long as I don't have to deal with it on each reboot. – Steve Kiss Apr 21 '15 at 00:50
  • @SteveKiss Yes. You should make a script to mount it, then move the sh file to the startup directory, which I will search for and include in the answer I will write if this is what you want. – TheWanderer Apr 21 '15 at 00:52
  • @Zacharee1, that would be great. Thank you! – Steve Kiss Apr 21 '15 at 00:56
  • @SteveKiss Still finding good ways to add a startup script. Should be a few minutes. – TheWanderer Apr 21 '15 at 00:57
  • @SteveKiss OK. Try it. – TheWanderer Apr 21 '15 at 01:13
  • @SteveKiss You should use UUIDs instead of /dev/sdXY. See http://askubuntu.com/questions/17381/unity-doesnt-load-no-launcher-no-dash-appears – muru Apr 21 '15 at 01:21
  • @Zacharee1, worked like a charm. Thank you!! – Steve Kiss Apr 21 '15 at 23:22
  • Good! @SteveKiss – TheWanderer Apr 21 '15 at 23:26
  • I use fstab by UUID for /mnt SATA drives. pmount is for named USB drives. It always automatically ensures they have the correct name under /media. https://askubuntu.com/questions/88523/creating-a-mount-point-if-it-does-not-exist/941726#941726 – SDsolar Aug 01 '17 at 09:55

1 Answers1

2

Try this:

  1. Make your script: make a new text document and put this in:

    #!/bin/sh  
    mkdir -p /path/to/custom-mount  
    sudo umount /dev/sdaX ((This is the drive you want to mount in the custom location))  
    sudo mount -t filesystem-type -o rw /dev/sdaX /path/to/custom-mount  
    
  2. Put this script under /etc/init.d.

  3. Make it executable by running sudo chmod -x /etc/init.d/script-name.
  4. Run update-rc.d script-name defaults.

Hopefully, this will unmount your drive and then remount it under the folder you want.

muru
  • 197,895
  • 55
  • 485
  • 740
TheWanderer
  • 19,395
  • 12
  • 50
  • 65
  • @ThomasW. I think he already has that. Will it be removed upon reboot, when the drive gets unmounted? – TheWanderer Apr 21 '15 at 01:15
  • missed that. sorry. It should stay but it's still a good form to make a note that you should make sure the mount point exists yet. In fact if you change /bin/sh to /bin/bash we can add in some error check code but meh – Thomas Ward Apr 21 '15 at 01:22
  • @ThomasW. I think it would be better to keep it simple. – TheWanderer Apr 21 '15 at 01:22
  • Yes, like - automatic. pmount takes care of this problem all by itself. https://askubuntu.com/questions/88523/creating-a-mount-point-if-it-does-not-exist/941726#941726 – SDsolar Aug 01 '17 at 09:56