Commit Graph
544 Commits
Author SHA1 Message Date
Daan De Meyer ea09f92ce4 repart: Remove leftover debug statement 2022-11-29 10:08:51 +01:00
Daan De Meyer cc751c75a0 repart: Move backing_fd, node and from_scratch variables into Context 2022-11-29 10:08:51 +01:00
Daan De Meyer a2d7c42e97 repart: Make sure split partition files are cleaned up on failure 2022-11-29 10:08:51 +01:00
Daan De Meyer 621083481b repart: Refactor split names 2022-11-29 10:08:51 +01:00
Daan De Meyer 7d07030eea repart: Make sure we clean up temporary files created in context_minimize() 2022-11-29 10:08:49 +01:00
Daan De Meyer d3201eb4f4 repart: Prefer using loop devices to populate filesystems when available
Let's make sure we use loop devices if we have access to them and
only fall back to regular files if we can't use loop devices. We
prefer loop devices because when using mkfs --root options, we have
to populate a temporary staging tree which means we're copying every
file twice instead of once when using loop devices.
2022-11-28 10:52:21 +01:00
Daan De Meyer d2ac7698cb repart: Make sure all files in the image are owned by root 2022-11-28 10:46:00 +01:00
Daan De Meyer 8a050905a3 repart: Move comment 2022-11-28 10:46:00 +01:00
Lennart Poettering f8cf3d19d2 fdisk: introduce common fdisk_new_context_fd() helper
We do the same thing over and over again and it's a bit ugly, hence
let's unify the code for it at one common place.
2022-11-26 11:28:05 +09:00
Daan De Meyer 5fe8dbe728 repart: Remove bogus check
The --empty option applies to the partition table of the block
device, not the number of definition files we've read. Also, even
if we don't find any definition files, let's not shortcut execution
so we can run repart on a device/loopback file to get information
on the partition table.
2022-11-26 08:27:41 +09:00
Daan De Meyer 7d505753f1 repart: Add --skip-partitions=
--include-partitions and --exclude-partitions now fully exclude
partitions from repart. Whenever a partition type is excluded, we
don't take any partitions of that type into account at all when
running systemd-repart.

--skip-partitions= is introduced to do what --exclude-partitions did
previously. Any skipped partitions are taken into acount when doing
size calculations, but are not yet populated.

Why do we need both concepts? Exclusion is needed so that we can
use shared repart definitions to generate bootable and non-bootable
images. When generating a non-bootable image, we use --exclude-partitions
to exclude the ESP partition. Skipping is needed so that we can
populate the root partition while skipping the ESP partition, get
the roothash of the root partition, use that to generate a UKI, and
finally populate the ESP partition with the UKI included.
2022-11-25 12:07:38 +01:00
Daan De Meyer 220780db86 repart: Make parse_filter_partitions() more generic 2022-11-23 12:41:23 +01:00
Daan De Meyer d989dd7631 repart: Rename arg_filter_partitions_size to arg_n_filter_partitions 2022-11-23 12:41:23 +01:00
Luca Boccassi 0dce448bbc repart: respect --discard=no also for block devices
It's only used to avoid BLKDISCARD on individual partitions at the moment.
It can take a lot of time to run on very slow devices, so avoid it for
them too.
2022-11-23 01:33:26 +01:00
Daan De Meyer 6b1ea55e0b repart: Rework PartitionTarget initialization 2022-11-21 11:47:13 +01:00
Daan De Meyer 488bb758c0 repart: Use fd based operations in partition_populate_directory() 2022-11-21 11:47:13 +01:00
Daan De Meyer 48b1e18aae repart: Remove redundant parentheses in partition_populate_directory() 2022-11-21 10:53:23 +01:00
Daan De Meyer 922576e452 repart: Use ASSERT_PTR() in partition_encrypt() 2022-11-21 10:45:26 +01:00
Daan De Meyer 983154f518 repart: Use ftruncate() instead of posix_allocate() 2022-11-21 10:44:38 +01:00
Daan De Meyer 766f52f25c repart: Fix parse_filter_partitions() log messages 2022-11-21 10:36:37 +01:00
Daan De Meyer 53538e33e9 repart: Fix FilterPartitionsType enum name 2022-11-21 10:35:18 +01:00
Daan De Meyer 5f59807d2d repart: Rework unused partition number algorithm 2022-11-21 10:34:28 +01:00
Daan De Meyer c1979cd881 repart: Use IN_SET() in one more place 2022-11-21 10:28:36 +01:00
Daan De Meyer 0b75744d5c repart: Write temporary LUKS header to /var/tmp instead of /tmp
This is a relatively large file so let's not create it in memory.
2022-11-17 14:15:28 +01:00
Daan De Meyer dd3c825294 tmpfile-util: Introduce fopen_temporary_child()
Instead of having fopen_temporary() create the file either next
to an existing file or in tmp/, let's split this up clearly into
two different functions, one for creating temporary files next to
existing files, and one for creating a temporary file in a directory.
2022-11-17 14:14:31 +01:00
Daan De Meyer a64769d605 repart: Don't use loop devices when we're not operating on a block device
When repart is not operating on a block device, if we avoid using
any loop devices at all, it becomes possible to run repart without
needing root privileges.

Note that this also depends on the filesystems in use to support
population without needing root privileges (specifically, squashfs,
ext4 or btrfs).
2022-11-15 20:23:51 +01:00
Daan De Meyer 0b34f351d1 repart: Change mode of temporary root to 755
Let's make sure regular users can access read/execute files when
we're populating from a temporary root.
2022-11-15 20:23:51 +01:00
Daan De Meyer 0eb23798d5 repart: Fail early if no sources are provided for a read-only filesystem 2022-11-15 20:23:51 +01:00
Daan De Meyer 2a99f964ff repart: Skip partition_populate_directory() if no sources are provided 2022-11-15 20:23:51 +01:00
Daan De Meyer 6d6cefad37 repart: Fail early if we're missing privileges to populate a filesystem 2022-11-15 20:23:51 +01:00
Daan De Meyer e59678b2cf repart: Ensure files end up owned by root in generated filesystems
By forking off a user namespace before running mkfs and ID mapping
the user running repart to root in the user namespace, we can make
sure that files in the generated filesystems are all owned by root
instead of the user running repart.

To make this work we have to make sure that all the files in the
root directory that's passed to the mkfs binary are owned by the
user running repart, so we have to drop the shortcut for only a
single root directory in partition_populate_directory().
2022-11-15 20:23:51 +01:00
Daan De Meyer cf2ed23cd2 repart: Fix copy failure error message 2022-11-15 20:23:51 +01:00
Daan De Meyer 4ecd39c511 repart: Move verity sig formatting into data partition functions
Refactoring to make implementing rootless repart easier.
2022-11-15 20:23:47 +01:00
Daan De Meyer 2b392d860e repart: Move verity hash formatting into data partition functions
Refactoring to make implementing rootless repart easier.
2022-11-15 20:23:28 +01:00
Daan De Meyer 48a09a8fff repart: Do offline encryption instead of online
Offline encryption can be done without mounting the luks device. For
now we still use loop devices to split out the partition we want to
write to but in a later commit we'll replace this with a regular file.

For offline encryption, we need to keep 2x the luks header size space
free at the end of the partition, so this means our encrypted partitions
will be 16M larger than before.
2022-11-15 20:07:54 +01:00
Daan De Meyer 98e0456ec0 repart: Let libcryptsetup calculate the volume key
We also bump the volume key size to 512 bits.
2022-11-15 20:07:54 +01:00
Daan De Meyer 59e2be46cc mkfs-util: Add root support for ext and btrfs
For these filesysrems, it's useful to provide the filesystem upfront
so that we don't have to mount it later which requires root privileges.
2022-11-15 20:07:54 +01:00
Daan De Meyer 81d1098bc1 repart: Add --include/--exclude-partitions
Let's allow filtering the partitions to operate on by partition
type UUID. This is necessary when building bootable images with a
verity protected root/usr partition as we can only build the UKI
image when we have the verity roothash which means we cannot populate
the EFI partition yet when we run repart initially to determine the
verity roothash.
2022-11-15 13:45:25 +01:00
Daan De Meyer 00428745e3 repart: Use first unused partition number for new partitions
If we skip some partition types in a first run of systemd-repart,
we don't want their partition numbers to be different than usual,
so let's change the allocation of partition numbers to account for
that.
2022-11-15 13:27:59 +01:00
Daan De Meyer 22e932f4d1 gpt: Expose GptPartitionType and get rid of SECONDARY/OTHER
Instead of exposing just the partition type UUID, let's expose the
GptPartitionType struct, which has a lot more information available
in a much more accessible way.

Also, let's get rid of SECONDARY/OTHER in PartitionDesignator. These
were only there to support preferred architectures in dissect-image.c,
but we can easily handle that by comparing architectures when we decide
whether to override a partition. This is done in a new function
compare_arch().
2022-11-15 13:27:15 +01:00
Li kunyu bef69ae878 repart: Remove the repeated ';' from code (#25386) 2022-11-15 17:02:51 +09:00
Daan De Meyer 32a3f802f6 Merge pull request #24908 from DaanDeMeyer/repart-minimize
repart: Add Minimize setting
2022-11-15 08:19:28 +01:00
Lennart Poettering 7f77b40011 repart: fix build
Follow-up for: 12e2b70f9b
2022-11-11 19:01:59 +01:00
Daan De Meyer c4a87b76c3 repart: Take into account minimal filesystem size
Instead of requiring users to guess the required space for partitions
populated with CopyFiles=, let's make an educated guess ourselves. We
can populate the filesystem once in a very large sparse file and see
how much data is actually used as a good indicator of the required size.
2022-11-11 14:33:19 +01:00
Daan De Meyer b262cbe871 repart: Use ULL for all size constants 2022-11-11 13:49:50 +01:00
Daan De Meyer 585c5c756f repart: Allow custom root directory per copy blocks source
Preparation for the next commit
2022-11-11 13:49:50 +01:00
Daan De Meyer a7f1f7d8c1 repart: Don't log partition number when populating filesystem
This might not be known yet so let's use the filesystem itself
instead.
2022-11-11 13:49:50 +01:00
Daan De Meyer 7c17515203 repart: Create loop device when populating filesystems if needed 2022-11-11 13:49:49 +01:00
Daan De Meyer 143c3c08d7 repart: Move fstype_is_ro() checks out of the populate functions
Preparation for the next commit.
2022-11-11 13:49:22 +01:00
Daan De Meyer 8bbbdfd788 repart: Calculate filesystem UUID earlier 2022-11-11 13:48:21 +01:00