If you’ve shied away from Linux because of the hassle of working with removable media, you may want to take another look. Thanks to automation — and with the help of these tips — you may find that removable media is downright user friendly.

For many new Linux users, removable media can be a deal-breaker. Anyone coming over from Windows knows you simply insert the CD, use it, and eject it. With Linux, it isn’t always that simple. In fact, with Linux, removable media has always held a completely different philosophy.

In the old days of UNIX, removable media was seen in the same light as the PC itself — multi-user. So when you inserted some form of media (usually a floppy disk, back then), it had to be mounted to a mount point (such as /mnt/floppy) and was then made available to all users on the system. Because of this, the removable media synchronization wasn’t “on demand.” It typically worked by caching the data until the media was unmounted. Upon unmounting the media, the data was written and the media could be removed.

Linux has caught up to the needs of today’s user and, in many cases, the media mounting/unmounting is automatic. But not every situation is the same. Here are some tips that should make your Linux life with removable media better.

Note: This information is also available as a PDF download.

#1: Use the right desktop

The right desktop can make your job so much easier. The newest releases of both KDE and GNOME offer systems that check for the insertion of removable media. When a CD is inserted, you will be greeted with a window asking what you would like to do with the media. You can even set that action you choose as the default action to take upon insertion of that type of media. Those desktops also have applets that reside in the panel (or desktop icons) that allow you to easily mount and unmount the media with a click of the mouse. No more entering commands like mount /dev/cdrom /media/cdrom.

#2: Get to know /etc/fstab

Because I generally stick with more old-school desktops (such as Enlightenment DR16), I often still have to mount my removable media. So instead of having to issue the full command mount /dev/sda1 /media/mp3 to mount my MP3 player, I will add a line to my /etc/fstab file that will do two things: Point the device to the correct mount point and make sure the mount point is both readable and writable by the user. The fstab entry will look something like this:

/dev/sda1 /media/ipod vfat users,exec,noauto,managed 0 0

Now when you need to mount the device, enter mount /media/ipod. Just remember to unmount the device before you remove it.

#3: Use udev to make your life easier

Let’s build upon using fstab to simplify mount of removable media. Let’s say you have an entry in your /etc/fstab file for your iPod pointing it from /dev/sda1 to /media/ipod. Now let’s say you plug in another USB device or reboot. The problem is that entry in your fstab file may or may not be valid now because /dev/sda1 might be used by something else. To avoid this, make use of the udev system. You’re going to tell udev to always make sure that device shows up with the same filename. Enter a line in the /etc/udev/rules.d/00.rules file that looks like:

## iPod

BUS=”scsi”, SYSFS{model}=”iPod*”, NAME=”ipod”

Of course, your entry in /etc/fstab will have to change to reflect the above. So now /etc/fstab will look like:

/dev/ipod /media/ipod vfat users,exec,noauto,managed 0 0

#4: Use menu entries for mount/umount

Back in the day, when I used AfterStep, I always had a submenu that included an entry for mounting and unmounting both the floppy and the CD-ROM. This made life much easier because I no longer had to open up a command line and enter the mount and umount commands to use the device. Granted, the window manager you use will determine how this is employed. For example, in Enlightenment, I can create two entries in the user_apps.menu file that look like:

“mount iPod” NULL exec “mount /media/ipod”

“umount iPod” NULL exec “umount /media/ipod”

Now on the Enlightenment menu, I will see two entries: mount iPod and umount iPod. With the device connected all I have to do is click the mount entry. To remove the device I only need to click the umount entry.

#5: Be safe with your removable hard drives

One time, I left a USB drive plugged into a machine I was re-installing the operating system on. I wasn’t paying enough attention and wound up with an operating system spanning both my internal drive and my removable drive. Yes, this was a big mistake and no, it has never happened since. Why? Because anytime I install an OS on a machine with a removable drive, that removable drive is removed during installation. It’s not a problem, because upon first boot, I plug the drive back in and it is always automatically recognized and mounted. Of course, I will make an entry in /etc/fstab that will automatically mount the drive on boot.

#6: Never forget to use the dmesg command

When you plug in a device or insert removable media, the dmesg command will give you the status of the system. For example, when I insert an iPod into a Mandriva 2008 machine I run the dmesg command and see:

usb 1-4: new high speed USB device using ehci_hcd and address 2

usb 1-4: configuration #1 chosen from 3 choices

usb 1-4: USB disconnect, address 2

usb 1-4: new high speed USB device using ehci_hcd and address 3

usb 1-4: configuration #1 chosen from 2 choices

Initializing USB Mass Storage driver…

scsi2 : SCSI emulation for USB Mass Storage devices

usbcore: registered new interface driver usb-storage

USB Mass Storage support registered.

usb-storage: device found at 3

usb-storage: waiting for device to settle before scanning

scsi 2:0:0:0: Direct-Access     Apple    iPod             1.62 PQ: 0 ANSI: 0

sd 2:0:0:0: [sdb] 58605120 512-byte hardware sectors (30006 MB)

sd 2:0:0:0: [sdb] Write Protect is off

sd 2:0:0:0: [sdb] Mode Sense: 68 00 00 08

sd 2:0:0:0: [sdb] Assuming drive cache: write through

sd 2:0:0:0: [sdb] 58605120 512-byte hardware sectors (30006 MB)

sd 2:0:0:0: [sdb] Write Protect is off

sd 2:0:0:0: [sdb] Mode Sense: 68 00 00 08

sd 2:0:0:0: [sdb] Assuming drive cache: write through

sdb: sdb1 sdb2

sd 2:0:0:0: [sdb] Attached SCSI removable disk

sd 2:0:0:0: Attached scsi generic sg1 type 0

usb-storage: device scan complete

From this, I know the device is being seen at /dev/sdb. Without knowing this, I would have a hard time guessing where the device has been mapped to.

#7: Don’t forget the eject command

Most people don’t know that there’s a command to eject CDs from the CD drive. Naturally, this isn’t an issue for those who have tray CD drives. But for those with slot-loading CD drives, eject will save you from pulling your hair out. After you have used and unmounted your CD drive, open up a terminal and enter the eject command, and your CD will pop out. To simplify the process, make a menu entry for the command.

#8: Remember that the mount command tells all

If you’re unsure what devices are mounted on your system, issue the mount command to see a listing of everything currently mounted on your machine. The output looks like:

/dev/sda1 on / type ext3 (rw)

none on /proc type proc (rw)

/dev/sda6 on /home type ext3 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /sys/fs/fuse/connections type fusectl (rw)

From this output, I can see that I have no removable media mounted on the machine. So I know it’s safe to unplug anything removable. Had there been an entry for, say, my iPod, I would know not to remove the device without unmounting it. Of course, on modern systems (using one of the major desktops), this will be made clear with the icon or the removable device applet on the panel. But this command will be helpful (along with dmesg) in debugging removable media issues.

#9: Reformat your iPod to a Windows format

If you’ve tried to add songs on a Mac-formatted iPod on Linux, you’ve probably discovered that it’s not possible without jumping through hoops even programmers don’t want to jump through. Format your iPod in Windows format, and you won’t have any problems using your iPod with Amarok, Banshee, or gtkpod.

#10: Allow others to connect to your removable media

In my office, I have a removable drive mounted to /media/music that contains my entire music collection. I allow others to listen to that music via samba by including it as a share. I like doing this far better than allowing users to have access to my internal drive because 1) it keeps anyone from trashing the drive containing my OS and 2) it allows me to keep sensitive data physically separated from shared data. This approach doesn’t have to be used for music, either. It’s a great way to share interoffice files or have a single repository for backups. Once the drive is full, remove it and store it. Just add a new removable drive for the new backup.

Simpler, easier

Not only is today’s Linux not nearly as challenged with removable media as it once was, it’s really quite flexible and user friendly. With the help of these tips, you should now see how you can expand your Linux experience to include various ways to employ removable media.

More Linux resources

TechRepublic’s Linux and Open Source newsletter, delivered on Tuesday, offers tips, news, and downloads to help you hone your Linux skills. Automatically sign up today!