Find the answer to your Linux question:
Results 1 to 5 of 5
Okay, I'm new here and am very foggy on the protocol so please don't get out the guillotine yet. Could anyone point me in the right direction towards documentation on ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2005
    Posts
    3

    Auto-mount a USB and then some!


    Okay, I'm new here and am very foggy on the protocol so please don't get out the guillotine yet. Could anyone point me in the right direction towards documentation on how to auto-mount a usb flash drive (if it's even possible). I plan to try and write code that will send a file to it when it is detected (suggestions welcome here also). Thanks in advance!

  2. #2
    Just Joined!
    Join Date
    Nov 2004
    Posts
    45
    It is possible. I can remember my USB CD-RW Drive bring automatically recognized before it shorted out! In fact, I can show you how to hide the mount points! But first, you need to know that Linux has a file which shows it how the root or boot or whatever should be handled. For mounting (using a disk or something), a file called /etc/fstab is very important to the software in that it tells Linux how to set up the various filesystems for use on the computer. Here is what you need to do:

    First, know what device file is being used. Knowing this is important because Linux needs this as the first thing in the fstab file. Second, find a place on your drive that you feel you can use, but also know that youm are creating something called a 'mount point', or where you want to use the USB drive. Once everything is figured out, get ready to edit the /etc/fstab file. I want to caution you in editing this, because if you make a mistake, Linux may not use the device in how you want it to be used. Now: Third: Open an editor like Emacs or vi, and open the /etc/fstab file. Go to the very end of the file (if oyu have to, start a new line), and type the following:

    Code:
    /dev/???     /mount_point     fs_type options 0 0
    (the ??? means whatever Linux says it is, mount_point is wherever you want to use it, fs_type is like what way the disk understands files (fat, vfat, etc), options is like read-only or read-write or whatever). The two numbers I am not clear on, but read up on the fstab file to be sure you have it ready for whatever you want to do with the drive. Once you have edited and saved the file, shut down the computer and turn it on. The computer should see the new line, and if the device is plugged in, should mount it. I want to caution you here as well: The computer may try to mount automatically a device which is not plugged in, so be careful.

    To hide the mount points, edit both the /etc/fstab and the /etc/mtab to reflect changes in the names of /mount_point, by placing a dot in front of /mount_point, to show /.mount_point (the '.' hides the files from a regular view of the files). Remember that the mount_point names MUST be changed to reflect what is in the /etc/fstab and /etc/mtab files. In opther words, rename the mount_point places to have a dot to hide them.

  3. #3
    Just Joined!
    Join Date
    Oct 2005
    Posts
    3
    Is there a message received upon mount, i.e., such that I can write a program to react upon the drive being connected?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Nov 2004
    Posts
    45
    I am now running Slackware, but from what I understand, no message that is shown will tell you.

    The mount command does release a code to the computer which in turn lets it know if there is anything the matter. I am unclear as to how to make mount show the code in public view, but I do know from experience that when I mount a device on the computer that, if it is successful, displays no specific messages, BUT it tells the computer the error code 0 (zero), meaning that it was successful, and there were no errors.

    Here is a suggestion that may work. It is 'off the cuff' code, but if it helps, here it is:
    Code:
    # First, mount the device, and put the information in a file
    
    mount /dev/sda /mnt/usbpoint 2> usbMountErrors
    # That is, if the system uses usbpoint in the folders
    # And, the 2> tells the computer to put the errors in a file to be created
    # Now, let's see if there ARE any errors
    if grep '0' usbMountErrors != '0';
    # Oops! There is an error!
    echo 'There was a problem mounting, please see the error file'
    else
    echo 'No problems.   Going on...'
    # Now, to request the drive to send the files to
    ...
    I hope this helps. I strongly suggest you use your computer's man pages and info pages to study programming.

  6. #5
    Just Joined!
    Join Date
    Oct 2005
    Posts
    3
    I think that should help. Thanks!

Posting Permissions

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