Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running systemd unit directly after local-fs.target and before basic.target

Tags:

systemd

I am creating an embedded system. The embedded system mounts a partition. Directly after mounting the partition, I need to prep an encrypted folder (encfs). I need this to run before any other multi-user.target or graphical.target

Here is my unit file, which works by it's self.

[Unit]
Description=Mx Encrypted Folder

[Service]
Type=oneshot
ExecStart=/usr/bin/mxmountencrypted
RemainAfterExit=true
ExecStop=/usr/bin/mxunmountencrypted

This unit file has no dependencies defined, currently.

Again, I need:

  1. To run this directly after mounting file systems (local-fs.target)
  2. Before any multi-user.target or graphical.target, where must of the services that depend on it will be ran.
  3. It must stop fully before stopping local-fs.target, since there will be a nested mount that needs to be unmounted before systemd can unmount the partition.

I looked into using the systemd.mount item, but it doesn't support encfs.

like image 599
Paul Knopf Avatar asked Oct 28 '25 08:10

Paul Knopf


1 Answers

Based on what you have listed in the requirements:

[Unit]
Description=Mx Encrypted Folder
Requires=local-fs.target
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/usr/bin/mxmountencrypted
RemainAfterExit=true
ExecStop=/usr/bin/mxunmountencrypted

[Install]
WantedBy=multi-user.target

More on systemd Unit files here: https://www.freedesktop.org/software/systemd/man/systemd.unit.html

and systemd Service files: https://www.freedesktop.org/software/systemd/man/systemd.service.html

like image 149
Brendan Avatar answered Oct 30 '25 14:10

Brendan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!