Troubleshooting Optical Drives from the CLI

From FreekiWiki
Revision as of 22:10, 9 December 2011 by Scellef (talk | contribs) (→‎Mounting Disc Images from the CLI)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


For reference, lines that start with $> indicate a command prompt in a terminal, where everything listed afterward would be a bash command.

Detecting & Interacting with the Drive

First things first: Confirm that Ubuntu recognizes the optical drive!

  $> dmesg | grep sr0

sr0 is the name Ubuntu gives to its optical media devices. If you have more than one optical drive, the number will increment by 1. In which case, you could try running something like:

  $> dmesg | grep -w 'sr.'

The -w flag will only grab an exact word match (excluding certain punctuations, such as a colon). The '.' is a regular expression wildcard for a single character. If you've just booted your system, and the optical drive is empty and otherwise untouched, you will generally see some output like this:

  [    0.847741] sr0: scsi3-mmc drive: 24x/24x writer cd/rw xa/form2 cdda tray
  [    0.847912] sr 0:0:0:0: Attached scsi CD-ROM sr0

So far, so good. If nothing is returned from either of those commands, this indicated that Ubuntu is not recognizing the optical drive. Start by confirming the drives are connected to both the power supply, and the motherboard. Recheck your jumper settings (The two vertical pins closest to the IDE interface designate Master, the next two designate Slave, and the two next to that designate Cable Select. Generally, we like to explicitly jumper our drives as Master and Slave, as it helps to eliminate ambiguities). Next, confirm that the BIOS is recognizing the optical drive. Most desktop BIOSes are pretty good about reporting the IDE and SATA interfaces that are present on the motherboard, but there do exist exceptions. If it's not there, try switching out some cables. If after all that, the drive doesn't exist in either the BIOS or Ubuntu, swap it out, remembering to mark a small X on the drive to indicate its failure.

The next thing to do is to see whether or not Ubuntu can actually interact with the drive. For this, we'll tell Ubuntu to eject the tray with:

  $> eject

Shocking! Occasionally, Ubuntu won't think to associate the optical drive with its 'cdrom' device, and you likely get an error that says something like:

  eject: unable to find or open device for: `cdrom'

In such an event, we'll have to specifically call out the device name:

  $> eject /dev/sr0

Ideally, all our of our interactions with optical drives will happen from the software. A lot of the bugs we encounter with Lucid, for instance when a disc image won't unmount, is the result of Ubuntu not catching hardware events (like the physical eject button on the drive itself). Letting Ubuntu take care of all the dirty work helps to keep those bugs from surfacing, and this is a habit that is especially good to impart to our up and coming Builders.

For the curious, you can also close an open tray with the -t flag:

  $> eject -t /dev/sr0

Watching & Interpreting System Logs

Now, for the coup de grace!

  $> watch -n1 "dmesg | tail -30"

watch is a lovely little command that will rerun a command over and over at a specified interval and print its output to the terminal. In this case, it's taking the 30 newest lines from the system log and updates them every second. The syntax is essentially

  $> watch -n[INTERVAL] "[COMMAND]"

There are of course a bajillion different options and features with this command; see your local man page for information. This command is particularly useful to observe how Ubuntu is interacting with the optical drive. Typical output looks something like this:

  [ 2481.781712] ISO 9660 Extensions: Microsoft Joliet Level 3
  [ 2481.945461] ISOFS: changing to secondary root

This is an ideal case, here the drive had no issue seeing, reading, and then mounting a disc. ISO 9660 is the filesystem for optical media. Unforunately, this isn't going to be a common sight when you start troubleshooting optical drives from the commandline. More often, you'll see something like this:

  [  377.899714] end_request: I/O error, dev sr0, sector 0
  [  377.900414] sr 1:0:0:0: [sr0] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
  [  377.900419] sr 1:0:0:0: [sr0] Sense Key : Illegal Request [current]
  [  377.900423] sr 1:0:0:0: [sr0] Add. Sense: Logical block address out of range
  [  377.900428] sr 1:0:0:0: [sr0] CDB: Read(10): 28 00 00 00 00 00 00 00 01 00

And these five lines repeat over and over. Pretty scary looking! Even more unfortunate, this is the output that results from a drive that actually mounts and reads just fine. For whatever reason, the firmware and Ubuntu like to endlessly panic about optical media. Now the thing about the above output is that it's what seems to print normally when Ubuntu is trying to read and mount a disc. If it seems like the optical drive is taking a really long time to mount, watching this output can help you to determine whether it's actually working at mounting, or getting held up with some other error. An example of some output that might indicate either a bad disc, or a bad drive:

  [ 27.942989] sr 4:0:0:0: [sr0] Sense Key : Medium Error [current]
  [ 27.942991] sr 4:0:0:0: [sr0] Add. Sense: L-EC uncorrectable error
  [ 27.942994] end_request: I/O error, dev sr0, sector 216176
  [ 27.942995] Buffer I/O error on device sr0, logical block 54044

If you see something like this, the first thing to try is swapping in a new disc. Be extra careful to check what kind of media you're putting in there. If it happens to be a rewritable DVD, make a mental note about which kind it is (DVD-RW, DVD+RW, etc). Some drives, even if they're just DVD-ROMs, will throw fits about the wrong type of writable media being thrown in.

Mounting Disc Images from the CLI

The last things I want to touch on is how to manually mount and dismount a disk from the commandline. In modern Linux operating systems, a lot of the footwork you'd have to do to mount a disk is usually taken care of for you, meaning you can usually get away something as lazy as:

  $> sudo mount cdrom /media/

Of course, the conveniences brought by modern operating sytems also introduces some modern errors. Frequently, you'll run into something like this:

  mount: you must specify the filesystem type

Typically, if this comes up, you can make a pretty safe assumption that drive doesn't like the media or might just be altogether bad. However, we can still give it the old college try just to confirm our suspicions. Remember the optical media filesystem type I mentioned before? That's specifically what mount is looking for:

  $> sudo mount /dev/sr0 -t iso9660 /media/

A quick primer for mount's syntax:

  $> sudo mount [DEVICE NAME] -t[FILESYSTEM TYPE] [WHERE TO MOUNT]

If this is successful, the contents of the device (in this case, the optical media) will be accessible under the /media directory. If, while trying to mount optical media, you get some output that looks like this:

  mount: wrong fs type, bad option, bad superblock on /dev/sr0,
         missing codepage or helper program, or other error
         In some cases useful info is found in syslog - try
         dmesg | tail  or so

it's a pretty good indicator either your disc is blank, or that its data has been corrupted.

In order to unmount a disc, then syntax looks like:

  $> sudo umount [WHERE IT'S MOUNTED]

Specifically, you tell it to unmount the discs place in the directory tree. So, from our earlier example:

  $> sudo umount /media/

should suffice. If you happen to mount a disc somewhere crazy, and can't for the life of you remember where it is, there is still hope! Just type 'mount':

  $> mount
  /dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0)
  proc on /proc type proc (rw,noexec,nosuid,nodev)
  none on /sys type sysfs (rw,noexec,nosuid,nodev)
  fusectl on /sys/fs/fuse/connections type fusectl (rw)
  none on /sys/kernel/debug type debugfs (rw)
  none on /sys/kernel/security type securityfs (rw)
  none on /dev type devtmpfs (rw,mode=0755)
  none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
  none on /dev/shm type tmpfs (rw,nosuid,nodev)
  none on /var/run type tmpfs (rw,nosuid,mode=0755)
  none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
  /dev/sda3 on /home type ext4 (rw,commit=0)
  binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
  gvfs-fuse-daemon on /home/scellef/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=scellef)
  /dev/sr0 on /media/Planar type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500)

This tells you all of the devices you currently have mounted on your system, and where they're located in the directory tree. From here, we can see that /dev/sr0 (our optical drive) is mounted at /media/Planar. And so:

  $> sudo umount /media/Planar