Skip to content

systemd-repart: added partition number not being the highest one available #43449

Closed

Description

@pslldq

systemd version the issue has been seen with

261.2

Used distribution

Arch Linux (full pkg version: 261.2-1)

Linux kernel version used

7.1.7-arch1-1

CPU architectures issue was seen on

x86_64

Component

systemd-repart

Expected behaviour you didn't see

Based on the systemd-repart(8) man page:

New partitions are always appended to the end of the partition table, taking the first partition table slot whose index is greater than the indexes of all existing partitions.

Therefore I'd expect that even if a partition table has free partition numbers in-between, those are not used when creating new systemd partitions.

Unexpected behaviour you saw

systemd-repart happily uses the first available partitions number when creating a new partition. This mixes up the ordering, as in another run systemd maps the partitions to different files, causing it to potentially do another change.

Steps to reproduce the problem

For the sake of simplicity I'll be using a disk image in a file to demonstrate the issue instead of a real disk.

Create and cd to an empty directory. Create the following two repart.d configuration files in it:

$ cat 10-a.conf 
[Partition]
Type=linux-generic
Label=a
SizeMinBytes=200M
SizeMaxBytes=200M
$ cat 20-b.conf 
[Partition]
Type=linux-generic
Label=b
SizeMinBytes=100M
SizeMaxBytes=100M

Then create the disk image file with systemd-repart:

$ systemd-repart --definitions=. --empty=create --size=500M test.img
Sized 'test.img' to 500M.
TYPE          LABEL UUID                                 PART FILE       RAW SIZE     SIZE PADDING
linux-generic a     945d9fb7-c748-4a13-81e8-78cb08a80759    0 10-a.conf 209715200   → 200M    → 0B
linux-generic b     d4e71732-a2b9-451a-826d-07e3a8d732a2    1 20-b.conf 104857600   → 100M    → 0B
                                                                                  Σ = 300M  Σ = 0B

 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
 │                                                                   └─ 20-b.conf                                                                                           
 └─ 10-a.conf                                                                                                                                                               

Applying changes to test.img.
Adding new partition 0 to partition table.
Adding new partition 1 to partition table.
Writing new partition table.
Partition table written.
$ fdisk -l test.img
Disk test.img: 500 MiB, 524288000 bytes, 1024000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C8E8C97F-7E27-4750-ADFB-C9106825CF03

Device      Start    End Sectors  Size Type
test.img1    2048 411647  409600  200M Linux filesystem
test.img2  411648 616447  204800  100M Linux filesystem

Now delete only the first partition:

$ sfdisk --delete test.img 1

The partition table has been altered.
$ fdisk -l test.img
Disk test.img: 500 MiB, 524288000 bytes, 1024000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C8E8C97F-7E27-4750-ADFB-C9106825CF03

Device      Start    End Sectors  Size Type
test.img2  411648 616447  204800  100M Linux filesystem

Now run systemd-repart again on the image file:

$ systemd-repart --definitions=. --dry-run=no test.img
Partition UUID calculated from seed for partition 18446744073709551615 already used, reverting to randomized UUID.
TYPE          LABEL UUID                                 PART FILE       RAW SIZE        SIZE        PADDING
linux-generic b     d4e71732-a2b9-451a-826d-07e3a8d732a2    1 10-a.conf 209715200 100M → 200M 198.9M → 98.9M
linux-generic b     92afbd8b-6d5e-4572-8947-2f2f74cc56d9    0 20-b.conf 104857600      → 100M           → 0B
                                                                                     Σ = 300M      Σ = 98.9M

 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
 └─ 20-b.conf                                                        │                                                                                                      
                                                                     └─ 10-a.conf                                                                                           

Applying changes to /tmp/t/test.img.
Successfully wiped file system signatures from future partition 0.
Successfully discarded data from future partition 0.
Successfully discarded gap after partition 0.
Growing existing partition 1.
Adding new partition 0 to partition table.
Writing new partition table.
Partition table written.
$ fdisk -l test.img
Disk test.img: 500 MiB, 524288000 bytes, 1024000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C8E8C97F-7E27-4750-ADFB-C9106825CF03

Device      Start    End Sectors  Size Type
test.img1    2048 206847  204800  100M Linux filesystem
test.img2  411648 821247  409600  200M Linux filesystem

As you can see, systemd-repart added the new 100M partition with partition number 0 (partition number 1 in fdisk). I'd expect systemd-repart to choose the partition number 2 instead (3 in fdisk) to match it's described man page behavior. Sidenote: Both partitions being labeled as b is expected, as the configuration file for a is mapped on the existing b partition.

This causes that running systemd-repart again maps the definitions differently, thus resizing the partition 0 (1 in fdisk) also to 200M:

$ systemd-repart --definitions=. --dry-run=no test.img
TYPE          LABEL UUID                                 PART FILE       RAW SIZE        SIZE   PADDING
linux-generic b     92afbd8b-6d5e-4572-8947-2f2f74cc56d9    0 10-a.conf 209715200 100M → 200M 100M → 0B
linux-generic b     d4e71732-a2b9-451a-826d-07e3a8d732a2    1 20-b.conf 209715200        200M     98.9M
                                                                                     Σ = 400M Σ = 98.9M

 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
 │                                                                   └─ 20-b.conf                                                                                           
 └─ 10-a.conf                                                                                                                                                               

Applying changes to /tmp/t/test.img.
Growing existing partition 0.
Writing new partition table.
Partition table written.
$ fdisk -l test.img
Disk test.img: 500 MiB, 524288000 bytes, 1024000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C8E8C97F-7E27-4750-ADFB-C9106825CF03

Device      Start    End Sectors  Size Type
test.img1    2048 411647  409600  200M Linux filesystem
test.img2  411648 821247  409600  200M Linux filesystem

Additional program output to the terminal or log subsystem illustrating the issue

Activity

  1. added
    bug 🐛
    on Aug 19, 2026
  2. added 4 commits that reference this issue on Aug 21, 2026
    d7d0e25
    60dfb46
    aedfbe5
    0a14ef7
  3. added a commit that references this issue on Aug 26, 2026
    a9ff124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛repart

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions