[systemd-devel] [PATCH 1/2] fstab-generator: Support root on tmpfs (or other deviceless FS)

Tom Gundersen teg at jklm.no
Tue Mar 24 10:08:29 PDT 2015


On Tue, Mar 24, 2015 at 5:53 PM, Tobias Hunger <tobias.hunger at gmail.com> wrote:
> Hi Tom,
>
> no, root=tmpfs rootfstype=tmpfs does *not* work without my patch. I
> had thought it should, too, and I did try.
>
> fstab-generator was silently ignoring root= since "tmpfs" is not a
> device. So no mount unit for /sysroot...
>
> Since fstab-generator did evaluate mount.usr* which did point to a
> real device it did create a sysroot-usr.mount unit though. So the
> initrd did create /sysroot/usr, mounted my usr-subvol there and then
> happily switched into the /sysroot directory. At that point systemd
> was no longer happy at all and produced lots of funny error messages
> about devices being missing.

Andrei likely pointed out the culprit. I'd be a lot happier with
making this work by changing that condition to be in line with fstab,
rather than have this whitelist around.

Any chance you could take a look at that?

Cheers,

Tom

> On Tue, Mar 24, 2015 at 4:39 PM, Tom Gundersen <teg at jklm.no> wrote:
>> Hi Tobias and Zbigniew,
>>
>> This already went in, but I was just looking at it again.
>>
>> Is there any reason the kernel commandline handling must be treated
>> differently here than the fstab handling? We already support
>> deviceless mounts (obviously) when specified in fstab without the need
>> for any whitelist, so why not just the same logic for the kernel
>> commandline? In fact, that should already work without this patch,
>> should it not (didn't actually try, just looked at the code)?
>>
>> "root=none rootfstype=tmpfs"
>>
>> Cheers,
>>
>> Tom
>>
>> On Tue, Mar 24, 2015 at 12:52 AM, Tobias Hunger <tobias.hunger at gmail.com> wrote:
>>> This allows for stateless systems.
>>> ---
>>>  src/fstab-generator/fstab-generator.c | 21 +++++++++++++--------
>>>  src/shared/util.c                     | 30 ++++++++++++++++++++++++++++++
>>>  src/shared/util.h                     |  1 +
>>>  3 files changed, 44 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
>>> index 2ece12f..77c97fd 100644
>>> --- a/src/fstab-generator/fstab-generator.c
>>> +++ b/src/fstab-generator/fstab-generator.c
>>> @@ -397,15 +397,20 @@ static int add_root_mount(void) {
>>>          _cleanup_free_ char *what = NULL;
>>>          const char *opts;
>>>
>>> -        if (isempty(arg_root_what)) {
>>> -                log_debug("Could not find a root= entry on the kernel command line.");
>>> -                return 0;
>>> -        }
>>> +        if (fstype_is_deviceless(arg_root_fstype)) {
>>> +                if (free_and_strdup(&what, arg_root_what) < 0)
>>> +                        return log_oom();
>>> +        } else {
>>> +                if (isempty(arg_root_what)) {
>>> +                        log_debug("Could not find a root= entry on the kernel command line.");
>>> +                        return 0;
>>> +                }
>>>
>>> -        what = fstab_node_to_udev_node(arg_root_what);
>>> -        if (!path_is_absolute(what)) {
>>> -                log_debug("Skipping entry what=%s where=/sysroot type=%s", what, strna(arg_root_fstype));
>>> -                return 0;
>>> +                what = fstab_node_to_udev_node(arg_root_what);
>>> +                if (!path_is_absolute(what)) {
>>> +                        log_debug("Skipping entry what=%s where=/sysroot type=%s", what, strna(arg_root_fstype));
>>> +                        return 0;
>>> +                }
>>>          }
>>>
>>>          if (!arg_root_options)
>>> diff --git a/src/shared/util.c b/src/shared/util.c
>>> index ad548da..cb03527 100644
>>> --- a/src/shared/util.c
>>> +++ b/src/shared/util.c
>>> @@ -1713,6 +1713,36 @@ bool fstype_is_network(const char *fstype) {
>>>          return nulstr_contains(table, fstype);
>>>  }
>>>
>>> +bool fstype_is_deviceless(const char *fstype) {
>>> +        static const char table[] =
>>> +                "autofs\0"
>>> +                "bdev\0"
>>> +                "cgroup\0"
>>> +                "configfs\0"
>>> +                "cpuset\0"
>>> +                "debugfs\0"
>>> +                "devpts\0"
>>> +                "devtmpfs\0"
>>> +                "efivarfs\0"
>>> +                "hugetlbfs\0"
>>> +                "mqueue\0"
>>> +                "nfs\0"
>>> +                "nfs4\0"
>>> +                "overlayfs\0"
>>> +                "pipefs\0"
>>> +                "proc\0"
>>> +                "pstore\0"
>>> +                "ramfs\0"
>>> +                "rootfs\0"
>>> +                "rpc_pipefs\0"
>>> +                "securityfs\0"
>>> +                "sockfs\0"
>>> +                "sysfs\0"
>>> +                "tmpfs\0";
>>> +
>>> +        return nulstr_contains(table, fstype);
>>> +}
>>> +
>>>  int chvt(int vt) {
>>>          _cleanup_close_ int fd;
>>>
>>> diff --git a/src/shared/util.h b/src/shared/util.h
>>> index 29e85bb..b5f44b8 100644
>>> --- a/src/shared/util.h
>>> +++ b/src/shared/util.h
>>> @@ -409,6 +409,7 @@ int fd_cloexec(int fd, bool cloexec);
>>>  int close_all_fds(const int except[], unsigned n_except);
>>>
>>>  bool fstype_is_network(const char *fstype);
>>> +bool fstype_is_deviceless(const char *fstype);
>>>
>>>  int chvt(int vt);
>>>
>>> --
>>> 2.3.3
>>>
>>> _______________________________________________
>>> systemd-devel mailing list
>>> systemd-devel at lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list