LVM on an external drive

As part of my Mini-ITX project (something else which has been a “work in progress” for far too long), I have an external USB HDD enclosure. What I would like to do is move the existing hard drive out of the main case and into this external enclosure.

The enclosure runs almost silently (only HDD spin & seek noise barely audible), and more importantly, contributes zero towards the main case temperature. This is good for two reasons:

  1. it reduces the amount of active cooling required within the case
  2. the airflow within the case is improved, so the CPU heatsink gets more of the cool intake air than at present

The main problem with this is that you can’t just put the drive in the external box and assume everything will work. There are subtleties to consider, such as:

  • A standard initrd doesn’t contain USB modules needed to hook into the external storage device at boot time.
  • GRUB doesn’t understand LVM configurations.
  • A USB drive does not necessarily get allocated the same device name every time at boot. Moving USB devices around (or even adding ones) changes things. For example, what started as /dev/sda could suddenly move to /dev/sdb. That would mean entries in /etc/fstab (if you got that far) would be wrong if using standard partitions.
  • … and probably more I haven’t yet encountered.

I have Googled around a fair bit, but only found a couple of postings in newsgroups saying “don’t use LVM on an external drive” without reasons why. They’re also old posts, probably dating from LVM1 days. I joined the RedHat linux-lvm mailing list and posted a message to it, posing the question of why can’t it be done.

There was a very quick reply came back, saying “go for it”. This guy has had such a system running fine since April 2006, which seems to fit my needs fine.

To help me along, I’ve got a CompactFlash to IDE adapter module, which lets me use a spare CF card as a very small IDE device: bootable and everything. This will be great to hold a basic filesystem: something more complex than possible in a standard initrd image and capable of providing a basic boot system should the USB device go offline. I’m currently making a 512MB SanDisk standard card available for this purpose, but if needs be I can sacrifice one of my SanDisk Ultra II 2GB CF cards that was originally used in my Canon 350D.

My problem now is how to migrate the system over to be able to boot off the external drive. I imagine I’ll need to do something like the following:

  1. plan how each volume is going to map into the new system
  2. some preliminary setup on the machine ready for restart
  3. shut it down
  4. remove the physical drive from the case and install in the external enclosure
  5. power up to check it basically boots OK
  6. configure to fully bring up the LVM volumes at boot without any interaction (did I mention that this also needs to be headless?)
  7. shutdown and install in the correct physical location in my room
  8. power-on and hope that everything worked OK

Even step 1 isn’t trivial though. According to many sources on the web, Compact Flash cards have a limited read/write cycle and using a section of a CF card as swap will trash it fairly quickly. Even things like setting the ‘noatime‘ attribute on the CF filesystems will be useful.

Hopefully all of this will be documented on my Mini-ITX website, which is currently undergoing some reworking of menu systems to make it a more logical place to be. I also really like the “breadcrumbs” feature, but that’s not available on my current template. Must find a better one…