Saturday, February 28, 2009

Installing mediainfo on Ubuntu

There's no single ready made package for mediainfo as far as I can see, so no apt-get install, but the required .deb packages are available and so can be installed using dpkg.

Pick the appropriate packages for your system from the mediainfo sourceforge download page, then install in the correct order using dpkg -i.

To install the CLI version on my fit-pc Ubuntu 8.10 server, I did
$ wget http://downloads.sourceforge.net/mediainfo/mediainfo_0.7.11-1_i386.Debian_5.0.deb
$ wget http://downloads.sourceforge.net/mediainfo/libmediainfo0_0.7.11-1_i386.Debian_5.0.deb
$ wget http://downloads.sourceforge.net/zenlib/libzen0_0.3.8-1_i386.Debian_5.0.deb
$ sudo dpkg -i libzen0_0.3.8-1_i386.Debian_5.0.deb
$ sudo dpkg -i libmediainfo0_0.7.11-1_i386.Debian_5.0.deb
$ sudo dpkg -i mediainfo_0.7.11-1_i386.Debian_5.0.deb
Then it's good to go.

Monday, February 2, 2009

Automount USB disks in Ubuntu Server

I am using the usbmount package to automount a 1TB USB disk connected to my mini linux media server. This allows me to mount and unmount the external disk simply by turning it on and off, which is a convenient and power-saving arrangement.

Since I'm now storing DVD rips for my Popcorn Hour media player, I needed to add more storage to my streaming media server. My fit-PC takes 2.5" IDE/PATA drives, so it is already fully loaded with a 250G drive. So I got a 1TB 3.5" SATA drive (Western Digital GreenPower) and put it in a USB enclosure.

It's a very quiet, low power drive (about 9W generally), but I don't want it on 24/7. Spinning down the disk is one option, and I might investigate that further. But right now I want
  1. To simply switch the disk on when I need it and off when I'm done.
  2. For that to be safe (without potential for losing data).
  3. To include the disk in the network share I export for the Popcorn Hour.
Desktops systems automount USB disks when you plug them in or power them on. This functionality is not available by default in Ubuntu server. (The packages used depend on the desktop environment.) Following a suggestion in the Ubuntu documentation, I installed the usbmount package
This package automatically mounts USB mass storage devices (typically USB pens) when they are plugged in, and unmounts them when they are removed. The mountpoints (/media/usb[0-7] by default), filesystem types to consider, and mount options are configurable. When multiple devices are plugged in, the first available mountpoint is automatically selected. If the device provides a model name, a symbolic link /var/run/usbmount/MODELNAME pointing to the mountpoint is automatically created. [...]
... which sounds ideal. And as far as I can see, it does the job.

I couldn't find much online about how to configure usbmount, but I soon found /etc/usbmount/usbmount.conf. You can configure mount options per filesystem type. The default options are
MOUNTOPTIONS="sync,noexec,nodev,noatime"

Out of the box, it only automounts ext2 and ext3 formatted volumes. I had formatted my new disk with XFS, so I added xfs to the configuration

FILESYSTEMS="ext2 ext3 xfs"

and it seems to work fine. When I switch on the disk, I see these messages in syslog:

kernel: [1034394.920087] usb 1-2: new high speed USB device using ehci_hcd and address 27
kernel: [1034395.064826] usb 1-2: configuration #1 chosen from 1 choice
kernel: [1034395.078845] scsi25 : SCSI emulation for USB Mass Storage devices
kernel: [1034395.085992] usb-storage: device found at 27
kernel: [1034395.086033] usb-storage: waiting for device to settle before scanning
kernel: [1034400.084595] usb-storage: device scan complete
kernel: [1034400.087474] scsi 25:0:0:0: Direct-Access     WDC WD10 EADS-00L5B1      0041 PQ: 0 ANSI: 0
kernel: [1034400.091636] sd 25:0:0:0: [sdb] 1953525168 512-byte hardware sectors (1000205 MB)
kernel: [1034400.094271] sd 25:0:0:0: [sdb] Write Protect is off
kernel: [1034400.094309] sd 25:0:0:0: [sdb] Mode Sense: 03 00 00 00
kernel: [1034400.094328] sd 25:0:0:0: [sdb] Assuming drive cache: write through
kernel: [1034400.104985] sd 25:0:0:0: [sdb] 1953525168 512-byte hardware sectors (1000205 MB)
kernel: [1034400.113058] sd 25:0:0:0: [sdb] Write Protect is off
kernel: [1034400.113094] sd 25:0:0:0: [sdb] Mode Sense: 03 00 00 00
kernel: [1034400.113114] sd 25:0:0:0: [sdb] Assuming drive cache: write through
kernel: [1034400.120193]  sdb: sdb1
kernel: [1034400.137434] sd 25:0:0:0: [sdb] Attached SCSI disk
kernel: [1034400.137980] sd 25:0:0:0: Attached scsi generic sg1 type 0
usbmount[16483]: executing command: mount -txfs -osync,noexec,nodev,noatime /dev/sdb1 /media/usb0
kernel: [1034401.228110] XFS mounting filesystem sdb1
kernel: [1034401.710070] Ending clean XFS mount for filesystem: sdb1
usbmount[16483]: executing command: run-parts /etc/usbmount/mount.d

The disk is mounted:

$ mount
<snip...>
/dev/sdb1 on /media/usb0 type xfs (rw,noexec,nodev,sync,noatime)

And when I switch it off, I see

kernel: [1034259.923629] usb 1-2: USB disconnect, address 26
kernel: [1034259.936251] xfs_force_shutdown(sdb1,0x1) called from line 420 of file /build/buildd/linux-2.6.27/fs/xfs/xfs_rw.c.  Return address = 0xe0a9ddb4
kernel: [1034259.936334] Filesystem "sdb1": I/O Error Detected.  Shutting down filesystem: sdb1
kernel: [1034259.936404] Please umount the filesystem, and rectify the problem(s)
kernel: [1034259.949818] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034259.949851] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034259.949890] xfs_force_shutdown(sdb1,0x1) called from line 420 of file /build/buildd/linux-2.6.27/fs/xfs/xfs_rw.c.  Return address = 0xe0a9ddb4
kernel: [1034259.968157] Filesystem "sdb1": xfs_log_force: error 5 returned.
usbmount[16307]: executing command: umount -l /media/usb0
kernel: [1034260.050924] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.057086] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.061208] xfs_force_shutdown(sdb1,0x1) called from line 420 of file /build/buildd/linux-2.6.27/fs/xfs/xfs_rw.c.  Return address = 0xe0a9ddb4
kernel: [1034260.069650] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.073675] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.077672] xfs_force_shutdown(sdb1,0x1) called from line 420 of file /build/buildd/linux-2.6.27/fs/xfs/xfs_rw.c.  Return address = 0xe0a9ddb4
usbmount[16307]: executing command: run-parts /etc/usbmount/umount.d
kernel: [1034260.084706] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.084735] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.084820] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.084864] Filesystem "sdb1": xfs_log_force: error 5 returned.
kernel: [1034260.084891] Filesystem "sdb1": xfs_log_force: error 5 returned.

which doesn't look so great. But after repeatedly mounting and unmounting the disk without any apparent problems, I was getting the feeling that this was not harmful.

I did a bit of searching to see whether XFS supports the sync mount option. The answer wasn't clear, so I raised a question on the XFS mailing list to see what they thought. The initial response was discouraging, but on followup it seems like since...
  • I am sync mounting the filesystem (what usbmount does by default), and

  • my kernel version is later than 2.6.17 (from which point write barrier support is enabled by default in XFS)
... I can keep on doing what I'm doing. I will not get corruption of the file system. (Do read the thread, the XFS FAQ and otherwise satisfy yourself. It's your data.)

The last item on my wish list was to include the disk in the network share I export for the Popcorn Hour. This is easy.

Usbmount mounts the disk to /media/usb[0-7] arbitrarily, but it also creates a symbolic link in /var/run/usbmount using the disk model name, which provides a consistent reference point. I created a link in my media storage directory to that point, e.g.
ln -s /home/shared/movies /var/run/usbmount/WDC_WD10_EADS-00L5B1_1/movies

Using my existing Samba share (/home/shared), this works perfectly. When the disk is on, I can browse into the linked directory from the Popcorn Hour. When the disk is off, the link is invisible.