On Thu, Jan 06, 2022 at 11:11:30AM -0000, Stuart Henderson wrote:
> You can create more than one "fdisk partition" but there's not much
> point in doing so. It doesn't give you any extra "disklabel partitions".

There is a niche use case for multiple OpenBSD MBR partitions, though:

Imagine a machine with an existing disk layout like this:

Disk: vnd0      geometry: 156250/1/100 [15625000 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 0C      0   0  65 -  41943   0  68 [          64:     4194304 ] Win95 FAT32L
 1: 83  41943   0  69 -  83886   0  72 [     4194368:     4194304 ] Linux files*
 2: 82  83886   0  73 - 125829   0  76 [     8388672:     4194304 ] Linux swap  
 3: 00      0   0   0 -      0   0   0 [           0:           0 ] unused      

The spoofed disklabel would look something like:

# /dev/rvnd0c:
type: vnd
disk: vnd device
label: fictitious
duid: 0000000000000000
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 156250
total sectors: 15625000
boundstart: 0
boundend: 15625000
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  c:         15625000                0  unused                    
  i:          4194304               64   MSDOS                    
  j:          4194304          4194368  ext2fs                    
  k:          4194304          8388672 unknown                    

Note that there is about 1.5 Gb of free space at the end of the disk.

If you now wanted to install OpenBSD on this disk, keeping the Linux 
installation but deleting the FAT partition at the beginning, you could edit 
the MBR to include two OpenBSD MBR partitions:

Disk: vnd0      geometry: 156250/1/100 [15625000 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: A6      0   0  65 -  41943   0  68 [          64:     4194304 ] OpenBSD     
 1: 83  41943   0  69 -  83886   0  72 [     4194368:     4194304 ] Linux files*
 2: 82  83886   0  73 - 125829   0  76 [     8388672:     4194304 ] Linux swap  
 3: A6 125829   0  77 - 156249   0 100 [    12582976:     3042024 ] OpenBSD     

The spoofed disklabel would now look like this:

# /dev/rvnd0c:
type: vnd
disk: vnd device
label: fictitious
duid: 0000000000000000
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 156250
total sectors: 15625000
boundstart: 64
boundend: 4194368
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  c:         15625000                0  unused                    
  i:          4194304          4194368  ext2fs                    
  j:          4194304          8388672 unknown                    

Note that the bounds of the OpenBSD partition no longer cover the whole disk, 
as they did when there was no OpenBSD MBR partition, but now only span the 
space defined by the first OpenBSD MBR partition.

We can change the bounds:

# /dev/rvnd0c:
type: vnd
disk: vnd device
label: fictitious
duid: a8dacebd60fac195
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 156250
total sectors: 15625000
boundstart: 64
boundend: 15625000
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  c:         15625000                0  unused                    
  i:          4194304          4194368  ext2fs                    
  j:          4194304          8388672 unknown                    

And now create disklabel partitions across the whole of the disk:

# /dev/rvnd0c:
type: vnd
disk: vnd device
label: fictitious
duid: a8dacebd60fac195
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 156250
total sectors: 15625000
boundstart: 64
boundend: 15625000
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:          4194304               64  4.2BSD   2048 16384     1 
  b:          1048624         12582976    swap                    
  c:         15625000                0  unused                    
  d:          1993376         13631616  4.2BSD   2048 16384     1 
  i:          4194304          4194368  ext2fs                    
  j:          4194304          8388672 unknown                    

Note that the disklabel editor will not, by default, allow you to create a 
disklabel partition which overlaps space used by one of the other MBR 
partitions, which is usually a good thing and probably the behaviour that most 
people would want.

However, if we instead wanted to use the space currently allocated as a Linux 
swap partition as our OpenBSD 'b' partition, I.E. share swap space with the 
Linux installation on the same disk, and re-allocate the space currently used 
as 'b' above to a 4.2BSD partition, 'e', we can, by removing the 'j' partition 
from the disklabel entirely:

# /dev/rvnd0c:
type: vnd
disk: vnd device
label: fictitious
duid: a8dacebd60fac195
flags:
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 156250
total sectors: 15625000
boundstart: 64
boundend: 15625000
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:          4194304               64  4.2BSD   2048 16384     1 
  b:          4194304          8388672    swap                    
  c:         15625000                0  unused                    
  d:          1993376         13631616  4.2BSD   2048 16384     1 
  e:          1048640         12582976  4.2BSD   2048 16384     1 
  i:          4194304          4194368  ext2fs                    

Admittedly, there are usually much better ways to partition disks, but it does 
demonstrate not only a use for multiple OpenBSD MBR partitions, but also how 
the BSD disklabel really is independent of other partitioning schemes, and can, 
(usefully), present a totally different view of the disk.  In the above 
example, the fdisk partitions still look the same:

Disk: vnd0      geometry: 156250/1/100 [15625000 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: A6      0   0  65 -  41943   0  68 [          64:     4194304 ] OpenBSD     
 1: 83  41943   0  69 -  83886   0  72 [     4194368:     4194304 ] Linux files*
 2: 82  83886   0  73 - 125829   0  76 [     8388672:     4194304 ] Linux swap  
 3: A6 125829   0  77 - 156249   0 100 [    12582976:     3042024 ] OpenBSD     

No other operating system needs to know that OpenBSD is happily scribbling over 
the Linux swap partition.

Reply via email to