Skip to content

systemd-repart cannot CopyBlocks=auto for usr-verity partition #32029

Closed

Description

@septatrix

systemd version the issue has been seen with

systemd-255.4-1.fc40.x86_64

Used distribution

Fedora 40

Linux kernel version used

6.8.1-300.fc40.x86_64

CPU architectures issue was seen on

x86_64

Component

systemd-repart

Expected behaviour you didn't see

systemd-repart should detect the usr-verity partition and copy it to the destination.

Continuation from https://lists.freedesktop.org/archives/systemd-devel/2024-March/050152.html

Unexpected behaviour you saw

systemd-repart is unable to find the correct partition and fails with the message:

Unable to automatically discover suitable partition to copy blocks from.

Steps to reproduce the problem

Clone https://github.com/septatrix/systemd-issue and run the test script.

The test script also contains another workaround using VerityMatchKey= only copying the usr partition and creating the hash anew however this results in a different root hash without any obvious reason.

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

Failed to find TPM2 pcrlock policy file 'pcrlock.json': No such file or directory
Opened '/run/user/1000/tmp.w077B7QbJH/image-copy' in O_RDONLY access mode, with O_DIRECT enabled.
Determined sector size 512 based on discovered partition table.
loop0: Acquired exclusive lock.
Successfully acquired /dev/loop0, devno=7:0, nr=0, diskseq=352
Kernel was quicker than us in adding partition 1.
Opened /dev/loop0p1 (fd=3, whole_block_devnum=7:0, diskseq=352).
Kernel was quicker than us in adding partition 2.
Opened /dev/loop0p2 (fd=4, whole_block_devnum=7:0, diskseq=352).
Kernel was quicker than us in adding partition 3.
Opened /dev/loop0p3 (fd=7, whole_block_devnum=7:0, diskseq=352).
Probed fstype 'erofs' on partition /dev/loop0p2.
Mounting rootfs (tmpfs) on /run/systemd/mount-rootfs (MS_NODEV "")...
Mounting /proc/self/fd/4 (erofs) on /run/systemd/mount-rootfs/usr (MS_RDONLY|MS_NODEV "")...
Mounting /proc/self/fd/3 (vfat) on /run/systemd/mount-rootfs/efi (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOSYMFOLLOW "umask=0077")...
Sized 'a-copy' to 55.0M.
Not resizing partition table, as there currently is none.
Sector size of device is 512 bytes. Using grain size of 4096.
No machine ID set, using randomized partition UUIDs.
Automatically found partition 259:5 of right type 8484680c952148c69c11b0720656f69e.
Partition 259:5 has non-matching partition type 8484680c952148c69c11b0720656f69e (needed: 77ff5f63e7b64633acf41565b864c0e6), ignoring.
Unable to automatically discover suitable partition to copy blocks from.
Failed to umount /run/systemd/mount-rootfs, ignoring: Device or resource busy
Failed to umount /run/systemd/mount-rootfs, ignoring: Device or resource busy

Activity

  1. added
    bug 🐛
    on Mar 31, 2024
  2. septatrix commented on Apr 5, 2024

    @septatrix
    ContributorAuthor

    I tried a workaround to create the partitions as empty partitions and then fill them using sd-sysupdate though that failed with the message File system type not supported or not known.. The only method apart from manually fiddling with parted or a similar tool is to manually create definition files for repart:

    [Partition]
    Label=DSPlayerOS_2.4.0
    UUID=2b3d1236340c8ff3b24d27cce57ecbb5
    SizeMaxBytes=8G
    CopyBlocks=/partitions.d/DSPlayerOS_2.4.0._2b3d1236340c8ff3b24d27cce57ecbb5.usr-x86-64.raw
    
    # same thing for verity partition

    While this works it is very ugly and quite annoying to automate. Furthermore this requires me to create split artifacts of the image.

  3. septatrix commented on Apr 25, 2024

    @septatrix
    ContributorAuthor

    From the mailinglist:

    Pretty sure nobody ever tried this. The root hash might be changing
    because we format the verity hash partition with different parameters
    than it was originally formatted with in your case. I assume the
    roothash will only stay the same if the verity format arguments are
    exactly the same. We'd probably accept PRs to allow configuring more
    verity arguments to support this use case
    ~ Daan

    @daandemeyer what exactly would those arguments be and can I log or compare them somehow?

  4. septatrix commented on Oct 17, 2024

    @septatrix
    ContributorAuthor

    Interestingly it turns out that the amount of data blocks differs...

    # veritysetup dump /dev/loop0p3 # image-match
    VERITY header information for /dev/loop0p3
    UUID:                   5944df34-a3ea-4e7a-8e01-dfa4d285817d
    Hash type:              1
    Data blocks:            1
    Data block size:        4096
    Hash blocks:            0
    Hash block size:        4096
    Hash algorithm:         sha256
    Salt:                   bd6fa20b4bf52d5563b69b391c1bd5b995469c46bd4d81f80ded0e3bdc6ecc68
    Hash device size:       4096 [bytes]
    
    # veritysetup dump /dev/loop1p3 # a-match
    VERITY header information for /dev/loop1p3
    UUID:                   5944df34-a3ea-4e7a-8e01-dfa4d285817d
    Hash type:              1
    Data blocks:            7163
    Data block size:        4096
    Hash blocks:            57
    Hash block size:        4096
    Hash algorithm:         sha256
    Salt:                   bd6fa20b4bf52d5563b69b391c1bd5b995469c46bd4d81f80ded0e3bdc6ecc68
    Hash device size:       237568 [bytes]
  5. septatrix commented on Oct 17, 2024

    @septatrix
    ContributorAuthor

    The root hash might be changing because we format the verity hash partition with different parameters than it was originally formatted with in your case.

    One thing which I had to manually add was the --seed, as sd-repart does not extract the seed from the previous verity partition which I guess makes sense but is definitely something one has to watch out for.

  6. daandemeyer commented on Sep 24, 2025

    @daandemeyer
    Collaborator

    I think this was fixed by #36631

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