Commit Graph

209 Commits

Author SHA1 Message Date
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 75f86906c5 basic: rework virtualization detection API
Introduce a proper enum, and don't pass around string ids anymore. This
simplifies things quite a bit, and makes virtualization detection more
similar to architecture detection.
2015-09-07 13:42:47 +02:00
Karel Zak bf1d7ba70a swap: use swapon -o
This patch simplify swapon usage in systemd. The command swapon(8)
since util-linux v2.26 supports "-o <list>". The idea is exactly the
same like for mount(8). The -o specifies options in fstab-compatible
way. For systemd it means that it does not have to care about things
like "discard" or another swapon specific options.

        swapon -o <options-from-fstab>

For backward compatibility the code cares about "Priority:" swap unit
field (for a case when Priority: is set, but pri= in the Options: is
missing).

References: http://lists.freedesktop.org/archives/systemd-devel/2014-October/023576.html
2015-05-25 17:06:15 +02:00
Karel Zak 3519d230c8 fstab-generator: add x-systemd.requires and x-systemd.requires-mounts-for
Currently we have no way how to specify dependencies between fstab
entries (or another units) in the /etc/fstab. It means that users are
forced to bypass fstab and write .mount units manually.

The patch introduces new systemd fstab options:

x-systemd.requires=<PATH>

 - to specify dependence an another mount (PATH is translated to unit name)

x-systemd.requires=<UNIT>

 - to specify dependence on arbitrary UNIT

x-systemd.requires-mounts-for=<PATH ...>

 - to specify dependence on another paths, implemented by
   RequiresMountsFor=. The option may be specified more than once.

For example two bind mounts where B depends on A:

 /mnt/test/A    /mnt/test/A     none    bind,defaults
 /mnt/test/A    /mnt/test/B     none    bind,x-systemd.requires=/mnt/test/A

More complex example with overlay FS where one mount point depends on
"low" and "upper" directories:

 /dev/sdc1   /mnt/low    ext4     defaults
 /dev/sdc2   /mnt/high   ext4     defaults
 overlay     /mnt/merged overlay  lowerdir=/mnt/low,upperdir=/mnt/high/data,workdir=/mnt/high/work,x-systemd.requires-mounts-for=/mnt/low,x-systemd.requires-mounts-for=mnt/high

https://bugzilla.redhat.com/show_bug.cgi?id=812826
https://bugzilla.redhat.com/show_bug.cgi?id=1164334
2015-05-18 16:07:52 +02:00
Zbigniew Jędrzejewski-Szmek 4652c56c59 Use fflush_and_check() in more places 2015-05-16 18:11:32 -04:00
Lennart Poettering 7410616cd9 core: rework unit name validation and manipulation logic
A variety of changes:

- Make sure all our calls distuingish OOM from other errors if OOM is
  not the only error possible.

- Be much stricter when parsing escaped paths, do not accept trailing or
  leading escaped slashes.

- Change unit validation to take a bit mask for allowing plain names,
  instance names or template names or an combination thereof.

- Refuse manipulating invalid unit name
2015-05-05 15:06:42 -07:00
Zbigniew Jędrzejewski-Szmek 2e8522767e generators: rename add_{root,usr}_mount to add_{sysroot,sysroot_usr}_mount
This makes it obvious that those functions are only usable in the
initramfs.

Also, add a warning when noauto, nofail, or automount is used for the
root fs, instead of silently ignoring. Using those options would be a
sign of significant misconfiguration, and if we bother to check for
them, than let's go all the way and complain.

Other various small cleanups and reformattings elsewhere.
2015-05-04 08:45:07 -04:00
Zbigniew Jędrzejewski-Szmek 336b5c615e fstab-generator: fix memleak
filtered was used to store an allocated string twice. The first allocation was
thus lost. The string is not needed for anything, so simply skip the allocation.

Fixup for deb0a77cf0.
2015-05-02 13:01:28 -04:00
Michael Olbrich deb0a77cf0 automount: add expire support 2015-04-21 20:23:41 +02:00
Lennart Poettering 171181bcd6 fstab-generator: don't continue on OOM 2015-04-08 20:27:11 +02:00
Tobias Hunger 093c2cfe3b fstab-generator: don't accept missing root=, but accept root=none
And other non-device entries (like fstab does).

Mount whatever the user asked to be mounted on / on the kernel
command line. Do less sanity check and do *not* bail out
when the mount device looks strange or does not exist.

This basically makes the changes for deviceless filesystems
from yesterday unnecessary and is in line with what we do for
filesystems set up in fstab.

Remove some code that is now dead (reverting fb02a2775a and
b0438462).

[tomegun:
  - change patch title/description a bit.
  - don't touch the /usr logic, that would be a separate change and
    we don't currently have a convincing use-case for that.
  - don't bail out on /sys ro. This only makes sense in containers,
    where we would not be doing this anyway. If there is a use-case
    we could consider that as a separate patch.]
2015-03-25 00:00:46 +01:00
Tobias Hunger b043846208 fstab-generator: Support root on tmpfs (or other deviceless FS)
This allows for stateless systems.
2015-03-24 00:12:03 -04:00
Zbigniew Jędrzejewski-Szmek e0952d9d02 fstab-generator: ignore invalid swap priority
A failed priority is not something worth stopping boot over. Most people
have only one swap device, in which case priority is irrelevant, and even
if there is more than one swap device, they are all usable, and ignoring the
priority field should only result in some loss of performance.

The kernel will report the priority as -1 if not set, so it's easy for
people to make this mistake.

https://bugzilla.redhat.com/show_bug.cgi?id=1204336
2015-03-21 11:54:46 -04:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Zbigniew Jędrzejewski-Szmek b9f111b93f Support negated fstab options
We would ignore options like "fail" and "auto", and for any option
which takes a value the first assignment would win. Repeated and
options equivalent to the default are rarely used, but they have been
documented forever, and people might use them. Especially on the
kernel command line it is easier to append a repeated or negated
option at the end.
2015-01-11 23:41:41 -05:00
Zbigniew Jędrzejewski-Szmek d15d0333be Add new function to filter fstab options
This fixes parsing of options in shared/generator.c. Existing code
had some issues:

- it would treate whitespace and semicolons as seperators. fstab(5)
  is pretty clear that only commas matter. And the syntax does
  not allow for spaces to be inserted in the field in fstab.
  Whitespace might be escaped, but then it should not seperate
  options. Treat whitespace and semicolons as any other character.
- it assumed that x-systemd.device-timeout would always be followed
  by "=". But this is not guaranteed, hasmntopt will return this
  option even if there's no value. Uninitialized memory could be read.
- some error paths would log, and inconsistently, some would just
  return an error code.

Filtering is split out to a separate function and tests are added.

Similar code paths in other places are adjusted to use the new function.
2015-01-11 23:41:41 -05:00
Lennart Poettering 00b4ffdecb fstab-generator: use more appropriate checks for swap and device availability
We always should use the same checks when deciding whether swap support
and mounting of devices is supported. Hence, let's make
fstab-generator's logic more similar to the usual logic we follow:

a) Look for /proc/swaps and no container support before activating
swaps.

b) Look for /sys being writable befire supporting device mounts.
2015-01-05 12:35:08 +01:00
Michael Marineau eb5800026d fstab-generator: Allow mount.usr without mount.usrflags, honor rw/ro
There is no need to require mount.usrflags. The original implementation
assumed that a btrfs subvolume would always be needed but that is not
applicable to systems that do not use btrfs for /usr.

Similar to using rootflags= for the default of mount.usrflags=, append
the classic 'ro' and 'rw' flags to the mount options.
2014-12-09 02:24:26 +01:00
Lennart Poettering 59cfa62f20 fstab-generator: free all allocated strings 2014-12-09 02:22:44 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt 23bbb0de4e treewide: more log_*_errno + return simplifications 2014-11-28 18:24:30 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Zbigniew Jędrzejewski-Szmek 5607d856b8 swap: restore support for nofail
systemd stops adding automatic dependencies on swap.target to swap
units. If a dependency is required, it has to be added by unit
configuration. fstab-generator did that already, except that now it is
modified to create a Requires or Wants type dependency, depending on
whether nofail is specified in /etc/fstab. This makes .swap units
obey the nofail/noauto options more or less the same as .mount units.

Documentation is extended to clarify that, and to make
systemd.mount(5) and system.swap(5) more similar. The gist is not
changed, because current behaviour actually matches existing
documentation.

https://bugs.freedesktop.org/show_bug.cgi?id=86488
2014-11-26 15:17:07 -05:00
Lennart Poettering b5884878a2 util: simplify proc_cmdline() to reuse get_process_cmdline()
Also, make all parsing of the kernel cmdline non-fatal.
2014-11-07 01:19:56 +01:00
Harald Hoyer 3f85ef0f05 s/commandline/command line/g 2014-11-06 15:34:18 +01:00
Lennart Poettering 47cb901e38 swap: replace Discard= setting by a more generic Options= setting
For now, it's systemd itself that parses the options string, but as soon
as util-linux' swapon can take the option string directly with -o we
should pass it on unmodified.
2014-10-28 14:31:25 +01:00
Tobias Hunger 9f103625b1 fstab-generator: Honor mount.usr*= on kernel command line
This allows to configure boot loader entries for systems where the
root and usr filesystems are in different subvolumes (or even on
different drives).
2014-10-10 12:57:19 +02:00
Tobias Hunger f88dc3edeb fstab-generator: Small cleanup 2014-10-03 20:42:09 -04:00
Zbigniew Jędrzejewski-Szmek 4f52d3fe2d fstab-generator: properly deal with discard as non-last option
Previous code would only return correct results when discard
was the last option.

While at it, avoid incorrect behaviour for (invalid) 'pri' option
not followed by '=...', and also do not return -1 as the error code.
2014-09-29 11:08:12 -04:00
Jan Synacek 86b23b07c9 swap: introduce Discard property
Process possible "discard" values from /etc/fstab.
2014-09-29 11:08:12 -04:00
Dave Reisner 8085f163c5 util: allow strappenda to take any number of args
This makes strappenda3 redundant, so we remove its usage and
definition. Add a few tests along the way for sanity.
2014-08-13 20:41:41 -04:00
Zbigniew Jędrzejewski-Szmek 126cc76074 fstab-generator: fix trivial leak 2014-07-07 18:36:55 -04:00
Zbigniew Jędrzejewski-Szmek b3208b6629 fstab-generator: allow x-systemd.device-timeout for swap units 2014-06-30 18:39:45 -04:00
Zbigniew Jędrzejewski-Szmek 2968644080 Move x-systemd-device.timeout handling from core to fstab-generator
Instead of adjusting job timeouts in the core, let fstab-generator
write out a dropin snippet with the appropriate JobTimeout.
x-systemd-device.timeout option is removed from Options= line
in the generated unit.

The functions to write dropins are moved from core/unit.c to
shared/dropin.c, to make them available outside of core.

generator.c is moved to libsystemd-label, because it now uses
functions defined in dropin.c, which are in libsystemd-label.
2014-06-30 18:39:45 -04:00
Zbigniew Jędrzejewski-Szmek 75a59316ea fstab-generator: simplify add_root_mount 2014-06-23 23:14:54 -04:00
Lennart Poettering 8501384436 stop complaining about unknown kernel cmdline options
Also stop warning about unknown kernel cmdline options in the various
tools, not just in PID 1
2014-06-19 16:55:20 +02:00
Lennart Poettering 689aede8c6 fstab-generator: when running in a container, ignore fstab entries referring to device nodes
Since these device nodes will never appear in the container anyway
there's no point in waiting for them.

This makes it easier to boot images generated with general purpose
installers like Anaconda which unconditionally populate /etc/fstab to
boot in containers.
2014-03-11 18:02:27 +01:00
Lennart Poettering 5ecdcf41cb fstab-generator: the root partition is not optional 2014-03-07 02:40:24 +01:00
Lennart Poettering 6db615c17e fstab-generator: merge /proc/cmdline parsing loops into one 2014-03-07 02:40:24 +01:00
Lennart Poettering c3834f9b88 generators: add Documentation= fields that point to the generator man pages 2014-03-06 18:48:22 +01:00
Lennart Poettering 059cb3858a util: move more intellegince into parse_proc_cmdline()
Already split variable assignments before invoking the callback. And
drop "rd." settings if we are not in an initrd.
2014-03-06 18:48:22 +01:00
Lennart Poettering e48fdd8443 generators: rework mount generators
- Add support for finding and mounting /srv based on GPT data, similar
  to how we already handly /home.

- Share the fsck logic between GPT, EFI and fstab generators

- Make sure we never run the EFI generator inside containers

- Drop DefaultDependencies=no from EFI mount units

- Other fixes
2014-03-06 04:00:41 +01:00
Zbigniew Jędrzejewski-Szmek 141a79f491 Extract looping over /proc/cmdline into a shared function
In cryptsetup-generator automatic cleanup had to be replaced
with manual cleanup, and the code gets a bit longer. But existing
code had the issue that it returned negative values from main(),
which was wrong, so should be reworked anyway.
2014-02-17 02:26:22 -05:00
Colin Guthrie 63a1b905d8 fstab-generator: Create fsck-root symlink with correct path
This was noticed in Brussels at the hackfest. The fstab-generator currently
creates a broken symlink pointing to itself in
/run/systemd/generator/local-fs.target.wants/ for systemd-fsck-root.service
2014-02-10 11:59:07 +01:00
Thomas Bächler e2f123b97b fstab-generator: Do not try to fsck non-devices
This fixes a regression introduced in 64e70e4 where the mount fails
when fstab is misconfigured with fs_passno > 0 on a virtual file
system like nfs, and the type is specified as "auto".
2013-12-21 22:52:56 -05:00
Zbigniew Jędrzejewski-Szmek 4e8da52959 fstab-generator: use RequiresOverridable for fsck units
This allows the user to disable fsck's by masking.

If fsck fails, emergency target is started, the user might mount the
unit using mount and disable fsck by masking the unit. In this case,
.mount will be active because the mount is detect through
/proc/self/mountinfo, but systemd-fsck@.service will still be in
failed mode. This results in a funny situation where

$ systemctl show -p ActiveState local-fs.target yyy.mount
ActiveState=active
ActiveState=active

$ sudo systemctl start local-fs.target
[sudo] password for test:
Failed to start local-fs.target: Unit systemd-fsck@xxx.service is masked.
2013-11-15 22:53:14 -05:00
Zbigniew Jędrzejewski-Szmek 94192cdaf6 fsck,fstab-generator: be lenient about missing fsck.<type>
If fstab contains 1 for passno, treat this as an error, but only warn
briefly. If fstab doesn't contain this information, don't complain at
all.

Patch is complicated a bit by the fact that we might have the fstype specified
in fstab or on /proc/cmdline, in which case we can check if we have the appropriate
fsck tool, or not specified, or specified as auto, in which case we have to look
and check the type of the filesystem ourselves. It cannot be done before the
device appears, so it is too early in the generator phase, and it must be done
directly in fsck service.
2013-11-15 22:53:14 -05:00
Lennart Poettering 74df0fca09 util: unify reading of /proc/cmdline
Instead of individually checking for containers in each user do this
once in a new call proc_cmdline() that read the file only if we are not
in a container.
2013-11-06 03:15:16 +01:00
Tom Gundersen a7623afb7a fsck-root: only run when requested in fstab
fsck-root is redundant in case an initrd is used, or in case the rootfs
is never remounted 'rw', so the new default is the correct behavior for
most users. For the rest, they should enable it in fstab.
2013-10-19 12:23:17 +02:00
Thomas Bächler 64e70e4b86 fstab-generator: Generate explicit dependencies on systemd-fsck@.service instead of using FsckPassNo
[tomegun:
  * order all fsck instances after fsck-root
  * check for OOM
  * added notes in the manpages]
2013-10-19 12:23:17 +02:00
Thomas Bächler 7f5806d709 fstab-generator: When parsing the root= cmdline option, set FsckPassNo to 1
[tomegun: without this we would never fsck the rootfs if it was directly
mounted 'rw' from the initrd. We now risk fsck'ing it twice in the case it
is mounted 'ro', so that should be addressed in a separate patch.]
2013-10-19 12:23:17 +02:00
Zbigniew Jędrzejewski-Szmek 5862d652ba Introduce _cleanup_endmntent_ 2013-10-03 22:13:55 -04:00
Zbigniew Jędrzejewski-Szmek 1dc2ced464 Remove six unused variables and add annotation
clang FTW!
2013-09-17 19:08:51 -04:00
Tom Gundersen 4e82fe5213 swap: create .wants symlink to 'auto' swap devices
As we load unit files lazily, we need to make sure something pulls in swap
units that should be started automatically, otherwise the default dependencies
will never be applied.

This partially reinstates code removed in
commit 64347fc2b9.

Also don't order swap devices after swap.target when they are 'nofail'.
2013-09-16 01:11:52 +02:00
Tom Gundersen 64347fc2b9 swap: handle nofail/noauto in core 2013-09-11 14:43:24 +02:00
Tom Gundersen 5073f89f10 mount: move device links handling from generator
This makes mount units work like swap units: when the backing device appears
the mount unit will be started.

v2: the device should want the mount unconditionally, not only for DefaultDependencies=yes
2013-09-11 14:40:59 +02:00
Tom Gundersen 80c3b720bf fstab-generator: use DefaultDependencies=yes
This removes some redundancy between the generator and the core mount handling.
2013-09-11 14:40:59 +02:00
WANG Chao 01264ad1cc fstab-generator: log_oom() if automount_name is null 2013-08-14 22:38:09 -04:00
WANG Chao ef53700c20 fstab-generator: read rd.fstab=on/off switch correctly 2013-08-09 18:09:44 +02:00
WANG Chao 21d1a67863 fstab-generator: respect noauto/nofail when adding sysroot mount
Currently we don't respect noauto/nofail root mount options (from
rootflags kernel cmdline). We should map these two flags to the
corresponding boolean variable noauto and nofail when calling
add_mount().
2013-08-09 02:04:51 +02:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek 8333c77edf Always use errno > 0 to help gcc
gcc thinks that errno might be negative, and functions could return
something positive on error (-errno). Should not matter in practice,
but makes an -O4 build much quieter.
2013-03-29 10:12:41 -04:00
Lennart Poettering 0c17fbce55 unit: replace remote-fs-setup.target by network-online.target
https://bugzilla.redhat.com/show_bug.cgi?id=787314
2013-03-29 03:07:17 +01:00
Harald Hoyer a87586a171 fstab-generator: drop x-initrd.rootfs mount option
x-initrd.mount now has different meanings, if fstab-generator is called
in the initramfs.

initrd:/etc/fstab and x-initrd.mount defines mounts for the
initrd-root-fs.target

initrd:/sysroot/etc/fstab and x-initrd.mount defines mounts for the
initrd-fs.target
2013-03-26 15:39:29 +01:00
Harald Hoyer 4e5ed9b69b fstab-generator: degrade the message about missing "root=" to log_debug
Some installation media (fedora at least) does not have and need a
"root=" argument on the kernel command line.
2013-03-26 14:46:35 +01:00
Lennart Poettering e8d2f6cde0 units: introduce remote-fs-setup.target to pull in dependencies from remote mounts
This introduces remote-fs-setup.target independently of
remote-fs-pre.target. The former is only for pulling things in, the
latter only for ordering.

The new semantics:

remote-fs-setup.target: is pulled in automatically by all remote mounts.
Shall be used to pull in other units that want to run when at least one
remote mount is set up. Is not ordered against the actual mount units,
in order to allow activation of its dependencies even 'a posteriori',
i.e. when a mount is established outside of systemd and is only picked
up by it.

remote-fs-pre.target: needs to be pulled in automatically by the
implementing service, is otherwise not part of the initial transaction.
This is ordered before all remote mount units.

A service that wants to be pulled in and run before all remote mounts
should hence have:

a) WantedBy=remote-fs-setup.target -- so that it is pulled in

b) Wants=remote-fs-pre.target + Before=remote-fs-pre.target -- so that
   it is ordered before the mount point, normally.
2013-03-25 22:04:40 +01:00
Mantas Mikulėnas 1b036593b7 fstab-generator: add missing strempty() calls 2013-03-25 20:14:29 +01:00
Lennart Poettering 80c39ad27f fstab-generator: fix minor memory leak on error path 2013-03-25 18:20:03 +01:00
Lennart Poettering df3e57f542 fstab-generator: add missing OOM check 2013-03-25 18:20:03 +01:00
Lennart Poettering 790838e4f1 fstab-generator: rename x-initrd-rootfs.mount to x-initrd.rootfs
This changes the fstab mount option x-initrd-rootfs.mount to
x-initrd.rootfs, in order to only use a single namespace "x-initrd." for
all mount options of the initrd.
2013-03-25 18:18:11 +01:00
Harald Hoyer 9e5f0f9291 Make initrd.target the default target in the initrd
First, rename root-fs.target to initrd-root-fs.target to clarify its usage.

Mount units with "x-initrd-rootfs.mount" are now ordered before
initrd-root-fs.target. As we sometimes construct /sysroot mounts in
/etc/fstab in the initrd, we want these to be mounted before the
initrd-root-fs.target is active.

initrd.target can be the default target in the initrd.

                             (normal startup)
                                    :
                                    :
                                    v
                              basic.target
                                    |
             ______________________/|
            /                       |
            |                  sysroot.mount
            |                       |
            |                       v
            |             initrd-root-fs.target
            |                       |
            |                       v
            |            initrd-parse-etc.service
(custom initrd services)            |
            |                       v
            |            (sysroot-usr.mount and
            |             various mounts marked
            |               with fstab option
            |                x-initrd.mount)
            |                       |
            |                       v
            |                initrd-fs.target
            |                       |
            \______________________ |
                                   \|
                                    v
                               initrd.target
                                    |
                                    v
                          initrd-cleanup.service
                               isolates to
                         initrd-switch-root.target
                                    |
                                    v
             ______________________/|
            /                       |
            |        initrd-udevadm-cleanup-db.service
            |                       |
(custom initrd services)            |
            |                       |
            \______________________ |
                                   \|
                                    v
                        initrd-switch-root.target
                                    |
                                    v
                        initrd-switch-root.service
                                    |
                                    v
                               switch-root
2013-03-15 00:49:37 +01:00
Harald Hoyer 700e07ffd5 add initrd-fs.target and root-fs.target
Instead of using local-fs*.target in the initrd, use root-fs.target for
sysroot.mount and initrd-fs.target for /sysroot/usr and friends.

Using local-fs.target would mean to carry over the activated
local-fs.target to the isolated initrd-switch-root.target and thus in
the real root. Having local-fs.target already active after
deserialization causes ordering problems with the real root services and
targets.

We better isolate to targets for initrd-switch-root.target, which are
only available in the initrd.
2013-03-13 08:11:17 +01:00
Harald Hoyer ac4785b031 Revert "fstab-generator: place initrd /sysroot mounts in initrd-fs.target"
This reverts commit 8330847e94.

Conflicts:
	src/fstab-generator/fstab-generator.c
2013-03-05 06:45:06 +01:00
Harald Hoyer 135b5212d4 fstab-generator: only handle block devices with root= kernel command line parameter
skip s.th. like root=nfs:... root=iscsi:... root=nbd:...
2013-03-04 21:00:56 +01:00
Harald Hoyer 8330847e94 fstab-generator: place initrd /sysroot mounts in initrd-fs.target
also do not overwrite /sysroot*.mount units already generated from fstab
2013-03-04 19:37:06 +01:00
Tom Gundersen 3d22d1ab57 fstab-generator: initrd - mount selected entries from /sysroot/etc/fstab
We only mount "/usr" and entries marked with "x-initrd.mount".

This (together with the right unit files) is needed in the initramfs in order to
natively support mounting /usr (and friends) from the initramfs.

The way it is meant to work is:
 * wait for sysroot.mount to be mounted
 * do a daemon-reload to generate sysroot-usr.mount (++) from /sysroot/etc/fstab
 * wait for sysroot-usr.mount to be mounted
 * switch-root

Cc: Harald Hoyer <harald.hoyer@gmail.com>
Cc: Dave Reisner <d@falconindy.com>
2013-03-01 22:52:36 +01:00
Tom Gundersen 533740e161 fstab-generator: drop rootwait support
I originally added this to stay as compatible as possible with the kernel, but
as Lennart argued it is not really useful in the initramfs, so let's drop it (we
already don't support 'rootdealy').
2013-03-01 21:17:19 +01:00
Harald Hoyer 945d1442ed fstab-generator: set "ro" as default for sysroot.mount 2013-03-01 17:52:05 +01:00
Harald Hoyer 3fb5a0feb4 fstab-generator: fix commit 92094b7 2013-03-01 17:07:44 +01:00
Harald Hoyer 92094b75fb fstab-generator: parse_new_root_from_proc_cmdline() don't use "defaults"
Don't use "defaults" as default option string.

"defaults,<anyotheroption>" does not
even work for the mount unit mount options.
2013-03-01 15:05:28 +01:00
Frederic Crozat 3f8ee79182 fstab,mount: detect rbind as bind mount
Correctly detect rbind mount option as bind mount.

Fixes https://bugzilla.novell.com/show_bug.cgi?id=804575.
2013-03-01 14:43:18 +01:00
Harald Hoyer 696164cb5b fstab-generator: change kernel command line mount path for root
Use /sysroot instead of /new_root to mount the real root in the
initramfs.
2013-02-21 10:27:38 +01:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00
Thomas Hindoe Paaboel Andersen b929bf049d tabs to spaces
Skipped bootchart and various files that looked like they should be
kept in sync with external sources.
2013-01-09 21:20:43 +01:00
Zbigniew Jędrzejewski-Szmek d0aa9ce519 fstab-generator: modernize style 2013-01-06 13:52:48 -05:00
Tom Gundersen 6fe8ab6d57 fstab-generator: fix typo 2012-12-29 00:21:28 +01:00
Tom Gundersen 5e398e546e fstab-generator: generate new_root.mount in initrd
The configuration is taken from /proc/cmdline, aiming at emulating the
behavior of the kernel when no initramfs is used.

The supported options are: root=, rootfstype=, rootwait=, rootflags=,
ro, and rw. rootdelay= was dropped, as it is not really useful in a
systemd world, but could easily be added.

v2: fix comments by Lennart, and complain loudly if root= can not be found

Cc: Harald Hoyer <harald@redhat.com>
Cc: Dave Reisner <dreisner@archlinux.org>
2012-12-28 23:39:42 +01:00
Lennart Poettering f9ea108e7c fstab-generator: properly detect bind mounts
This kinda undoes a83cbaccd0 and
1d634e21b4 but corrects the original code
to compare the mount type with "bind" rather than the mount options.
2012-12-24 13:01:00 +01:00
Tom Gundersen 67ab5f761f fstab-generator: make error more helpful in case of duplicates in fstab
Traditional sysvinit systems would not complain about duplicates in
fstab. Rather it (through monut -a) would mount one fs on top of another,
in effect the last entry taking precedent.

In systemd, the first entry takes precedent, all subsequent ones are
ignored and an error is printed.

The change of behavior and the source of this error message was causing
some confusion, so give a hint what migt be wrong.
2012-11-27 01:57:57 +01:00
Tom Gundersen 1d634e21b4 fstab-generator: drop mount_is_bind
Do the check in-line instead, as the function is now a bit pointless.
2012-11-27 00:56:09 +01:00
Tom Gundersen a83cbaccd0 fstab-generator: remove redundancy in mount_is_bind 2012-11-27 00:41:43 +01:00
Michal Schmidt 40b8acd039 fstab-generator: more specific error messages 2012-11-09 12:00:46 +01:00
Shawn Landden 0d0f0c50d3 log.h: new log_oom() -> int -ENOMEM, use it
also a number of minor fixups and bug fixes: spelling, oom errors
that didn't print errors, not properly forwarding error codes,
few more consistency issues, et cetera
2012-07-26 11:48:26 +02:00
Shawn Landden 669241a076 use "Out of memory." consistantly (or with "\n")
glibc/glib both use "out of memory" consistantly so maybe we should
consider that instead of this.

Eliminates one string out of a number of binaries. Also fixes extra newline
in udev/scsi_id
2012-07-25 11:23:57 +02:00
Lennart Poettering b7def68494 util: rename join() to strjoin()
This is to match strappend() and the other string related functions.
2012-07-13 13:41:01 +02:00
Lennart Poettering 9473414219 fstab-generator: support fstab=/rd.fstab= kernel cmdline
This generalizes functionality already available in dracut.
2012-06-22 10:27:05 +02:00
Kay Sievers ec6ceb1866 fstab-generator: avoid mangling of mount source string
This is a valid source entry in /etc/fstab:
  //192.168.6.10/data /data cifs noperm,auto

On Mon, Jun 4, 2012 at 2:04 PM, Dave Reisner <d@falconindy.com> wrote:
> On Mon, Jun 04, 2012 at 12:57:47PM +0200, Kay Sievers wrote:
>>
>> Changed it to use:
>>   path_is_absolute()
>> instead of:
>>   is_path(),
>> so that we still sanitize the input we might match against.
>>
>> Let me know, if you think that could still cause any problems?

> Yes, this will still break CIFS shares.
2012-06-04 15:21:05 +02:00
Kay Sievers 2b71016a3c fstab-generator: avoid mangling of non-path mount source and dest
This can invalidate otherwise valid source paths with trailing slashes,
such as "host:/" in the case of a network mount.

Based on a patch from Dave Reisner <dreisner@archlinux.org>, which
removed the slash mangling entirely.

Changed it to match on the leading slash to exclude non-path values.
2012-06-04 12:52:14 +02:00
Kay Sievers d2e54fae5c mkdir: append _label to all mkdir() calls that explicitly set the selinux context 2012-05-31 12:40:20 +02:00
Lennart Poettering 07719a21b6 manager: rework generator logic
Previously generated units were always placed at the end of the search
path. With this change there will be three unit dirs instead of one, to
place generated entries at the beginning, in the middle and at the end
of the search path:

beginning: for units that need to override all configuration, regardless
of user or vendor. Example use: system-update-generator uses this to
temporarily redirect default.target.

middle: for units that need to override vendor configuration, but not
vendor configuration. Example use: /etc/fstab should override vendor
supplied configuration (think /tmp), but should not override native user
configuration.

end: does not override anything but is available as well. Possible usage
might be to convert D-Bus bus service files to native units but allowing
vendor supplied native units to win.
2012-05-23 03:43:29 +02:00
Lennart Poettering 1b64d026af units: remove service sysv_path variable and replace it by generic unit_path
UnitPath= is also writable via native units and may be used by generators
to clarify from which file a unit is generated. This patch also hooks up
the cryptsetup and fstab generators to set UnitPath= accordingly.
2012-05-22 23:08:24 +02:00
Lennart Poettering a690306153 log: make sure generators never log into the journal to avoid activation deadlocks
This makes all generators log to kmsg by default.
2012-05-22 22:00:37 +02:00
Lennart Poettering 6b1dc2bd3c mount: replace PID1 internal fstab parser with generator
Bit by bit we should remove non-unit parsing from PID 1 and move into
generators, to clean up our code base a bit and clearly separate
parsers.
2012-05-22 19:25:17 +02:00