1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00
systemd/units/systemd-repart.service

38 lines
1.3 KiB
SYSTEMD
Raw Normal View History

# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Repartition Root Disk
Documentation=man:systemd-repart.service(8)
ConditionVirtualization=!container
ConditionDirectoryNotEmpty=|/usr/lib/repart.d
ConditionDirectoryNotEmpty=|/usr/local/lib/repart.d
ConditionDirectoryNotEmpty=|/etc/repart.d
ConditionDirectoryNotEmpty=|/run/repart.d
ConditionDirectoryNotEmpty=|/sysusr/usr/lib/repart.d
ConditionDirectoryNotEmpty=|/sysusr/usr/local/lib/repart.d
DefaultDependencies=no
Wants=modprobe@loop.service modprobe@dm_mod.service
After=initrd-usr-fs.target modprobe@loop.service modprobe@dm_mod.service systemd-tpm2-setup-early.service
Before=initrd-root-fs.target
units/systemd-repart: stop pretending that root config is executed in the initrd I have a system with /usr/lib/repart.d/50-root.conf with GrowFileSystem=yes. The partition wouldn't be resized in the initrd, because ConditionDirectoryNotEmpty=|/sysusr/usr/lib/repart.d was evaluated very early, before /sysroot was mounted. There was no ordering dependency between systemd-repart.service and sysroot.mount. (There was After=initrd-usr-fs.target, but it seems to be only referred to by systemd-fstab-generator, which in my case doesn't even run, because there's no fstab.) But in fact, we neeed to run systemd-repart in the initrd only in limited circumstances: when we need to create the root device based on config under sysusr.mount. If there is config on the root device, it can be executed in the host system, early during boot. Thus, let's remove the condition on /sysroot/…. Without an ordering dependency on sysroot.mount, it was subject to a race condition anyway. (A race condition with a low probability of "winning", because systemd-repart.service has no dependencies, but sysroot.mount requires a device to be detected and the mount to happen.) The other problem was that systemd-repart.service didn't have the ordering wrt. initrd-switch-root.target, so it was subject to the same race condition that was fixed for other units in 7c0e2b555968d70ac563a37e32a6931ee90961a6. (If the systemd-repart.service/stop job is slow, we could end up not restarting systemd-repart.service in the host system.) With the changes here, I see systemd-repart.service/start running twice: in the initrd it is skipped because the conditions fail, and then in the host system it runs normally. Note: support for /sysroot is retained in systemd-repart code. I don't see a strong reason to remove it, since it may still be useful to people invoking repart in the initrd in other circumstances.
2022-09-15 17:12:05 +03:00
Conflicts=shutdown.target initrd-switch-root.target
Before=shutdown.target initrd-switch-root.target
[Service]
Type=oneshot
RemainAfterExit=yes
2024-03-08 20:08:50 +03:00
ExecStart=systemd-repart --dry-run=no
# The tool returns 76 if it can't find the root block device
SuccessExitStatus=76
# The tool returns 77 if there's no existing GPT partition table
SuccessExitStatus=77