Thursday, December 4, 2008

Minimize removable media headaches in Linux

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.


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.


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.


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


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.


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.


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.


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.


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.

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.


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.

20 comments:

逆円助 said...

さあ、今夏も新たな出会いを経験してみませんか?当サイトは円助交際の逆、つまり女性が男性を円助する『逆円助交際』を提供します。逆円交際を未経験の方でも気軽に遊べる大人のマッチングシステムです。年齢上限・容姿・経験一切問いません。男性の方は無料で登録して頂けます。貴方も新たな出会いを経験してみませんか

メル友募集 said...

最近仕事ばかりで毎日退屈してます。そろそろ恋人欲しいです☆もう夏だし海とか行きたいな♪ k.c.0720@docomo.ne.jp 連絡待ってるよ☆

家出 said...

最近TVや雑誌で紹介されている家出掲示板では、全国各地のネットカフェ等を泊り歩いている家出娘のメッセージが多数書き込みされています。彼女たちはお金がないので掲示板で知り合った男性の家にでもすぐに泊まりに行くようです。あなたも書き込みに返事を返してみませんか

動物占い said...

あなたの性格を、動物に例えて占っちゃいます。もしかしたらこんな動物かも!?動物占いをうまく使って、楽しい人間関係を築いてください

家出 said...

家出中の女性や泊まる所が無い女性達がネットカフェなどで、飲み放題のドリンクで空腹を満たす生活を送っています。当サイトはそんな女性達をサポートしたいという人たちと困っている女性たちの為のサイトです

セレブラブ said...

セレブ女性との割り切りお付き合いで大金を稼いでみませんか?女性に癒しと快楽、男性に謝礼とお互い満たしあえる当サイト、セレブラブはあなたの登録をお待ちしております。

夏フェス!! said...

夏フェス一緒に行ってくれる人募集!!夏の思い出一緒につくろぉ☆ megumi-0830@docomo.ne.jp 連絡してね♪

無料ゲーム said...

あなたのゲーマー度を無料ゲーム感覚で測定します。15個の質問に答えるだけの簡単測定で一度遊んでみませんか?ゲームが得意な人もそうでない人もぜひどうぞ。

素人 said...

Hな女性たちは素人ホストを自宅やホテルに呼び、ひとときの癒しを求めていらっしゃいます。当サイトでは男性ホスト様の人員が不足しており、一日3~4人の女性の相手をするホストもおられます。興味を持たれた方は当サイトにぜひお越しください

出会い系 said...

実は出会い系には…関係者用入り口があるのを知っていますか?広告主やスポンサー用に用意されたIDではサクラや業者が立ち入ることが出来ないようになっているのです。当サイトでは極秘に入手した関係者用URLが公開されています

逆援助 said...

男性はお金、女性は快楽を得る逆援助に興味はありませんか?お金を払っても性的欲求を満たしたいセレブ達との割り切り1日のお付き合いで当サイトでは大金を得ることができます。無料登録なのでアルバイト感覚でOK、詳しくはTOPページでどうぞ。

友達募集 said...

ホムペ完成記念!私の事みんなに知ってもらいたくて頑張りましたぁ。色々とご感想をお待ちしているので思った事を意見してください。メアドはほむぺにのせてありますぅ!★ fan.jna@docomo.ne.jp

家出 said...

夏休みで気軽に家出する女子○生が急増しています。しかし家出したはいいものの泊る所やお金が無い彼女たちは、掲示板などで泊めてくれる男性を探す子も多いようです。当掲示板にも夏休みに入ってから通常の3倍以上のメッセージが寄せられています

人妻 said...

今最もアツイバイトは人妻とのセフレ契約です。当サイトではお金を払ってでもセフレがほしい人妻が集まり、男性会員様との逆援生活を待っています。当サイトで欲求不満の女性との出会いをしてみませんか

素人 said...

素人ホストでは、男性のテクニック次第で女性会員様から高額な謝礼がもらえます。欲求不満な人妻や、男性と出会いが無い女性達が当サイトで男性を求めていらっしゃいます。興味のある方はTOPページからどうぞ

友達募集中 said...

少し魅惑な自分をネットだから公開してみました。普段言えない事など、思い切って告白しているプロフなので興味ある方はぜひ除いてみてください連絡待ってまぁす。 hinyaaaaa@docomo.ne.jp

Anonymous said...

私はあなたのブログが好きです。 あなたは良い仕事をしています。 そのまま続けてください。 [url=http://www.gogo-eigo.com/sony-%E3%82%A6%E3%82%A9%E3%83%BC%E3%82%AF%E3%83%9E%E3%83%B3-a%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BA-64gb-%E3%83%96%E3%83%A9%E3%82%A6%E3%83%B3-nw-a847t/]ウォークマン s[/url]

Anonymous said...

I would like to exchange links with your site www.paritoshonline.com
Is this possible?

Anonymous said...

Genial brief and this fill someone in on helped me alot in my college assignement. Gratefulness you for your information.

Anonymous said...

Thanks for an idea, you sparked at thought from a angle I hadn’t given thoguht to yet. Now lets see if I can do something with it.