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 would like to auto-mount a flash drive I have called "flash". Infact I have 2 drives with the same name. Both FAT.

I would like ideally which ever one is connected when the system boots to be mounted. Is this possible? Or does auto mount work on an identifier beyond the name?

share|improve this question
    
Have you considered renaming the FAT partition on one of the drives? it can be done easily using gparted –  GM-Script-Writer-62850 Jul 30 '13 at 10:58
    
So renaming the fat partitions the same thing? –  NickP Jul 30 '13 at 11:07
1  
The label ('flash' in your case) shouldn't affect the auto-mounting. Ubuntu will mount the drives in separate locations and use these locations to identify them. I labeled a USB Drive and a SD Card with the same names and connected them both at the same time. One is mounted at /dev/sdb and the other is at /dev/sdc. These are the identifiers that will be used by the operating system rather than the label. –  Merri Jul 30 '13 at 11:40
1  
+1 @Merri - If you plug both flash drives in, Ubuntu will create two folders in /mnt on which the devices will be mounted: one called "flash" and the other named "flash_". –  searchfgold6789 Jul 30 '13 at 15:21
1  
@searchfgold6789 not in /mnt but in /media... smells like a server guy here :P –  Braiam Jul 31 '13 at 1:56
show 4 more comments

4 Answers

up vote 3 down vote accepted
+50

You can edit your /etc/fstab and add the following line to do this easily. But you may understand the risks of doing so.

LABEL=flash /media/where_will_be_mounted vfat defaults 0 0

Ok, lets boil down each option:

  • LABEL=flash: tells the system to mount any driver with the label flash
  • /media/where_will_be_mounted: Self-explanatory, you should already have the path created before mounting.
  • vfat: you said the filesystem will be FAT always, if it's not FAT it will fail.
  • defaults: This set up the driver with the default mount options for the filesystem, equivalent to rw,suid,dev,exec,auto,nouser,async. The important part here is the auto, that tells the system to mount automatically the filesystem when mount -a is issued, like it does at boot.
  • 0: They are dump and fscheck options, you most likely won't want this.
share|improve this answer
    
just a quick question, will vfat work for fat32? –  NickP Aug 6 '13 at 10:54
    
Any FAT partition is mounted using vfat so, yeah. –  Braiam Aug 6 '13 at 11:40
add comment

If you know the flash drive will always be in the computer when it is booted, you can add it to your /etc/fstab (the file which controls mounting) by the UUID of the device, which should be different between the two flash drives.

share|improve this answer
add comment

Connect both drives, open a terminal (maximize it) and run

sudo blkid -olist

Take note of the UUID of your flash drives. Now write a script:

#!/bin/sh

first_uuid=<first-drive-uuid>
second_uuid=<second-drive-uuid>

udisks --mount /dev/disk/by-uuid/$first_uuid
udisks --mount /dev/disk/by-uuid/$second_uuid

(Substitute <first-drive-uuid> and <second-drive-uuid> with the UUID's of the drives.)

Make the script executable, and add it to Startup Applications or to some initialization script.

share|improve this answer
add comment

Create two directories flash1 flash2 wherever you want to mount the drive (e.g. ~/flash1)

Perform the following steps for each drive

  1. Insert flash drive and determine the device name (e.g. /dev/sdb1)
  2. run the command sudo blkid /dev/sdb1
  3. Write down or copy the UUID somewhere.
  4. sudo nano /etc/fstab
  5. add the line: UUID=<uuidfordevice> ~/flash1 vfat defaults 0 0

And Repeat with the other drive.

You might be able to just use one mount directory (flash) if you only ever have one in at a time, but I would have separate directories for each drive.

share|improve this answer
add comment

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.