Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm trying to get access to the partition type (the one-byte field in the master boot record) in udev, so that I can set ownership and permissions based on partition type. The challenge is of course that while I want to set the owner, etc. of sda1, the partition table is actually part of its parent, sda. (Of course, there are actually lots of disks, not just sda)

I've managed to get the partition type of all the primary partitions imported into udev database entry each disk. This adds four ENV entries to each disk, one per possible primary partition. They look like this, as shown by udevadmin info --query=all:


I can then get access to those in the partition device (sda1) by using an IMPORT{parent}. The partition number (1–4) can be found in ATTR{partition}. The problem is getting the type of this partition.

It seems like ENV{LOCAL_PARTTYPE}="$env{LOCAL_PARTTYPE_P$attr{partition}}" should do this, but it doesn't work. If you take off the leading $, the generated name is correct, udev just won't do the indirect lookup.

The only way I've found to do it is this awkward line: IMPORT{program}="/bin/sh -c 'echo LOCAL_PARTTYPE=$$LOCAL_PARTTYPE_P$attr{partition}'" which works because ENV entries are passed as environment variables to programs udev runs, and thus the shell can do the expansion and echo it right back.

I could also duplicate everything for each possible partition number (doable, since I'm only using primary partitions), but that strikes me as even worse:

$ATTR{partition}=="1", $ENV{LOCAL_PARTTYPE_P1}=="da", OWNER="grid", ...
$ATTR{partition}=="2", $ENV{LOCAL_PARTTYPE_P2}=="da", OWNER="grid", ...

Is there a good way to do this?

share|improve this question
It is not clear what you are trying to accomplish. For example: in the paragraph where you mention IMPORT{program}=", you refer to a method of setting a device property, whereas below that, you present rules for matching a device. Your description does not put it clearly, what is your attempt at each point. –  rozcietrzewiacz Nov 10 '11 at 23:57
@rozcietrzewiacz: I'm trying to set ownership & permissions based on partition type. I'll make an attempt to clarify... –  derobert Nov 11 '11 at 0:32
@rozcietrzewiacz: OK, I've done my best to clarify, please let me know if that helps. –  derobert Nov 11 '11 at 0:56
I don't understand why you are having problems with getting the partition type of a given partition. When I do udevadm info --query=all --name=/dev/sda1, I clearly have ID_PART_ENTRY_TYPE=0x83 and ID_FS_TYPE=ext4. Don't you have those or do they not satisfy your needs? –  rozcietrzewiacz Nov 11 '11 at 17:42
@rozcietrzewiacz: Unfortunately, I only have ID_PART_TABLE_TYPE=dos, not ID_PART_ENTRY_TYPE. Debian Squeeze apparently doesn't have a new-enough udev, or blkid rather. I suppose backporting util-linux would be an option. –  derobert Nov 11 '11 at 18:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.