Skip to contentSkip to conversation

Extended partition mapping wrong size

DISCUSSION Phillip Susi 2 participants 5 messages Mar 29, 2010 – Apr 6, 2010

lore
Share & tools
lore
#0 lore raw

I've been investigating a problem I ran into trying to create partitions in sector mode and found that the first logical partition can not begin on the very first sector of the extended partition, immediately following the EBR. This apparently is because the kernel creates a dev node to represent the extended partition and sizes it to two sectors. I could have sworn that the kernel did not used to create a device for the extended partition itself, but I wondered why it was 2 sectors long. I found this:

from fs/partitions/msdos.c:

            /* prevent someone doing mkfs or mkswap on an
               extended partition, but leave room for LILO */
            put_partition(state, slot, start, size == 1 ? 1 : 2);

This appears to set the size of the device to 2 sectors, unless the extended partition is only 1 sector long. Shouldn't the size be whatever length there is between the start of the extended partition, and the first logical partition it contains? So if there are 63 sectors there, as is the usual case when using cylinder alignment, then the device node would expose all of those, but if there is no space, then the device node should only be 1 sector for the EBR, otherwise it overlays the first sector of the logical partition.

#1 lore raw
Quoted 5 lines · Phillip Susi

I've been investigating a problem I ran into trying to create partitions in sector mode and found that the first logical partition can not begin on the very first sector of the extended partition, immediately following the EBR. This apparently is because the kernel creates a dev node to represent the extended partition and sizes it to two sectors.

This is probably kernel bug. It's really insane that the extended pseudo partition overflows to the next logical partition.

Quoted 10 lines

could have sworn that the kernel did not used to create a device for the extended partition itself, but I wondered why it was 2 sectors long. I found this:

from fs/partitions/msdos.c:

            /* prevent someone doing mkfs or mkswap on an
               extended partition, but leave room for LILO */
            put_partition(state, slot, start, size == 1 ? 1 : 2);
Quoted 5 lines

This appears to set the size of the device to 2 sectors, unless the extended partition is only 1 sector long. Shouldn't the size be whatever length there is between the start of the extended partition, and the first logical partition it contains? So if there are 63 sectors there, as is the usual case when using cylinder alignment, then the

Please no. I think the size should not be more than 2 sectors (1024 bytes). The current concept works for years and we have in userspace /etc/partitions parsers that use "if (blocks <= 1)" to detect extended partitions.

The other problem are mkfs programs, the space used for alignment could be 1MiB (or more) -- it's enough many mkfs programs.

BTW, Linux does not use this policy for the others nested partition tables (e.g. Solaris, BSD, Minix, ...). The extended dos partition table is exception. The primary partitions for the others nested PT are exported to the system with its real size :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 2 lines · Karel Zak

This is probably kernel bug. It's really insane that the extended pseudo partition overflows to the next logical partition.

Indeed.

Quoted 4 lines

Please no. I think the size should not be more than 2 sectors (1024 bytes). The current concept works for years and we have in userspace /etc/partitions parsers that use "if (blocks <= 1)" to detect extended partitions.

Could you elaborate a bit on this? What programs have such tests and what would they do differently if it were larger?

Quoted 2 lines

The other problem are mkfs programs, the space used for alignment could be 1MiB (or more) -- it's enough many mkfs programs.

What's wrong with that? If you REALLY want to, there's no reason you can't create a tiny fs there. Then again, I could swear that once upon a time the kernel simply did not bother creating a dev node for the extended partition, and this seems to be a hack that was put in to make it easy for LILO to install to one. Personally I'd prefer going back to the old behavior of just not having a useless device there.

Quoted 4 lines

BTW, Linux does not use this policy for the others nested partition tables (e.g. Solaris, BSD, Minix, ...). The extended dos partition table is exception. The primary partitions for the others nested PT are exported to the system with its real size :-)

Indeed, also the hidden space in the logical partitions is also not exposed, otherwise you would have two dev nodes per logical partition.

#3 lore raw
Quoted 9 lines · Phillip Susi
Quoted 2 lines · Karel Zak

This is probably kernel bug. It's really insane that the extended pseudo partition overflows to the next logical partition.

Indeed.

Quoted 3 lines

Please no. I think the size should not be more than 2 sectors (1024 bytes). The current concept works for years and we have in userspace /etc/partitions parsers that use "if (blocks <= 1)" to detect

Sorry, /proc/partitions

Quoted 4 lines
Quoted 1 line

extended partitions.

Could you elaborate a bit on this? What programs have such tests and what would they do differently if it were larger?

I know about libblkid in e2fsprogs and util-linux-ng. It scans /proc/partitions to get list of "normal" block devices.

We have no clue how many programs/scripts depend on this behaviour.

Quoted 4 lines
Quoted 2 lines

The other problem are mkfs programs, the space used for alignment could be 1MiB (or more) -- it's enough many mkfs programs.

What's wrong with that?

Irrelevant question ;-) It's there for years and it's well know kernel feature.

I understand that from a pedantic point of view the current solution is not perfect, but I don't see any practical reason why we need to change anything. There is no issue. Right?

Quoted 1 line

If you REALLY want to, there's no reason you can't create a tiny fs there.

You have to care about the partition table (EBR).

The current 1024 bytes is completely useless size, if you enlarge the size of the partition (for example to 1MiB) you will see reports from people who lost their extended partitions. (I don't believe that all mkfs programs are able to detect/skip EBR.)

Quoted 5 lines

Then again, I could swear that once upon a time the kernel simply did not bother creating a dev node for the extended partition, and this seems to be a hack that was put in to make it easy for LILO to install to one. Personally I'd prefer going back to the old behavior of just not having a useless device there.

This is probably better idea than enlarge the size :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#4 lore raw
Quoted 6 lines · Karel Zak

You have to care about the partition table (EBR).

The current 1024 bytes is completely useless size, if you enlarge the size of the partition (for example to 1MiB) you will see reports from people who lost their extended partitions. (I don't believe that all mkfs programs are able to detect/skip EBR.)

Good point... mke2fs won't damage it since it leaves the first sector intact and places its boot sector in sector 1 ( or was it 2? ), but FAT and NTFS won't be so kind.

Quoted 7 lines
Quoted 5 lines

Then again, I could swear that once upon a time the kernel simply did not bother creating a dev node for the extended partition, and this seems to be a hack that was put in to make it easy for LILO to install to one. Personally I'd prefer going back to the old behavior of just not having a useless device there.

This is probably better idea than enlarge the size :-)

Aye, I'd prefer the useless device to be removed, but at the very least it should not use a size of 2 when the second sector is not actually there because it is the first sector of the logical partition, though we just patched parted to reserve that second sector anyhow even though you are using none alignment mode, just to avoid running into this problem.