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. 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.

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.

Windows-Linux Interoperability

You want to be able to read and write files greater than 2GB from Windows and Linux? Then use NTFS.

See also

External Links