summaryrefslogtreecommitdiff
path: root/src/shared/mkfs-util.c
Commit message (Collapse)AuthorAgeFilesLines
* mkfs-util: Add quiet argument to make_filesystem()Daan De Meyer2023-05-121-12/+29
| | | | | | | | We default to quiet operation everywhere except for repart, where we disable quiet and have the mkfs tools write to stdout. We also make sure --quiet or equivalent is implemented for all mkfs tools.
* repart: Add more loggingDaan De Meyer2023-04-061-0/+7
|
* mkfs-util: Redirect mksquashfs output to /dev/nullDaan De Meyer2023-03-151-3/+5
| | | | | | The -quiet option for mksquashfs was added somewhat recently so to support older versions, let's redirect stdout of mksquashfs to /dev/null instead.
* mkfs-util: Redirect mkfs.vfat stdout to /dev/nullDaan De Meyer2023-03-121-1/+12
| | | | | mkfs.vfat does not have a --quiet option so let's redirect its stdout to /dev/null instead.
* mkfs-util: Don't explicitly enable has_journal for ext3/ext4Daan De Meyer2023-03-121-19/+1
| | | | | It's enabled by default anyway and removing it allows merging the ext conditionals into one.
* mkfs-util: Always use "default" usage type for ext filesystemsDaan De Meyer2023-03-121-0/+2
| | | | | | | | If no usage type is explicitly specified, ext will choose one based on the filesystem size. Let's override this and always use the "default" usage type so that we can create filesystems that are initially small but might grow later without opting in to the "small" usage type.
* repart: Add support for reading mkfs options from environmentDaan De Meyer2023-03-101-0/+21
|
* Revert "repart: Ensure files end up owned by root in generated filesystems"Daan De Meyer2023-01-231-49/+2
| | | | | | | | | | | This reverts commit e59678b2cf42e4206ddabc959d3cf9a5a865ecdc. We also modify the repart integration tests to make them pass with the changes in this commit. In short, we have to make sure every file is owned by the user executing repart. We use tee instead of cat since it makes that easier. This also has the benefit of improving debugability as seeing the config file contents on stdout makes it easier to know which test is failing.
* repart: Allow configuring sector sizeDaan De Meyer2023-01-171-2/+21
| | | | | | Let's allow users to configure the (logical) sector size of their image. This is required when building images for a 4k sector size disk on a 512b sector size host or vice-versa.
* mkfs-util: Shorten strv operations error handlingDaan De Meyer2023-01-171-36/+15
|
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* Implement SYSTEMD_HOME_MKFS_OPTIONS_* envvars to configure mkfs options for ↵Aidan Dang2022-12-151-1/+8
| | | | homed LUKS directories
* repart: support erofsLennart Poettering2022-12-101-0/+17
| | | | | | | | | | | | | | | So, i think "erofs" is probably the better, more modern alternative to "squashfs". Many of the benefits don't matter too much to us I guess, but there's one thing that stands out: erofs has a UUID in the superblock, squashfs has not. Having an UUID in the superblock matters if the file systems are used in an overlayfs stack, as overlayfs uses the UUIDs to robustly and persistently reference inodes on layers in case of metadata copy-up. Since we probably want to allow such uses in overlayfs as emplyoed by sysext (and the future syscfg) we probably should ramp up our erofs game early on. Hence let's natively support erofs, test it, and in fact mention it in the docs before squashfs even.
* mkfs-util: fix memleakYu Watanabe2022-11-301-1/+3
| | | | | | Fixes an issure introduced by c75cf0164cbd69104f13cbe7be42ab639953bd7d. Fixes CID#1501073.
* mkfs-util: Drop batch (b) and n flags from mcopyDaan De Meyer2022-11-251-1/+1
| | | | | | | | | | | | | | | | The batch flag is bugged on older versions of mcopy causing failures such as: ``` Internal error, size too big Streamcache allocation problem:: 5 ``` It's also a little unclear what the batch flag actually does, so since everything still works without it, it doesn't hurt to remove it. The n flag only applies when copying from fat to unix which we don't do so it doesn't make sense in this scenario.
* Merge pull request #25500 from DaanDeMeyer/mcopy-skip-symlinksDaan De Meyer2022-11-241-8/+18
|\ | | | | mkfs-util: Skip symlinks when calling mcopy
| * mkfs-util: Skip non files/directories when calling mcopyDaan De Meyer2022-11-241-8/+18
| | | | | | | | | | | | | | | | | | | | | | Only files and directories are supported by vfat. When we pass a symlink to mcopy, it will try to dereference them and copy what the symlink points at into the vfat partition instead. Let's avoid this by skipping all unsupported file types when establishing the list of top level targets that mcopy should copy. We also use RECURSE_DIR_SORT everywhere when iterating directories to make things more reproducible.
* | mkfs-util: Check if mcopy is installedDaan De Meyer2022-11-241-2/+9
|/
* mkfs-util: Use FORK_CLOSE_ALL_FDSDaan De Meyer2022-11-211-2/+2
|
* mkfs-util: Prefer fd based stat() where possibleDaan De Meyer2022-11-211-1/+1
|
* mkfs-util: Use GID_FMTDaan De Meyer2022-11-211-2/+2
|
* Followups for aa6aa81c1e2fa0d35f91545d440ce5a31e1a43dfDaan De Meyer2022-11-171-20/+19
|
* tmpfile-util: Introduce fopen_temporary_child()Daan De Meyer2022-11-171-1/+1
| | | | | | | 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.
* mkfs-util: Add support for rootless xfs populationDaan De Meyer2022-11-161-1/+105
| | | | | | We use mkfs.xfs's protofile (-p) support to achieve this. The protofile is a description of the files that should be copied into the filesystem. The format is described in the manpage of mkfs.xfs.
* repart: Ensure files end up owned by root in generated filesystemsDaan De Meyer2022-11-151-1/+49
| | | | | | | | | | | | 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().
* mkfs-util: Add support to populate vfat without mounting using mcopyDaan De Meyer2022-11-151-1/+63
| | | | | | | | mkfs.vfat doesn't support specifying a root directory to bootstrap the filesystem from (see https://github.com/dosfstools/dosfstools/issues/183). Instead, we can use the mcopy tool from the mtools package to copy files into the vfat filesystem after creating it without needing to mount the vfat filesystem.
* mkfs-util: Add root support for ext and btrfsDaan De Meyer2022-11-151-5/+29
| | | | | 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.
* mkfs-util: Make argument handling for mkfs binaries more flexibleDaan De Meyer2022-11-151-83/+99
| | | | Preparation for the next commit.
* shared: Don't try to generate read-only filesystem that we don't supportDaan De Meyer2022-09-231-0/+4
| | | | | | | | We need explicit support to generate read-only filesystems, since we always need to pass a source tree to the mkfs binary to populate the filesystem. As such, let's add an explicit check to return a recognizable error when users try to generate a read-only filesystem that we don't support.
* repart: Extend squashfs logic to all read-only filesystemsDaan De Meyer2022-09-231-5/+7
| | | | | | The same logic will apply to every read-only filesystem that we might add support for in the future, so let's make this a bit more future proof.
* shared: Add squashfs support to make_filesystem()Daan De Meyer2022-09-211-0/+24
| | | | | The caveat is that the caller has to provide a source directory to initialize the squashfs filesystem from.
* sd128: export sd_id128_to_uuid_string()Lennart Poettering2022-02-141-2/+2
| | | | | | | | | We expose various other forms of UUID helpers already, i.e. SD_ID128_UUID_FORMAT_STR and SD_ID128_MAKE_UUID_STR(), and we parse UUIDs, hence add a high-level helper for formatting UUIDs too. This doesn't add any new code, it just moves some helpers id128-util.[ch] → sd-id128.[ch], to make them public.
* makefs: add "support" for f2fsZbigniew Jędrzejewski-Szmek2021-11-161-1/+12
| | | | | | | | | | | | | The man page doesn't quite match what --help says, and I needed to use "-f" to write a wiped partition. This all feels a bit experimental, but the fs has some adherents, and we should make it easy to use. (Also, an empty 256MB device formatted and mounted shows up as Filesystem Size Used Avail Use% Mounted on /dev/loop0 254M 85M 170M 34% /var/tmp/mount which also seems a bit over the top…) Requested in https://github.com/systemd/systemd/pull/21275#issuecomment-967928690.
* makefs: fix too-long swap labelsZbigniew Jędrzejewski-Szmek2021-11-161-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Apparently mkswap has it's own limit, and it seems to be one lower than the one for ext2/3/4. $ for i in ext2 ext3 ext4 btrfs xfs vfat swap minix; do echo $i && wipefs -q -a '/var/tmp/głąbźśńćąśððð.img' build/systemd-makefs $i '/var/tmp/głąbźśńćąśððð.img' done ext2 /var/tmp/głąbźśńćąśððð.img successfully formatted as ext2 (label "głąbźśńćą", uuid 7626bc5c-8ac4-43cf-87b7-1b2761272dd3) ext3 /var/tmp/głąbźśńćąśððð.img successfully formatted as ext3 (label "głąbźśńćą", uuid 0da22cad-0dbf-4a7a-962d-12cd39d006b5) ext4 /var/tmp/głąbźśńćąśððð.img successfully formatted as ext4 (label "głąbźśńćą", uuid dded267b-8955-4d19-82a5-1f231d446059) btrfs /var/tmp/głąbźśńćąśððð.img successfully formatted as btrfs (label "głąbźśńćąśððð.img", uuid 9e2e89f1-010d-4ab6-80f3-f9e215dbc225) xfs /var/tmp/głąbźśńćąśððð.img successfully formatted as xfs (label "głąbźśń", uuid 2cc937af-4c41-465c-8f52-aab2304bd860) vfat mkfs.fat 4.2 (2021-01-31) /var/tmp/głąbźśńćąśððð.img successfully formatted as vfat (label "G__B_______", uuid a3a9e028) swap ... LABEL=głąbźśńć, UUID=0ab787aa-37a6-4b32-978b-d71efc6e6098 /var/tmp/głąbźśńćąśððð.img successfully formatted as swap (label "głąbźśńć", uuid 0ab787aa-37a6-4b32-978b-d71efc6e6098) minix ... /var/tmp/głąbźśńćąśððð.img successfully formatted as minix (no label or uuid specified)
* makefs: fix too-long ext2/3/4 labelsZbigniew Jędrzejewski-Szmek2021-11-161-1/+37
|
* makefs: fix label for vfat filesystemsZbigniew Jędrzejewski-Szmek2021-11-161-7/+30
| | | | | | I was testing with a "test1.img" and mkfs.vfat rejects "TEST1.IMG" with the error "Labels with characters *?.,;:/\|+=<>[]" are not allowed". So let's replace those characters with "_".
* makefs: supress mkfs output, but print one line on successZbigniew Jędrzejewski-Szmek2021-11-121-21/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | $ for i in ext2 ext3 ext4 btrfs xfs vfat swap minix; do echo $i && wipefs -q -a /var/tmp/test2_img && build/systemd-makefs $i /var/tmp/test2_img done ext2 /var/tmp/test2_img successfully formatted as ext2 (label "test2_img", uuid ad584a5b-037b-497a-825d-eaf2ba90da2d) ext3 /var/tmp/test2_img successfully formatted as ext3 (label "test2_img", uuid 95239fff-55f4-44d5-bae0-11ef75d13166) ext4 /var/tmp/test2_img successfully formatted as ext4 (label "test2_img", uuid 8c7ea699-05ab-4ce6-8df6-bc20d53dfd29) btrfs /var/tmp/test2_img successfully formatted as btrfs (label "test2_img", uuid 860bb061-4d92-4607-8821-a9d00216490e) xfs /var/tmp/test2_img successfully formatted as xfs (label "test2_img", uuid f32499ea-7311-47bb-be57-da62e51d33ae) vfat mkfs.fat 4.2 (2021-01-31) /var/tmp/test2_img successfully formatted as vfat (label "TEST2_IMG", uuid d1e4ae63) swap mkswap: /var/tmp/test2_img: insecure permissions 0644, fix with: chmod 0600 /var/tmp/test2_img mkswap: /var/tmp/test2_img contains holes or other unsupported extents. This swap file can be rejected by kernel on swap activation! Use --verbose for more details. Setting up swapspace version 1, size = 256 MiB (268431360 bytes) LABEL=test2_img, UUID=16bc3d8c-98d4-462b-8ff8-338467cde871 /var/tmp/test2_img successfully formatted as swap (no label or uuid specified) minix 21856 inodes 65535 blocks Firstdatazone=696 (696) Zonesize=1024 Maxsize=268966912 /var/tmp/test2_img successfully formatted as minix (no label or uuid specified)
* makefs: also set uuid/label for ext2/ext3Zbigniew Jędrzejewski-Szmek2021-11-091-1/+10
| | | | | | | | | | | | We were only "supporting" ext4. Let's add "support", i.e. pass our optimization options and uuid/label for the other two fses in the same family. Nowadays there is separate code in the kernel, all three fs types are handled by ext4 code. ext2 in particular is useful for in-memory devices: the journal is just a waste of space there. ext3 is added for completeness mostly, since ext4 should probably be used instead. But people might use it for testing or for compatibility with older systems and I don't see much reason to not add "support" here.
* makefs: reindent mkfs calls to follow the same styleZbigniew Jędrzejewski-Szmek2021-11-091-9/+15
| | | | I think this also makes it much easier to see what args are passed.
* variuos: add missing includesZbigniew Jędrzejewski-Szmek2021-09-221-0/+2
|
* tree-wide: port everything over to new sd-id128 compund literal blissLennart Poettering2021-08-201-17/+13
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Rename find_binary to find_executableZbigniew Jędrzejewski-Szmek2020-09-181-2/+2
| | | | "executable" is more correct than "binary", since scripts are OK too.
* mkfs-util: add support for making vfat partitionsLennart Poettering2020-08-241-0/+21
| | | | | | | fat is a bit more limited in volume name length and UUID support. Let's add some special support for it. This is particularly useful to generate EFI system partitions.
* shared: introduce mkfs-util.c/.hLennart Poettering2020-08-241-0/+114
Let's move the "mkfs" code from homed there, plus other related code. This way we can easily reuse it from other places.