Steps to manually mount a USB flash drive in GNU/Linux

March 17, 2007
I recently got hold of a 1 GB USB memory stick. It is a Kingmax 1 GB flash drive (U201G - U2GMHDWG) which is (believe it or not), half the size of my little finger. In fact, it is so small that there is a good chance I might misplace it somewhere if it was not tethered to a chain. Anyway, the USB stick has a FAT partition on it and contain some data which I wanted to access in GNU/Linux. I was using Ubuntu and it straight away detected the device as soon as I inserted it and it was automatically mounted in the /media/USB DISK location.

Kingmax 1 GB USB flash driveFig: The tiny 1 GB USB flash drive from Kingmax

But when I tried to mount it in a bare bones Linux distribution (a distribution which has just enough software as is needed), it was not mounted automatically. This is because the auto mounting takes place by means of a program known as hotplug which detects the USB device that is inserted in real time and then mounts it in the desired location.

So is it possible to mount a USB device (in my case the USB stick) manually ? Yes, it is possible. The idea is that the USB ports are detected by GNU/Linux as /dev/sdax - where 'x' in sdax stands for the number of the USB port. And once the USB device is connected to the USB port of your machine, you have to mount it manually.

These are the steps I followed to successfully mount the USB memory stick on my bare bones Debian Etch machine.
  1. Insert the USB stick into the USB port. My machine has 4 USB ports, 3 in the back and one at front. It doesn't matter which port you insert the device. The first USB port you use will be assigned the name /dev/sda1, the next port /dev/sda2 and so on.
  2. Check if the USB device is detected by GNU/Linux by running the following command:
    # lsusb
    Bus 002 Device 007: ID 0457:0151 Silicon Integrated Systems Corp. Super Flash 1GB Flash Drive
    Bus 002 Device 002: ID 8086:1120 Intel Corp.
    Bus 002 Device 001: ID 0000:0000
    Bus 001 Device 001: ID 0000:0000
    The first line in the output of the above command shows that the memory stick has been detected as Super Flash 1 GB Flash drive.
  3. Mount the device in the desired location. I chose to mount it in the /mnt/usbstick directory.
    # mount -t vfat -o rw,nosuid,nodev,quiet,shortname=mixed,uid=1001,gid=100,umask=077,iocharset=utf8 /dev/sda1 /mnt/usbstick
As an aside, you can do away with a lot of mount options such as nosuid, nodev and so on. The uid is necessary and is my user id number which allows me to access the device without being logged in as root. And if you are not sure of the partition on your usb stick, you can also use auto instead of vfat.

Update (19th March 2007): I forgot to mention one thing. The 'lsusb' command is used to find out if your USB device has indeed been detected by GNU/Linux kernel. If it is not detected by any chance because of non-availability of Linux drivers for your device, the command will not output the specific information. Once you are sure that the device has been detected, you can use the fdisk command to list the device(s) as follows :
# fdisk -l
which will list all the devices including the USB devices detected by GNU/Linux. Then you can use the mount command to mount it at a specific location.

9 comments:

  • When a usb drive is detected by the system a new device node is created of the form: /dev/sd<letter> as well as one node of the form /dev/sd<letter><number> for each partition on the device. There is no guarantees on which letter is assigned to the device, however; this letter will be consistent across all nodes associated with a given device. For example, when I plug in my iPod, we get the following messages in the syslog :

    aaron@athena:/dev$ tail -n 0 -f /var/log/syslog
    Mar 18 08:55:34 athena kernel: [17491581.168000] usb 2-8: new high speed USB device using ehci_hcd and address 6
    Mar 18 08:55:34 athena kernel: [17491581.304000] usb 2-8: configuration #1 chosen from 2 choices
    Mar 18 08:55:34 athena kernel: [17491581.304000] scsi7 : SCSI emulation for USB Mass Storage devices
    Mar 18 08:55:34 athena kernel: [17491581.304000] usb-storage: device found at 6
    Mar 18 08:55:34 athena kernel: [17491581.304000] usb-storage: waiting for device to settle before scanning
    Mar 18 08:55:39 athena kernel: [17491586.304000] usb-storage: device scan complete
    Mar 18 08:55:40 athena kernel: [17491586.308000] Vendor: Apple Model: iPod Rev: 1.62
    Mar 18 08:55:40 athena kernel: [17491586.308000] Type: Direct-Access ANSI SCSI revision: 00
    Mar 18 08:55:40 athena kernel: [17491586.308000] SCSI device sdd: 58605119 512-byte hdwr sectors (30006 MB)
    Mar 18 08:55:40 athena kernel: [17491586.312000] sdd: Write Protect is off
    Mar 18 08:55:40 athena kernel: [17491586.312000] sdd: Mode Sense: 6c 00 00 08
    Mar 18 08:55:40 athena kernel: [17491586.312000] sdd: assuming drive cache: write through
    Mar 18 08:55:40 athena kernel: [17491586.316000] SCSI device sdd: 58605119 512-byte hdwr sectors (30006 MB)
    Mar 18 08:55:40 athena kernel: [17491586.320000] sdd: Write Protect is off
    Mar 18 08:55:40 athena kernel: [17491586.320000] sdd: Mode Sense: 6c 00 00 08
    Mar 18 08:55:40 athena kernel: [17491586.320000] sdd: assuming drive cache: write through
    Mar 18 08:55:40 athena kernel: [17491586.320000] sdd: sdd1 sdd2
    Mar 18 08:55:40 athena kernel: [17491586.344000] sd 7:0:0:0: Attached scsi removable disk sdd
    Mar 18 08:55:40 athena kernel: [17491586.344000] sd 7:0:0:0: Attached scsi generic sg3 type 0
    Mar 18 08:55:40 athena kernel: [17491586.528000] printk: 28 messages suppressed.

    We can see that the iPod was assigned the identifier sdd, by looking in /dev:

    aaron@athena:/dev$ ls /dev/ | grep sdd
    sdd
    sdd1
    sdd2

    We can see that three new device nodes have been created: /dev/sdd, /dev/sdd1 and /dev/sdd2. /dev/sdd represents the device itself whereas /dev/sdd2 represents the second partition on my iPod.

    Finally, auto mounting is not handled by hotplug rather the Gnome Volume Manager (or the KDE/Xfce/etc. equivalent). Hotplug is a very low level service which emits events when hotpluggable devices (such as usb and SCSI drives) are attached/detached to/from the system. Notably these events are used by udev to create/destroy device nodes to make newly attached devices accessible in userspace.

    In summary, the names assigned to your usb drive has nothing to do with which port you plug it into and everything to do with the state of the system when it is detected. Numbered device nodes represent partitions whereas non-numbered device nodes represent the devices themselves. Automounting is handled by the window manager.

  • Danny

    sweet guide!!

    I have a simple guide to expanding initrd file stored on a USB drive used for booting my SLES10.

    http://thedaneshproject.com/linux/inspecting-the-contents-of-an-initrd-file/#more-66

  • If I recall correctly, the sda devices are for SCSI devices. If you also have other SCSI devices in your computer, how do you relate the output of lsusb to the appropriate sdaX device so that you mount the appropriate device?

  • Dave

    This is completely wrong. /dev/sda1 might be one of your hard disk partitions if you have SCSI or SATA drives, and if your key is not partitioned, it might be /dev/sda instead of /dev/sda1. Depending on your distribution, you could end up with garbage, or corruption your root partition, or both.

  • Excellent article. I have a 2 GB USB key drive and your steps worked like a charm on my machine.

    To those who say the device will be detected differently than /dev/sda, it happens only if you have another SCSI device, which is a rarity in a desktop pc.

  • To those who say the device will be detected differently than /dev/sda, it happens only if you have another SCSI device, which is a rarity in a desktop pc.

    SATA drives are becoming more common place in desktop computers, and are detected in linux as a /dev/sdx, just like a SCSI device.

    Since a lot of OEM and home built computers are featuring SATA drives, I don't consider this a rarity anymore.

  • Guy_Sweden

    hello.
    I guess it would be a great idea to use mount without any arguments.rets the number of mounted devices.

  • Hi
    And what about mounting mobile phone with internal memory (such as SE Z550i) via Usb-cable to Linux box?
    Not a flash card,but internal.
    How can one did this?

  • Thanks for the excellent post. I've been messing around with the fstab file so much I was going nuts. Turns out the uid/gid values saved me.

    Thanks again