Mounting USB storage devices and Windows partitions

245

Author: Rickford Grant

Nowadays, tiny portable storage devices that go by names such as PenDrive, JumpDrive, ClipDrive, DiskOnKey, and so on, have become quite popular. Because of their small size, these “flash drives” are very handy when you have to transfer fairly large, but not gigantic, amounts of data from computer to computer (from work to home, for example). They come in a variety of sizes from 16MB to 2GB and are becoming less and less expensive (especially in the 16MB to 256MB bracket).

This article is excerpted from the newly published book Linux for Non-Geeks.

Memory cards are also popular as portable storage devices; however, to read these cards, you use a card reader. Memory cards are most commonly used in digital cameras. As these memory cards come in a variety of formats, such as CompactFlash, Memory Stick, and SmartMedia, different types of card readers are available to read the different media formats.

As you may already know, USB devices, which are recognizable by their narrow rectangular connector plugs, have become increasing popular, largely because you can plug and unplug them while your computer is running (called hot plugging). While connecting universal serial bus (USB) storage devices to USB ports is about as simple as things can get, accessing those devices so that you can transfer data to and from them is still one of Fedora’s weaker areas, but once you go through the only slightly cumbersome one-time process of setting up your USB storage device, things will be as easy as can be.

Device compatibility

As you no doubt know by now, few devices specify Linux compatibility. There also seems to be little in the way of an online guide for Linux compatibility for USB storage devices, probably because many of these devices are manufactured, or at least distributed, by rather small (sometimes no-name) companies, of which there are too many to deal with.

It is pretty safe to say that if the device claims to work on both Mac and Windows, or if it works on recent Windows versions without the need for a special driver, it will probably work on Linux. Multireader card readers, which read a variety of card types, are more likely to give you headaches. Better, in my opinion, to stick with those specifically designed for one type of card.

If you are the worrying kind and you are not soothed by my words of encouragement, you can try one of the online Linux forums and ask for some recommendations, or if you have a particular model in mind, ask if anyone has experience with that particular device. And then there is the tried-and-true Google search, as I so often suggest for questions of hardware compatibility. Just type the make and model of the device in question along with the word “Linux” and see what happens.

Locating your device

Before you go about setting up your system to deal with a new USB storage device, it is useful to know how it is actually being handled by Linux. The mass storage driver in Linux deals with all USB storage devices as if they were SCSI (Small Computer System Interface) drives. SCSI devices were once the most popular type of peripherals out there, but they have largely been supplanted by the cheaper and easier-to-deal-with USB devices. This means that such devices, whether real SCSI or USB, will be listed in your Hardware Browser as SCSI drives under the /dev listings: /sda, /sdb, /sdc, and so on, depending on how many of these devices you have. As you might have guessed, these listings (sda, sdb, sdc, and so on) stand for SCSI device a, b, c, and so on.

To see what I am talking about, plug your USB storage device into a USB port on your computer; you don’t need to shut down your machine before doing this. Once you’ve done that, you need to find out where the device actually is, according to the computer. Of course, you know it is stuck into one of your USB ports, but your system has a reality all its own.

The easiest graphical way to find the USB device is to use your Hardware Browser. Just go to the Main menu and select System Tools > Hardware Browser. You will be asked for your root password, so type it when prompted and click OK. A window will then pop up telling you that it might take some time to check your hardware configuration; but before you finish reading it, the Hardware Browser window will open, and the message window will vanish. On the left side of the Hardware Browser you will see a number of headings. Click the one that says Hard Drives (not the one that says USB devices).

If your USB storage device is hardware-compatible with Linux, it will most likely appear in the list as /dev/sda1, assuming it is the only device of that type you are dealing with. If you are working with a second or third device, it might appear as sdb1, or sdc1, and so on.

Setting things up: Editing the fstab file

As things are right now, your system recognizes your USB storage device, but you still really can’t use it, at least not easily. In order to set things up so that you can use your storage device anytime you want with just a couple of mouse clicks, you need to create an entry for the device in your fstab file.

Now I must admit that the first time I heard about this fstab file, and that I was going to alter it in some way, I sort of got the willies. Just the name of the file seemed creepy enough: f+stab. I thought the name was one of those off-the-wall Linux acronyms for something dark and dreary. I was relieved (or maybe disappointed) to find out that fstab merely stood for File System Table. By modifying the fstab file, you are simply adding an item to a table.

To get at your fstab file, click the Terminal launcher in your GNOME Panel. Once you’ve done that, become root by using the su command, and then type gedit /etc/fstab and press Enter. In case you’re wondering, the first part of that command opens the text editor program Gedit, while the second half tells Gedit to open the fstab file located in the etc folder.

Now you can add an entry for your new USB storage device by using the device location listed in the Hardware Browser. What you need to do is go to the bottom of the list and add something like the following: /dev/sda1 /mnt/pendrive auto defaults,users,noauto 0 0

Now to explain what this all means, let’s go through it bit by bit.

  • The first element, /dev/sda1 (or /dev/sdb1, and so on), is where the system says your device is located. This is the bit of information that you got from the Hardware Browser. The 1 in sda1 points to the first (usually only) partition on that device.
  • The second element, /mnt/pendrive, is the mountpoint for the drive. This mountpoint doesn’t exist yet, but you will be creating it in the next section. The part of this element that comes after /mnt/ can be anything you like. If, for example, you are setting up a card reader instead of a PenDrive, you could call it /mnt/cardreader.
  • The third element is the file system for the device. To keep things simple, you will be using auto, which should be self-explanatory in this case.
  • The next three elements, which are strung together without spaces (only separated by commas), are the other settings for the device: defaults tells the system to handle this device in its usual way, users gives all users of the machine permission to use it, and noauto tells your system not to mount the device automatically on startup, as it is a removable device that might not be there when you start up. Make sure you don’t type any spaces around the commas in this part of the entry.
  • The last part, the two zeros, is a bit complicated, so just trust me on this one. Make sure that you have just one space between the two zeros.
  • You don’t need to worry too much about lining up your new entry with the ones before it. However, if you space things out, be sure to avoid using your Tab key to make the spaces, as it causes problems in some text editors. Once you done, click the Save button in Gedit and then quit the program.

    Now that your fstab has been edited, it is time to create the mountpoint that you listed in your fstab entry. Go back to your Terminal window, which should still be in root mode, type in mkdir /mnt/pendrive (or replace pendrive with whatever name you gave your storage device in the fstab file) and press Enter.

    Mounting your USB storage device

    It should now be very easy to use your new USB storage device. Plug in the device if it isn’t already plugged in and right-click your desktop. In the pop-up menu, select Disks > pendrive, and an icon for your new drive will appear on the desktop (in Red Hat Linux 9 you may have to restart your machine before your new storage device name appears in the pop-up menu). After that, you can use it like any other storage device by double-clicking it to open a Nautilus window. You can then drag files to and from the device as if it were a hard disk or floppy.

    Fedora users should note that dragging a file from your USB storage device to your desktop will move the file, rather than copy it; therefore, once you’ve completed the drag-and-drop procedure, the file will be located on your hard disk and be erased from your USB device. On the other hand, dragging a file from your USB device directly to your Home folder or any other location therein will result in the file being copied rather than moved — it will be present on both the hard drive and the storage device after the drag and drop is complete. In the case of Red Hat Linux 9, all drag-and-drop procedures are treated as copies rather than moves.

    Unmounting your USB storage device

    Once you are done using your USB storage device, you have to unmount it before you can unplug it from the USB port. If you do not do this, none of the files you dragged to the device will be saved there, which could be confusing. To unmount the USB device, right-click the desktop icon for the device and then select Unmount Volume in the pop-up menu. The icon will disappear and you can unplug the device if you like, though you do not have to. Make sure to close any open Nautilus windows for the drive before trying to unmount it, or the system won’t allow you to do so.

    Sometimes, as when unmounting floppies, your system will jump the gun a bit and tell you that it cannot unmount the drive, when in fact it is busy in the background doing just that. If you get such a no-can-do message, but the drive icon disappears anyway, you can ignore the system warning. Once the icon is gone, the drive is unmounted.

    Adding additional USB storage devices

    You can add additional storage devices in the same way that you added the first one:

    1. Use the Hardware Browser to check the device location.

    2. Add a new entry to the fstab file.

    3. Create a new mountpoint.

    4. Restart your machine.

    5. Mount the drive by right-clicking the desktop, and select Disks > newdrivename from the pop-up menu.

    Next — Mounting Windows partitions or drives

    If you are a dual booter, meaning that you have both Windows and Linux installed on your hard disk, you may want to transfer files back and forth between your Windows and Linux partitions or disks. This is useful, for example, if you want to copy some of your Windows fonts to your Linux system. To do this, you have to mount your Windows partition or drive. The process of setting up your system so that you can easily mount your Windows partition or drive is essentially the same as the one you learned for mounting USB drives.

    Locating your Windows partition or drive

    Just as with USB storage devices, the first thing you have to do is locate your Windows drive or partition with the Hardware Browser. Go to your Main menu and select System Tools > Hardware Browser, and then type your root password when requested to do so. Once the Hardware Browser opens up, click Hard Drives in the left panel.

    Next, look for your Windows partition, which will most likely be hda1. Check under the Type column to see what the file system format is for the partition. If it is fat16 or fat32, you will have no problem. If, however, it is ntfs (which is the default file system for Windows NT, 2000, and XP) you are out of luck and will have to forgo this process, as Linux doesn’t let you, as of yet, mount NTFS partitions — and not without good reason. Linux kernel support for NTFS is still buggy, thus endangering the integrity of such partitions or drives. [Editor’s note: This is not strictly true — see the Linux-NTFS Project and Paragon NTFS for Linux.]

    If you have a FAT16 or FAT32 partition, jot down the information for that partition — for example, /dev/hda1 fat32. Once you’ve done that, you can go on to edit the fstab file.

    Open a Terminal window, become root, and then type gedit /etc/fstab and press Enter. When the fstab file opens in Gedit, add a new entry to the bottom of the list by typing:

    /dev/hda1 /mnt/windows vfat defaults,users,noauto 0 0

    Of course, if your device location is different, change the entry accordingly. You might also want to change noauto to auto. If you do this, a desktop icon for your Windows partition or drive will appear each time you log in, thus eliminating the mount step each time you start your machine. When all is as you want it, click the Save button, and quit Gedit.

    Now create the mountpoint that you listed in your fstab entry. Go back to your Terminal, which should still be in root mode, type mkdir /mnt/windows and press Enter.

    You can mount your Windows partition or drive in essentially the same manner as was described for USB storage devices. Right-click anywhere on your desktop, and then, in the pop-up menu, select Disks > windows. A desktop icon for your Windows partition or drive will then appear.

    Double-clicking your Windows partition desktop icon will open a Nautilus window. You can then drag files to and from the Windows partition. If you changed noauto to auto in your Windows partition fstab entry, you won’t have to do anything the next time you start up your machine, as your Windows partition will be mounted automatically on startup, and the Windows partition desktop icon will appear automatically.

    Unmounting your Windows partition or disk is done in the same manner as unmounting USB storage devices. Close any open Nautilus windows for the partition, and then right-click the desktop icon for the Windows partition or drive and select Unmount Volume from the pop-up menu.