Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: How to automount automatically all units?

  1. #11
    Join Date
    Dec 2014
    Beans
    122

    Re: How to automount automatically ALL UNITS ??

    Many thanks Dennis N and schragge,

    That is just my problem, I want connected drives/disks/units to be mounted automatically on boot when they're connected in the moment of boot, so Dennis N has just describe it.

    In kubuntu it solved as I told, but now with Xubuntu I don't know how to. I've spent a lot of time and can't get a way to, I only read about including the disk in /etc/fstab, but I want ANY NEW UNIT to have this behaviour without having to add manually.

    I've found some information about Pysmd, but seems to be outdated.

    I honestly think it should be like this by default and don't understand why works as it does, It has nosense at all that you boot a computer and units connected are not avaiable until you click them in the file manager.

    Regards and thanks again, I hope someone can help me.

  2. #12
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to automount automatically ALL UNITS ??

    Ok, if you're going down the udisksctl path

    Basically you can enumerate removable media with something like
    Code:
    udisksctl dump|awk -F':\n' -v'RS=\n\n' '/[ \t]*HintAuto:[ \t]*true/&&/\.Filesystem:/{sub(/.*\/UDisks2\//,"",$1); print $1}'
    You can then directly mount them with
    Code:
    udisksctl mount -p path/from/the/command/above
    Then put the commands into a script, glue them with some shell code and make the script be invoked automatically on login.
    Code:
    #!/bin/sh
    
    udisksctl dump |
      awk -F':\n' -v'RS=\n\n' '/[ \t]*HintAuto:[ \t]*true/&&/\.Filesystem:/{
                                 print $1
                               }' |
      while read dev
      do
        udisksctl mount --object-path "${dev##*/UDisks2/}"
      done
    There are also some ready-made scripts that work with udisks.

    Another possibility is gvfs-mount.
    Last edited by schragge; January 2nd, 2015 at 01:58 AM. Reason: simplified, thx @Dennis N for hints

  3. #13
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    4,397

    Re: How to automount automatically ALL UNITS ??

    I did an test with Lubuntu 14.04. I inserted a USB flash drive (4gb stick) into a usb port and started up. After loging in, I found the flash drive had mounted automatically (no commands needed) and was accessible to applications. I was thinking I had noticed this before in Lubuntu, and was right. This is apparently the default in Lubuntu (but other disk partitions are not mounted automatically).

    By the way, I checked and found the udisksctl did not work to mount a flash drive automatically on login in Xubuntu - I amended my post #4 to reflect this. Maybe a different formulation would work, but I don't need that feature - working for partitions is enough. The command I have been using for mounting a partition at login is one of these:

    Code:
    udisks --mount /dev/disk/by-label/CommonData
    udisksctl mount -b /dev/disk/by-label/CommonData
    depending on the OS. Ubuntu 12.04 uses udisks.

  4. #14
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to automount automatically ALL UNITS ??

    @Dennis N: I amended my post, too. It's actually simpler than I thought. Thanks for useful hints. I've just tried it in Xubuntu with the shell script from my post above put in ~/bin/massmount, this ~/.xsessionrc:
    Code:
    PATH=$HOME/bin:$PATH
    and this ~/.config/autostart/massmount.desktop:
    Code:
    [Desktop Entry]
    Encoding=UTF-8
    Exec=massmount
    Name=Automatically mount removable media
    Comment=
    Terminal=true
    Type=Application
    StartupNotify=false
    OnlyShowIn=XFCE;
    NoDisplay=true
    and it successfully mounts unmounted flash drives on login (the state they are in after boot up). OTOH, after the flash drive is ejected, it cannot be mounted by the script.
    Last edited by schragge; January 2nd, 2015 at 02:36 AM.

  5. #15
    Join Date
    Dec 2014
    Beans
    122

    Re: How to automount automatically ALL UNITS ??

    Many thanks again to both of you.

    I'm not sure if I understand the procedure, schragge, I've do this having a USB drive connected but not mounted:

    Code:
    udisksctl dump|awk -F':\n' -v'RS=\n\n' '/[ \t]*HintAuto:[ \t]*true/&&/\.Filesystem:/{sub(/.*\/UDisks2\//,"",$1); print $1}'
    Output:

    Code:
    block_devices/sdb1
    Then I run:

    Code:
    udisksctl mount -p /block_devices/sdb1
    And the result:

    Code:
    (udisksctl mount:2294): GLib-GIO-CRITICAL **: g_dbus_object_manager_get_object: assertion 'g_variant_is_object_path (object_path)' failed
    Error looking up object with path /block_devices/sdb1
    (usb drive is not mounted)

    I don't really understand what you told in the last post, where you menction ~/bin/massmount, this ~/.xsessionrc and ~/.config/autostart/massmount.desktop. I mean, I'm not sure if you told to add those lines of code to those files or using the ones you wrote on last post.

    Many thanks again for the help, I hope we can get some way of doing what I need, I'm sure many people will find it usefull.

    Regards

  6. #16
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to automount automatically ALL UNITS ??

    No. If you want to mount it manually, you should use exactly the output of the first command, i.e. without the leading slash:
    Code:
    udisksctl mount -p block_devices/sdb1
    Quote Originally Posted by fkervin
    I don't really understand what you told in the last post, where you menction ~/bin/massmount, this ~/.xsessionrc and ~/.config/autostart/massmount.desktop. I mean, I'm not sure if you told to add those lines of code to those files or using the ones you wrote on last post.
    I'm afraid I was not very clear. So here it once again.

    Make directory ~/bin:
    Code:
    mkdir ~/bin
    Take this script:
    Code:
    #!/bin/sh
    
    udisksctl dump |
      awk -F':\n' -v'RS=\n\n' '/[ \t]*HintAuto:[ \t]*true/&&/\.Filesystem:/{
                                 print $1
                               }' |
      while read dev
      do
        udisksctl mount --object-path "${dev##*/UDisks2/}"
      done
    Put it into the file named massmount. Save the file in ~/bin/ directory. Add executable permissions on the file:
    Code:
    chmod +x ~/bin/massmount
    Create the file .xsessionrc in your home directory. It should contain
    Code:
    PATH=$HOME/bin:$PATH
    Create the file massmount.desktop. It should contain
    Code:
    [Desktop Entry]
    Encoding=UTF-8
    Exec=massmount
    Name=Automatically mount removable media
    Comment=
    Terminal=true
    Type=Application
    StartupNotify=false
    OnlyShowIn=XFCE;
    NoDisplay=true
    Put it into directory ~/.config/autostart/.

    Check that all pieces of the puzzle are in place. This commands should output the contents listed above:
    Code:
    cat ~/bin/massmount
    cat ~/.xsessionrc
    cat ~/.config/autostart/massmount
    Now your flash drives should get mounted automatically on login.

  7. #17
    Join Date
    Dec 2014
    Beans
    122

    Re: How to automount automatically all units?

    Thanks schragge!!!!

    I've just try and it works!! So i can't give you thanks enought

    Everyways I still have a pair of questions:

    -It mounts USB hard drives and USB thumb drives but doesn't mount other internal hard drives than the system one. Any way of modifying it in way that works also with internal disks? (I suppose it would be modifying this:

    Code:
    awk -F':\n' -v'RS=\n\n' '/[ \t]*HintAuto:[ \t]*true/&&/\.Filesystem:/
    In way that also pass the internal drives to the next "while".

    -When computer boots I see for a moment the terminal window mounting the disks, is there any way to execute it in "silent mode", I mean, to avoid the window appear.

    Many many thanks again, really, if I can meet those two things it would be great, but with the thing I've yet I'm very happy anyway

    Regards

  8. #18
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to automount automatically all units?

    Quote Originally Posted by fkervin View Post
    Any way of modifying it in way that works also with internal disks?
    While it is certainly possible, there's absolutely no point in doing so. Internal disks should be mounted through /etc/fstab (see community/Fstab, community/MountingWindowsPartitions, community/InstallingANewHardDrive, community/AutomaticallyMountPartitions, community/UsingUUID). Permanently attached devices may be addressed by UUIDs, labels, whatever thingies that unambiguously identify them.

    -When computer boots I see for a moment the terminal window mounting the disks, is there any way to execute it in "silent mode", I mean, to avoid the window appear.
    Oh sure, there are many ways to automatically execute a script on startup that not involve opening separate terminal window. Instead of invoking it from ~/.config/autostart/massmount.desktop, you could call it from /etc/rc.local, or as part of an upstart job in /etc/init/, or as session-setup-script from lightdm.conf, and so on. The first problem with these approaches is that the script would be then called unconditionally. Using freedesktop.org autostart specification we can restrict its execution to specific desktop environment(s) (see OnlyShowIn=XFCE; stanza in the massmount.desktop file). The second problem is that it would be then executed by root unless we call it like sudo -u <user> massmount or su - <user> -c massmount.

    TBH, I'm even not sure that the line Terminal=true in massmount.desktop is really needed. Just remove it, and see if the script still works as intended. Maybe you'll need to redirect the output of udisksctl mount to /dev/null in this case.

  9. #19
    Join Date
    Dec 2014
    Beans
    122

    Re: How to automount automatically all units?

    Hi again schragge,

    I've change Terminal=True to Terminal=False and it works but doesn't show terminal window .

    Besides that, I didn't like having bin folder on home, so I've move bin folder from home to another location, modifiyng then .xsessionrc to point the correct folder "PATH=/etc/fkervin/bin:$PATH".

    With this I only have to learn using /etc/fstab to add internal drives, with the links you've provide me I'm sure it will be easy

    Again, my biggest possible thanks to you and all the others who has interest in my question.

    Regards

  10. #20
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to automount automatically all units?

    Well, $HOME/bin is more or less standard way to handle executables that only needed by you. If your machine has several user accounts, and you want the script to be executed for them all on logon, you can put it into /usr/local/bin. You don't need .xsessionrc to amend PATH at all in this case as /usr/local/bin is already on system PATH by default. And massmount.desktop should be put in /etc/xdg/autostart then.

    Please mark this thread SOLVED, if it's solved (see UnansweredPostsTeam/SolvedThreads).

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •