Skip to content

gpt-auto-generator: when dissecting partition table, and multiple root partitions are available, always prefer the one already mounted to / if that exists #34319

Description

@tksc

systemd version the issue has been seen with

255.4

Used distribution

Custom built BSP-firmware using ptxdist

Linux kernel version used

6.9.12

CPU architectures issue was seen on

aarch64

Component

systemd-gpt-auto-generator, systemd-repart

Expected behaviour you didn't see

systemd-growfs-root.service should not be configured to run.

Unexpected behaviour you saw

growfs-root.service being added by/to generator.late.

[FAILED] Failed to start systemd-growfs-root.service.

root 00:00 : ~ # find / -name "growfs"
find: /proc/259: No such file or directory
/run/systemd/generator.late/local-fs.target.d/50-order-systemd-growfs-root.service.conf
/run/systemd/generator.late/-.mount.wants/systemd-growfs-root.service
find: /media/usb0: No such device
/usr/lib/systemd/system/[email protected]
/usr/lib/systemd/system/systemd-growfs-root.service
/usr/lib/systemd/systemd-growfs

The failing of the service due to rootfs being ro is not the issue I want to address, but it's mere presence.

Steps to reproduce the problem

Steps

  1. Run systemd-repart as configured. Please see below (we only run systemd-repart during rc.once).
  2. Reboot

Additional Info

It seems like gpt-auto-generator generates the drop-in when it finds GUID:59 in the other/unbooted partition.

ssahani@3d10422

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

root 05:28 : ~ # sfdisk -l /dev/mmcblk2
Disk /dev/mmcblk2: 3.64 GiB, 3909091328 bytes, 7634944 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: 6FF14787-3191-4269-B06D-BB7FBC884AA2

Device           Start     End Sectors  Size Type
/dev/mmcblk2p1    2048    4095    2048    1M Linux filesystem
/dev/mmcblk2p2    4096 2101247 2097152    1G Linux root (ARM-64)
/dev/mmcblk2p3 2101248 4198399 2097152    1G Linux root (ARM-64)
/dev/mmcblk2p4 4198400 7634903 3436504  1.6G Linux filesystem
root 05:32 : ~ # sfdisk --part-attrs /dev/mmcblk2 2
root 05:32 : ~ # sfdisk --part-attrs /dev/mmcblk2 3
GUID:59


root 14:57 : ~ # cat /etc/rc.once.d/repart 
#!/bin/sh

if systemd-analyze condition "ConditionKernelCommandLine=!root=/dev/nfs"; then
        echo "Repartitioning the root disk"
        systemd-repart --dry-run=no --definitions=/etc/repart.rc-once.d/
        echo "Growing the current root partition"
        /usr/lib/systemd/systemd-growfs /
else
        echo "Skipping repart in rc.once while running NFS boot"
        exit 0
fi


root 14:57 : ~ # for f in $(ls /etc/repart.rc-once.d/*); do echo "'cat $f'"; cat $f; echo; done
'cat /etc/repart.rc-once.d/50-barebox-environment.conf'
[Partition]
Type=linux-generic
Label=barebox-environment

'cat /etc/repart.rc-once.d/50-system0.conf'
[Partition]
Type=root
Label=system0
SizeMinBytes=1G
SizeMaxBytes=1G
Priority=10

'cat /etc/repart.rc-once.d/50-system1.conf'
[Partition]
Type=root
Label=system1
Format=ext4
SizeMinBytes=1G
SizeMaxBytes=1G
Priority=20

'cat /etc/repart.rc-once.d/60-appdata.conf'
[Partition]
Type=linux-generic
Label=appdata
Format=ext4
SizeMinBytes=1G
SizeMaxBytes=4G
Priority=30
Weight=2000

Activity

  1. added
    bug 🐛
    on Sep 9, 2024
  2. tksc commented on Oct 15, 2024

    @tksc
    Author

    Any thoughts on that one?

  3. poettering commented on Oct 15, 2024

    @poettering
    Member

    So the gpt-generator always generates the units for the "newest" root partition it finds on the dissected disk. it dtermines "newest" by doing a (slightly modified) strverscmp() compare on all matching root disks. This means your "system1" partition will always win.

    what it currently does not take into consideration is what is already mounted. that's partly because it is already invoked in the initrd, where nothing should be mounted, and partly because we want that generators are "idempotent" to some point, i.e. that they come to the same results given the same inputs. And while config files and kernel cmdline are clearly valid "inputs" for this, it's not entirely clear the root fs is.

    But i guess, it is surprising what happens here. hence, maybe we should tweak the dissection logic so that it takes into consideration the current rootfs when figuring out which root fs to use. Happy to review a patch for this

  4. added
    RFE 🎁
    and removed
    bug 🐛
    on Oct 15, 2024
  5. changed the title [-]gpt-auto-generator should not regard GUID:59 in redundant / unbooted root partition[/-] [+]gpt-auto-generator: when dissecting partition table, and multiple root partitions are available, always prefer the one already mounted to / if that exists[/+] on Oct 15, 2024
  6. added 4 commits that reference this issue on Mar 14, 2025
    b267cd1
    21d87a4
    b7e4192
    40bbcc7
  7. added 6 commits that reference this issue on Apr 1, 2025
    690362b
    df47e3e
    26c583e
    bcf7a4a
    2fad9fb
    5d3243b
  8. added a commit that references this issue on Apr 3, 2025
    23e724f
  9. added a commit that references this issue on Apr 3, 2025
    3777c6e
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

    RFE 🎁gpt-autorepart

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions