View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > USB Flash drive

From LQWiki

Jump to: navigation, search

A USB Flash drive is a small device (about the size of your thumb) which contains flash memory, a USB plug, and some electronics to make it look like a removable hard disk to your computer. They fall into the category of USB mass storage devices. They usually have anywhere from 32 to 2048 MB of read-write memory on them. Once they're mounted (usually you'll need usb_storage and sd_mod modules loaded), you just treat them like any other disk drive. Often they come with a key ring so you can carry them around with your house keys.

These are also known under a number of other names, such as: "usb memory stick", "thumb drive", "pen drive", "DiskOnKey", "flashdisk", and "usbdrive".

Flash drives are extremely handy thanks to their small size, large memory, and reliability. A properly configured computer will even boot from one. A common use for a flash drive is as a persistent (and mobile) Knoppix home directory.

You usually find their device files on the filesystem under /dev/sda, unless you have any SCSI or other USB mass storage devices. Once you format one, its first partition is then /dev/sda1, just like with other drives. You can use fdisk to partition it (and mke2fs to format it if you're making it ext2). Some people just leave it with whatever MS Windows format (FAT) that came with it. There is also a filesystem specifically designed for flash memory called JFFS. For transferring files between Linux and Windows, it is common to use FAT 16 or FAT 32.

Be sure to unmount the flash drive before unplugging it.

Manual Configuration

When running a much older or barebones Linux distribution that doesn't autodetect a USB drive, manual configuration is needed to mount the USB drive's filesystem. Modern Linux distributions do detect USB drives when plugged in, although the feature is only fully enabled while inside of an XWindows session. Manually configuring a USB drive is needed when outside of an XWindows session and is essential for instances where a Linux distribution doesn't detect a USB drive while in XWindows.

To determine if the usb-storage module is compiled into the Linux system for troubleshooting purposes run:

# modprobe usb-storage

List the plugged-in USB devices and available USB buses by running lsusb.

# lsusb

Run dmesg to determine the kernel assigned /dev/sd? file name. The last few lines of dmesg will show the device file name after the drive is plugged into the system and detected by Linux.

An alternative method is to run cdrecord with appropriate parameters to list flash drives.

# cdrecord --scanbus

Mount the flash drive by using the mount command with the correct device file. Below is an example of a FAT filesystem on the first partition of the device file /dev/sda.

# mount -t vfat /dev/sda1 /mnt/usb

Always unmount the filesystem to flush written changes back to the flash drive before unplugging.

# umount /dev/sda1

Plugging in a flash drive can be simplified further by adding a fstab entry to allow users to manually mount and unmount USB drives on the fly. If multiple flash drives are needed, take advantage of the udev system to assign specific USB drives to user assigned device files. To help remember the device file name, notice that the SD in /dev/sd? is short for SCSI Device.

See also

External Links


Personal tools