3

I want to mount my other drives (mostly ntfs and fat) on /drivename by clicking on the drive icon in the nautilus side pane, where "drivename" refers to the label of the drive. By default nautilus mounts drives with name drivename in /media/drivename folder.

My question is: How can I make nautilus to do like that?

I don't want to use fstab: Please do not suggest doing this by editing /etc/fstab file. I want this feature in nautilus and after clicking the drive should also be seen in the side pane. (should not be hidden).


Edit: Seems there are some misunderstanding with this question. I don't want to mount in the drive /, i.e all contents of a drive in /. What I want is when I mount a drive with drive name "Main", that drive will get mounted at /Main instead of /media/Main.

5
  • 3
    Why would you want to do that? The filesystem hierarchy standard or FHS states that /mnt/ and /media/ are the folders used for mounting. Jun 12, 2012 at 14:40
  • @medigeek, to do less typing when in terminal.
    – Anwar
    Jun 12, 2012 at 15:37
  • > @medigeek, to do less typing when in terminal. I can provide you with two workarounds: 1. Install the package nautilus-open-terminal Log out and log back in. Now you can right click inside any folder and open a terminal in the current folder path. 2. Linking: The ln -s command can help you create a symbolic link of a folder to the root filesystem. sudo ln -s /media/myfolder /m1 ls -l /m1 Jun 12, 2012 at 16:04
  • Do you know about auto-complete? When typing a path in the terminal, type a letter or 2 then hit the <tab> key and it will complete the name of the folder/file for you.
    – Jazz
    Jul 24, 2012 at 6:06
  • @ubnewbie2 Short answer: Yes. But, it is not only for less typing. I want to have them in my / dir. That's the point
    – Anwar
    Jul 24, 2012 at 6:09

4 Answers 4

1

you need write a udev rule for this: you can create a file in the directory /etc/udev/rules.d/ with

# Start at sdb to avoid system harddrive. 
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# Global mount options
ACTION=="add", ENV{mount_options}="defaults,relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs",         ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o    $env{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"

And change the actions ADD and REMOVE with your path, in this case /

ACTION=="add", RUN+="/bin/mkdir -p /%E{dir_name}", RUN+="/bin/mount -o    $env{mount_options} /dev/%k /%E{dir_name}"
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /%E{dir_name}", RUN+="/bin/rmdir /%E{dir_name}"
3
  • No, It is not doing what you say.
    – Anwar
    Jun 14, 2012 at 21:11
  • why no? what fail? Jun 15, 2012 at 20:58
  • It is only mounting the externel drives (USB Pendrives) and The mounted drive is not in the left pane of Nautilus
    – Anwar
    Jun 16, 2012 at 0:07
1

You can do this by extending these rules as your need -

# Start at sdb to avoid system harddrive. 
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# Global mount options
ACTION=="add", ENV{mount_options}="defaults,relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs",                ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o        $env{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}",   RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"

Take a closer look at the rules. It is not working for hard disk drives. KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end" says if device name is sda* (if not sdb* or sdc*) go to the label media_by_label_auto_mount_end ie. to the end of the rules. So Edit the line as you want. But don't forget about the system drive. Add an exception for it.

If your system drive is /dev/sda7 then first couple of line should be

KERNEL=="sda7" GOTO="media_by_label_auto_mount_end" #sda7 is system drive, so go to end.
#KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"

If you need to run additional command(s) concatenate them with RUN.

For more on udev rules click here

1
  • But, It doesn't work as expected. All partitions with some other extras dumped into the /media/ folder with some error messages during boot time. anyway thanks for response.
    – Anwar
    Jul 24, 2012 at 15:26
1

You want dynamically mounted volumes to appear directly in /. So far, work on this problem has focused on changing it from /media to /. I suspect there is some way to do that. But a simple, quick-and-dirty solution would be to make it so /media and / are the same folder.

I can't strongly recommend this, as the system is not designed to work this way, and there may be bugs that exists because developers did not consider this possibility. (Some might even not consider the assumption that / is not /media a bug.)

But you should be able to make /media a symbolic link to /, so that when something is mounted in /media/mount-point, it is actually mounted in /mount-point.

  • It will also be accessible through /media/media/mount-point, /media/media/media/mount-point, and so forth, though it would be quite confusing if you were to actually access it by those names.

Please note that while I have not done the necessary research to ensure that this could never create a security problem, it doesn't create one in any of the ways that it would initially seem to:

  • The directories in /, like /usr and /dev, that a non-root user could obtain system access by compromising, cannot be accessed in this way. If you mount a partition whose volume name is /usr, it won't overwrite or give access to /usr, it will mount with an alternate name (usually /usr_).

  • This does not give unrestrained access in /, and you do not need to (and indeed, should not) change ownership or permissions of / (or any other file or folder). The ownership and permissions of / and /media are already the same (0755, root:root):

    ek@Apok:~$ ls -ld / /media
    drwxr-xr-x 25 root root 4096 2012-07-15 19:17 /
    drwxr-xr-x 14 root root 4096 2012-07-23 15:16 /media
    

    It's only for specific mount points that non-root users may gain access they didn't already have, when the device is mounted on them.

To make /media a symbolic link to /, follow these steps:

  1. Unmount all your partitions that are mounted in /media so /media is empty.

  2. Delete /media:

    sudo rmdir /media
    
  3. Recreate /media as a symbolic link to /, located in /:

    sudo ln -s / /media
    

    Please note that / comes before /media in the ln command, because when creating symbolic links, we put the target first, and then the source.

If you ever need or want to undo this, just perform the steps in reverse:

  1. Unmount all dynamically mounted partitions.

    • They're mounted in /, but it's through the /media symbolic link, so you probably won't be able to remove that symbolic link while they're mounted, and if you did, you may not be able to access them, flush data to them, or unmount them cleanly.
  2. Remove the symbolic link:

    sudo rm /media
    
  3. Re-create the real directory:

    sudo mkdir /media
    

    You don't have to specify a bitmask, because when you create a folder as root, the default permissions are correct for /media.

This method is similar to the previous suggestion to manually create individual symbolic links in / to specific subdirectories of /media. It's different in that the symbolic link is /media itself, which should result in the exact behavior the OP requested, without having to manually make links for each mount point.

1
  • +1 for the answer. Although the answer successfully emulates the specification, but I also wanted them to display in the nautilus side pane. But, those disappear after mounting
    – Anwar
    Jul 25, 2012 at 18:03
-1

As far as I know, This isn't possible now, (at least not feasible). It may require compilation of some packages including nautilus

4
  • This is not true. Jul 24, 2012 at 17:37
  • But, After tying several answer and many solutions including myself, I think this is the answer. I will happily unaccept it if I get one answer. Eliah's answer was close, but I also want them to appear in the left bar, which is missing in his answer.
    – Anwar
    Jul 26, 2012 at 11:17
  • I seem to recall from chat that @BrunoPereira had tried one or more of the other answers (besides mine) and it had worked. Maybe the problem is specific to your system (or may the answers need to be updated to account for specific issues). Perhaps chat would be a good place to discuss these details. Jul 28, 2012 at 0:30
  • @EliahKagan OK, We can talk in this room
    – Anwar
    Jul 28, 2012 at 4:04

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.