2

I need an SD card to be mounted unattended, as soon as it is inserted in its slot. Usual enough, but the prbm is it does not get mounted and I am missing why.

In /etc/fstab:

#Entry for /dev/mmcblk0p1 :
UUID=_____   /mnt/SD-root ext3 defaults,nofail,umask=0027,utf8,comment=x-gvfs-show,x-gvfs-name=SD-root 0 2

EDIT-1: I also tried replacing /mnt/ with /media/myname/ above, and including the options user,uid=1000 (that's me) or users, to no avail.

Mount point is either /mnt/SD-root or /media/myname/SD-root. Mountpoint ownership is set to "root : adm".

$ ls -Al /mnt/ | grep -e 'SD-root'
1 drwxr-x--- 3 root adm 1024 Sep 25 16:51 SD-root/

Right now the only way for a non-root user to mount the SD card is to:

$  sudo mount /dev/mmcblk0p1 /mnt/SD-root/

What am I missing ?

5
  • 2
    /etc/fstab is for automounting when you boot not for automounting when you insert the card
    – mchid
    Sep 29, 2015 at 3:58
  • @Mchid: Not precisely. /etc/fstab is read at boot time when mountall is invoked to mount filesystems and detected block-devices are listed and don't have option noauto set . However /etc/fstab can also be and is used to list mounting options for devices not meant to be mounted at boot. Isn't that's the raison d'être of the option noauto ?
    – Cbhihe
    Sep 29, 2015 at 15:10
  • Then why doesn't it work?
    – mchid
    Sep 29, 2015 at 18:00
  • 2
    It doesn't work because: /etc/fstab is for automounting when you boot not for automounting when you insert the card
    – mchid
    Sep 29, 2015 at 20:38
  • 2
    @mchid: :D :D :D Cbhibe: two words: udev rules!
    – Fabby
    Sep 29, 2015 at 23:44

3 Answers 3

3

To mount the card automatically at /mnt in a running system you could use an additional udev rule. Without the rule, the card is mounted in /media/$USER/… and /dev/disk/….


The following script and udev rule create a folder in /mnt and mount a the partition with a defined UUID. In the current version, the mountpoint is the label of the mounted partition. I personally think, that's a bad idea. I would prefer the UUID and not the label, but the OP wanted this solution.

  1. The script

    • Create a script in /usr/local/bin

      sudo nano /usr/local/bin/mount_by
      
    • Add the code below

      #!/bin/sh
      export mount_point="/mnt/$1"
      existing_device=$(awk '$2 == ENVIRON["mount_point"] {print $1; exit}' < /proc/mounts)
      if [ -n "$existing_device" ]; then
        exit 1
      fi
      mkdir -p "$mount_point"
      sleep 1 # Perhaps not necessary, but in the test with the OP it was necessary
      mount "/dev/disk/by-uuid/$2" "$mount_point"
      exit 0
      
    • Make the script executable

      sudo chmod +x /usr/local/bin/mount_by
      
  2. The udev rule

    • Create a new rule

      sudo nano /etc/udev/rules.d/99-myrules.rules
      
    • Add the code below

      ENV{ID_FS_UUID}=="c8bf306d-3d5d-4878-8045-e4087494eff0", RUN+="/usr/local/bin/mount_by '%E{ID_PART_ENTRY_NAME}' '%E{ID_FS_UUID}'"

      or if your drive hasn't the ID_PART_ENTRY_NAME, try ID_FS_LABEL

    • Suppose that the partition is /dev/sdc1 Replace the value for ENV{ID_FS_UUID}== above with the output of

      udevadm info /dev/sdc1 | awk -F= '/ID_FS_UUID=/ {print $2}'
  3. Restart udev

    sudo service udev restart
    
  4. Plugin your SD card and you should see something like this

    % ls -la /mnt
    total 12
    drwxr-xr-x  3 root root 4096 Okt  6 19:29 .
    drwxr-xr-x 25 root root 4096 Sep 29 17:04 ..
    drwxr-xr-x  4 root root 4096 Okt  6 19:31 Label1
    
12
  • Can you give me pointers to a wiki or else to learn about udev rules ?
    – Cbhihe
    Sep 29, 2015 at 16:06
  • @Cbhihe: "Yes, expand your answer" = "I'll click ☑" (which means Yes, this answer is valid) so you can expand the answer...
    – Fabby
    Sep 29, 2015 at 17:52
  • @Fabby: Gee ! I was waiting for you to answer, just so I could select his ! Bear with me until tomorrow. Till then my hands are full.
    – Cbhihe
    Sep 29, 2015 at 19:16
  • 1
    @Cbhihe: I'm not A.B. ... Just dropping by because I didn't see an accepted answer! ;-)
    – Fabby
    Sep 29, 2015 at 19:58
  • I can't read your dropbox. Please use paste.ubuntu.com
    – A.B.
    Oct 1, 2015 at 6:00
1

I setup fresh new Ubuntu 14.04 to test this. The SD card formated as EXT3. The is automounted.

Here output of mount with different setups

  • With default setup, no fstab entry:

    /dev/mmcblk0p1 on /media/sneetsher/test0 type ext3 (rw,nosuid,nodev,uhelper=udisks2)
    
  • With fstab:

    /dev/mmcblk0p1                            /media/test0    ext3    nodev,noexec,comment=x-gvfs-show 0       0
    

    mounted as:

    /dev/mmcblk0p1 on /media/test0 type ext3 (rw,noexec,nodev)
    
  • With fstab:

    /dev/mmcblk0p1                            /media/test0    ext3    defaults,nofail,umask=0027,utf8,comment=x-gvfs-show,x-gvfs-name=SD-root 0 2
    

    Found dmesg errors:

    [ 3339.729139] EXT4-fs (mmcblk0p1): Unrecognized mount option "umask=0027" or missing value
    

    removed, then found:

    [ 3410.950108] EXT4-fs (mmcblk0p1): Unrecognized mount option "utf8" or missing value
    

    removed, then found:

    [ 3490.129696] EXT4-fs (mmcblk0p1): Unrecognized mount option "x-gvfs-name=SD-root" or missing value
    

    changed to:

    /dev/mmcblk0p1                            /media/test0    ext3    defaults,nofail,comment=x-gvfs-show,comment=x-gvfs-name=SD-root 0 2
    

    mounted as:

    /dev/mmcblk0p1 on /media/test0 type ext3 (rw,_netdev)
    

    x-gvfs-name is effective as it shown as SD-root in nautilus.

Did I miss some thing from your setup?

3
  • Thanks for taking the time Sneetsher. As evidenced by yr tests utf8 is not a valid option for ext4 or ext3. Also the umask=---- options spells trouble. That I don't comprehend. Nevertheless at least for the time being, my preferred mount route is that proposed by @A.B., i.e. with udev rules.
    – Cbhihe
    Oct 27, 2015 at 8:04
  • Could you reference from where did you get those options, I could find them in man mount for some other file systems but not for ext3.
    – user.dz
    Oct 27, 2015 at 18:35
  • You'll find everything in mount(8), I think.
    – Cbhihe
    Oct 29, 2015 at 7:17
0

Just take the ownership of the folder /media/test0.

chown user.user /media/test0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .