Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:07:16+00:00 2026-06-06T13:07:16+00:00

I apologise if the question is so stupid but I am new in linux

  • 0

I apologise if the question is so stupid but I am new in linux and python.
The point is that I need to write a python script which will detect connected usb stick and write a file to it. I use opensuse(but script shoild work with any linux distro. in ideal case). Current version can detect usb and write a file if that usb is mounted. But on my machine usb is mounted only if I browse it in file manager. Until that usb detected as a partion but without mount point. So, how can I force the system to mount usb or how can I write a file using devname or devpath or another information what I can get from hal manager. I can not use “mount” command because it requires a root permission

Simplified Source code:

import dbus, gobject, os

class DeviceAddedListener:
    def __init__(self):
        self.bus = dbus.SystemBus()
        self.hal_manager_obj = self.bus.get_object( "org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
        self.hal_manager = dbus.Interface(self.hal_manager_obj, "org.freedesktop.Hal.Manager")
        self.hal_manager.connect_to_signal("DeviceAdded", self.added)

    def show(self, name, udi):
        d_object = self.bus.get_object('org.freedesktop.Hal', udi)
        d_interface = dbus.Interface(d_object,'org.freedesktop.Hal.Device')

        if d_interface.QueryCapability("volume"):
            print name
            props = [ "block.device", "volume.label",  "volume.is_mounted", "volume.mount_point", "volume.size"]
            for p in props:
                print '\t', p, " = ",
                try:
                    print d_interface.GetProperty(p)
                except:
                    print "Fail"

    def added(self, udi): 
        self.show("DeviceAdded", udi)
        self.bus.add_signal_receiver(self.property_modified,
            "PropertyModified",
            "org.freedesktop.Hal.Device", 
            "org.freedesktop.Hal",
            udi,
            path_keyword = "sending_device" )

    def property_modified(self, numupdates, updates, sending_device = None): 
        self.show("PropertyModified", sending_device) 



if __name__ == '__main__':
    from dbus.mainloop.glib import DBusGMainLoop
    DBusGMainLoop(set_as_default=True)
    loop = gobject.MainLoop()
    DeviceAddedListener()
    print "running"
    loop.run()

The output when usb plugged in

DeviceAdded
block.device  =  /dev/sdb1
volume.label  =  @
volume.is_mounted  =  0
volume.mount_point  =  
volume.size  =  4009722368

The output when usb plugged in and mounted

    block.device  =  /dev/sdb1
volume.label  =  @
volume.is_mounted  =  1
volume.mount_point  =  /media/@
volume.size  =  4009722368

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:07:17+00:00Added an answer on June 6, 2026 at 1:07 pm

    You will have to use mount because the kernel controls mounting partitions within the operating system for security reasons. You can use mount without superuser/administrator privileges. Try something like this:

    Make sure that the directory (/mnt/usb1/) you are mounting to already exists, and then

    mount /dev/sdb1 /mnt/usb1 -o noauto,users,rw,umask=0
    

    There’s also something called autofs that does allow automatic mounting:

    http://linuxconfig.org/automatically-mount-usb-external-drive-with-autofs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question may sound a bit naive or stupid, but i was wondering...will POST
I apologise for what I'm pretty sure is a fairly stupid question, but I
I apologise if this question has already been asked. I'm really new to Python
I'm new to Python so apologies in advance if this is a stupid question.
I apologize for the stupid question, but I feel like I've really struck a
Apologies if this is a stupid question, I'm relatively new to Matlab. I've got
Before I ask this question I would to apologise because of the fact that
This is probably a very simple question, I apologise - I'm new to rails.
I'm currently coding a product which will have only one database but will host
Apologies for the massively stupid question but I am curious how to get this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.