Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
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. –  medigeek Jun 12 '12 at 14:40
    
@medigeek, to do less typing when in terminal. –  Anwar Shah Jun 12 '12 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 –  medigeek Jun 12 '12 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 '12 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 Shah Jul 24 '12 at 6:09

4 Answers 4

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}"
share|improve this answer
    
No, It is not doing what you say. –  Anwar Shah Jun 14 '12 at 21:11
    
why no? what fail? –  Andrés Ricardo Torres Martínez Jun 15 '12 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 Shah Jun 16 '12 at 0:07

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

share|improve this answer
    
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 Shah Jul 24 '12 at 15:26

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.

share|improve this answer
    
+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 Shah Jul 25 '12 at 18:03
up vote -1 down vote accepted

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

share|improve this answer
    
This is not true. –  Bruno Pereira Jul 24 '12 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 Shah Jul 26 '12 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. –  Eliah Kagan Jul 28 '12 at 0:30
    
@EliahKagan OK, We can talk in this room –  Anwar Shah Jul 28 '12 at 4:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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