[systemd-devel] Preserving bind mount options from mounts in the initrd

Andrei Borzenkov arvidjaar at gmail.com
Sat Aug 2 06:07:14 UTC 2025


02.08.2025 01:45, Ali Rizvi wrote:
> Good evening,
> 
> I'd like to discuss a particular problem that I've been having with my
> system. The basic idea I'm trying to go for is the setup of an ephemeral
> root, where my `/` partition is a `tmpfs`, and all directories I need to
> keep are linked via bind mounts to their respective locations (think
> /persistent/var/log bind mounted to /var/log). Originally I had set this up
> by simply writing all the mounts into `/etc/fstab`, but this wasn't early
> enough for some services and ended up losing some critical information
> pertaining to the boot (one example is the lack of `/etc/machine-id` making
> journald lose track of the system, even if all relevant logs where in a
> persisted `/var/log`). This forced me to move my mounting behaviour into
> the initrd, where i've written an initrd service that attempts to run
> before `initrd-root-fs.target` is reached so that all the mounts are
> successfully finalized before proceeding. I've also had to mark all my
> services with `DefaultDependencies = no` in order to prevent them from
> being unmounted before `switch_root` is invoked. An issue I have with this
> approach is that I cannot preserve any mount options associated with the
> respective mounts.

It would help if you explained what "preserve mount options" actually means.

> The main option I want to preserve is `x-gvfs-hide`, as
> without it, the default GNOME file manager will show these mounts with an
> option to unmount them, and it gets visually quite annoying.
> 
> First off I'd like to ask for some advice in regards to this entire setup.
> While it feels perfectly stable and so far I've never had an issue with it
> failing or causing issues, I can't help but feel that it's a little bit
> brittle. In particular, I'm not totally confident that I've set up the unit
> dependencies as properly as I could have. Secondly, I'm not sure how to
> tackle the issue of preserving mount options from the initrd into the root
> system. I tried using `/boot` as a reference to see how systemd was able to
> preserve its mount options, but I realized that `/boot` mounts in the real
> system, and not in the initrd stage, which isn't helpful for my case. I
> considered possibly allowing my mounts to unmount and then re-mounting them
> extremely early, near `local-fs-pre.target`, but I imagined this may cause
> issues with journald logging possibly getting cut off due to the lack of a
> proper write destination, though I've actually admittedly not tried this.
> 
> I'm aware this is probably a bit of a messy setup, but I'd nonetheless
> appreciate any advice or information that I could use to help me further
> refine and polish this system that I'm trying to create.
> 
> 
> 
> Thank you for your time and consideration,
> 
> Ali Rizvi (Frontear)
> 



More information about the systemd-devel mailing list