We'll see | Matt Zimmerman

a potpourri of mirth and madness

Quick hack: GPT partitions without kernel support

I have a couple of USB hard disks which each have a single GPT partition on them. I recently moved them to an embedded server, and discovered that its Linux kernel lacked support for GPT.

For various reasons, it isn’t practical for me to replace its kernel right now, but I still wanted to be able to use the disks, and to have them automount by UUID.

…some time later…

A set of udev rules:

# Import variables from devkit-disks-part-id on the *parent* device
# devkit-disks-part-id looks at $DEVPATH regardless of the argument passed to
# it, so we need to override that
ATTR{partition}=="1", IMPORT{program}="/usr/bin/env DEVPATH=%p/.. /lib/udev/devkit-disks-part-id /dev/%P"

# If this partition is on a disk using GPT, fake it
ATTR{partition}=="1", ENV{DKD_PARTITION_TABLE_SCHEME}=="gpt", RUN+="/sbin/losetup -o 16896 -f /dev/%k"

This code uses a tool from devicekit-disks to detect when a GPT partition table is present. If so, it sets up a loop device at the appropriate (hardcoded) offset corresponding to the GPT partition.

It only works for a single partition, and it’s not exactly pretty, but it solved my problem. The loop devices generate their own uevents, the generic udev rules detect the UUID, and everything works.

Advertisement

Written by Matt Zimmerman

December 22, 2009 at 16:59

%d bloggers like this: