Wednesday, 22 September 2010

Good Times with external USB drives on Ubuntu Linux 10.04

For a long while, I've been using a rather useful 320 GB USB drive from Lenovo, which has the added feature of security via a keycode entered on the device itself. Whilst I'm sure it's not totally hack-proof, it's good enough for my requirements.

A while back I did see an issue where Ubuntu would (correctly) throw up a message when I booted up because it was trying to automount the drive even though it wasn't connected. So far, so good, but my problem was that the error message was written in black text on a black background :-) I did report a bug via Launchpad, as per my previous post but haven't yet seen any response.

As long as I remember to hit the "S" key to skip past the error when I boot, I'm OK.

However, I have experienced another issue recently.

The drive is formatted using the Apple HFS/HFS+ format, which allows me to use it for read-only AND read-write under OSX and Ubuntu without needing to use the dreaded NTFS format.

Occasionally, when I try to write to the drive, I get the exception: -

Read-only file system

even though the drive is definitely mounted as read-write in /etc/fstab : -

/dev/sdb2 /home/hayd/lenovo hfsplus rw,auto,exec,user

and the mount point is definitely owned by my user ID: -

drwxrwxrwx  2 hayd hayd      4096 2010-08-05 16:27 lenovo

Following this thread led me to the solution, although I did go down a blind alley :-)

In the first instance, I thought that the drive might be using the Apple Journalling mechanism, which Ubuntu can't handle. Having mounted it up on my Macbook, I could see that this wasn't the case.

However, this section of the thread provided the answer: -

The Ubuntu kernel (at least as of Feisty) does have write support for non-journalled HFS+. If you've got a journalled HFS+ file system, you're out of luck.

Furthermore, the driver will refuse to mount the filesystem read/write if it was not cleanly unmounted (to prevent serious data corruption). If the drive is ever not cleanly unmounted, you'll need to run a filesystem checker/repairer on it before you'll be able to mount it read/write again. Unfortunately, the HFS+ filesystem checker isn't actually packaged for Ubuntu (or wasn't last time I checked). You can download and build the Apple tools -the howto I followed was on the Gentoo Wiki. You probably want to read that anyway, there's some good information there. You can ignore all the "adding kernel support" bits though - we've already got the kernel support.

I remembered that I'd previously removed the drive from my Thinkpad having suspended, rather than shut down, the OS, meaning that the drive was never cleanly unmounted.

I used the Ubuntu Disk Utility to check the file system on the relevant partition ( sdb2 ) on the drive, and then remounted it again, using the mount command.

This time, it mounted up in read-write mode, and I was able to create folders, copy files etc. to my heart's content.

Lovely

3 comments:

Fajar said...

Interesting article. Thanks for sharing ^^

mark said...

You'll be wanting the "nobootwait" parameter in fstab to make Ubuntu boot without waiting for you to press "S" if the drive is absent.

Dave Hay said...

Cheers, Mark, will check it out

Right Sed Fred!

I've been using the Stream Editor (sed) for the past few years, and especially love it's ability to do in-place editing of a file as...