How are USB flash drives designated
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2015
    Location
    NW-USA
    Posts
    130

    How are USB flash drives designated

    Hi, just finished a simple bash script (well almost finished) to copy my user files to either cd/dvd or memory stick. Then I realized I was having a carryover from M$ cuz I had used their device designation of C:, E: , etc. So I ran df and lsusb to see my flash drives. This created a problem as I had 2 flash drives in the hub and the Fedora 22 which I had installed on another. Now I see /xxxxx/yyyy for some usb drives but even after switching them in/out could not determine which was which. What is the obvious way to determine the designation for those drives so I can incorporate it into my bash script? I think it should be something like /sbd2/xxx. Thanks

  2. #2
    Join Date
    Dec 2013
    Location
    United Kingdom
    Posts
    6,699

    Re: How are USB flash drives designated

    It's usually the next letter up from your HDD as follows and entirely dependent in the order you plug the USB drive in. They don't get fixed drive letters.

    e.g.

    sda=HDD
    sdb=1st thumb drive or external HDD plugged in
    sdc=2nd plugged in storage media
    sdc=3rd
    and so on.

    The device partitions if any are given numbers which follow the letters, e.g. sdb1, sdb2 etc.

  3. #3
    Join Date
    May 2012
    Location
    NC
    Posts
    2,277

    Re: How are USB flash drives designated

    Yes, the designations are not permanent. If you have more than one device attached and remove one or add another, the designation may (will?)change.

    I don't know how you could determine the designations in a script at run time, but I'm not the one to ask that. However, the devices do need to be mounted, so getting a list of all mounted devices and parsing out the USB devices might be an approach.

    "lsblk" displays info about all current block devices, so it will list the currently attached USB devices (e.g., /dev/sdd, etc.) and also their mount points (e.g., /run/media.....), if they're mounted.

  4. #4
    Join Date
    Nov 2007
    Location
    Malaysia
    Age
    42
    Posts
    58

    Re: How are USB flash drives designated

    Try mounting your device via its UUID. Run blkid and you should see something like:
    Code:
    /dev/sdb1: LABEL="ADATA UFD" UUID="6DA7-4765" TYPE="vfat" PARTUUID="000c4034-01"
    Take note of the UUID="xxxxx" part and use that in your script(s). Mount your device like:
    Code:
    mount -U 6DA7-4765 /mnt
    The UUID of your device will not change unless you reformat it.

  5. #5
    Join Date
    Jun 2015
    Location
    NW-USA
    Posts
    130

    Re: How are USB flash drives designated

    That was a great lift for my recall from U all thanks.
    Still have a small problem
    If I extract the mount point from df -H for a particular pen drive
    How do I associate it with a directory on that drive? I checked mount but since the pen drive is automatically mounted by the system do I use:
    /home/<just-me-the-uer>/F9089...0923489/
    and them do mkdir? Thanks again.

  6. #6
    Join Date
    Oct 2005
    Location
    British Columbia, Canada
    Posts
    873

    Re: How are USB flash drives designated

    Quote Originally Posted by fed84
    That was a great lift for my recall from U all thanks.
    Still have a small problem
    If I extract the mount point from df -H for a particular pen drive
    How do I associate it with a directory on that drive? I checked mount but since the pen drive is automatically mounted by the system do I use:
    /home/<just-me-the-uer>/F9089...0923489/
    and them do mkdir? Thanks again.
    Hi fed84
    Your USB (pen drives) will always be mounted, alluded to in another post, are mounted at
    Code:
    /run/media/<username>/name-of-pen-drive
    (note replace with your <username>) If you give them names such as
    Code:
    Pen1
    or whatever they will consistently be so named in the auto mounts. Hence Pen1 will be mounted at
    Code:
    /run/media/username/
    as subdirectory Pen1. Hence your information will be at
    Code:
    /run/media/username/Pen1/
    Robert :)

  7. #7
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,875

    Re: How are USB flash drives designated

    Almost all USB pendrives come pre-formatted with vfat (usually 16 bit for compatibility) and have a single partition. They may or may not have been given a "Label". I cannot speak for other DE's other than Xfce which I use.

    I add a msdos Label to all of my vfat formatted USB thumb drives. Easily done with the fatlabel command (a.k.a. dosfslabel). When plugged in, Xfce adds an icon to the desktop to show it's presence, but does not automatically mount that device. A right click on the icon and choosing "mount volume" will do that. The Icon for the device displays the Label name in the text field.

    Mounting the device, as regular user, will always have the same mount point. Example:

    /run/media/$USER/LABEL_NAME_OF_THE_DEVICE

    e.g. /run/media/paul/JF-V10-1GB
    Code:
    $ ls -d /run/media/$USER/JF-V10-1GB
    /run/media/paul/JF-V10-1GB
    No need to wrestle with the actual /dev/sdxx. It's always the same. Same works for any fs type that has been given a Label. I gives labels to all my partitions, fixed and removable.
    Code:
    $ ll /dev/disk/by-label
    total 0
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 boot -> ../../sda9
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 home -> ../../sda8
    lrwxrwxrwx. 1 root root 10 Sep 27 20:01 JF-V10-1GB -> ../../sdb1
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 RECOVERY -> ../../sda5
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 root -> ../../sda7
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 swap -> ../../sda6
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 W8 -> ../../sda4
    lrwxrwxrwx. 1 root root 10 Sep 27 18:25 WINRE -> ../../sda1
    This consistency makes using a removable device in a script easy and simple. I would assume, but do not know for sure, that other DE's treat mounting by label-name in the same as Xfce does. If you choose to give a vfat partition a label with the fatlabel command, insure the device is not mounted at the time you do so.
    How do I associate it with a directory on that drive? I checked mount but since the pen drive is automatically mounted by the system do I use:
    /home/<just-me-the-uer>/F9089...0923489/
    I don't understand this question at all. Directory names are just that, directory names, just like anywhere else. Besides just regular files, I have two directories in the top level of the above USB stick I'm using as an example, Backup and BIN. You access them as you would any directory path.
    Code:
    /run/media/paul/JF-V10-1GB/Backup
    /run/media/paul/JF-V10-1GB/BIN

  8. #8
    Join Date
    Jun 2015
    Location
    NW-USA
    Posts
    130

    Re: How are USB flash drives designated

    I have yet to test this but from what I have read the df -H command will show the mount point as I gave in my last post. That can also be show with lsblk (apparently preferred to blkid which requires root privs) and mount (if U can find it). I guess the way to go is to make a directory on the mount point with
    mkdir /whatevermountpoint/new_directory
    then I can refer to the new_directory as either /new_directory or /run/media/new_directory. I will give this a try.
    FWIW the reason my pen drive is shown as mounted is because apparently if it is connected at boot time it will get mounted automatically. Also if the flash drive is NOT formatted lsblk will show it only as sdd or sdc whatever. df -H will NOT show pen drives if they are unformatted.
    Last edited by fed84; 28th September 2015 at 01:54 PM.

  9. #9
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,875

    Re: How are USB flash drives designated

    df -H will NOT show pen drives if they are unformatted.
    Well, of course not. Look at the first line of the df man page.
    Code:
    NAME
           df - report file system disk space usage
    df deals with filesystems. If the storage device isn't even formatted, there is no filesystem on it yet, so there is nothing there for df to see.

Similar Threads

  1. Cheap Flash Drives
    By mwesten in forum Wibble
    Replies: 8
    Last Post: 30th September 2010, 08:53 PM
  2. How to setup designated sectors with raid
    By larryc06 in forum Using Fedora
    Replies: 0
    Last Post: 27th June 2009, 03:08 AM
  3. Directory for USB flash drives
    By jpfalet in forum Hardware & Laptops
    Replies: 1
    Last Post: 22nd May 2009, 02:31 AM

Tags for this Thread

Posting Permissions

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