Run command before mounting filesystems under systemd

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

User avatar
NieXS
Why's the rum gone?
Posts: 286
Joined: Wed Mar 12, 2008 3:10 am UTC
Location: Brazil

Run command before mounting filesystems under systemd

Postby NieXS » Wed Nov 04, 2015 6:09 am UTC

PREAMBLE: fuck systemd for making running a single command (!!!) during boot time be this painful.

I dual boot Windows and Linux, and have an NTFS partition that is spread across two disk partitions, which I set up using Windows' Dynamic Disks functionality. I can access this dynamic volume under linux by assembling a linear RAID array containing both partitions. Since I want this file system to be mounted at boot, I have it in /etc/fstab as /dev/md0, and run mdadm to assemble it. I can't add it to mdadm.conf since it isn't listed when I run mdadm --scan.

I read that you could write unit files for device nodes under systemd, so I went ahead and wrote one for /dev/md0. It doesn't work; the unit file times out during boot and I have to run the command manually in the 'emergency shell' before booting can continue.

The unit file sits at /etc/systemd/system/dev-md0.device, and its content is as follows:
Spoiler:

Code: Select all

[Unit]
Description=Cria softraid de discos lineares
Wants=local-fs-pre.target
Before=local-fs-pre.target shutdown.target
Conflicts=shutdown.target
DefaultDependencies=no

[Service]
ExecStart=/sbin/mdadm --build --verbose /dev/md0 --chunk=64 --level=linear --raid-devices=2 /dev/disk/by-id/ata-ST3500418AS_9VM30NE5-part2 /dev/disk/by-id/ata-ST3500418AS_9VM30NE5-part1
Type=oneshot

I am really lost as for what I should do, since while there is documentation on what each entry on the unit file does, there really aren't many example files. Any ideas?
she/her


User avatar
Flumble
Yes Man
Posts: 2262
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Run command before mounting filesystems under systemd

Postby Flumble » Wed Nov 04, 2015 11:21 am UTC

Is /sdbin/mdam even available so early during booting?

Have you tried looking at any errors coming from the command? I don't know where you can pipe the output before fstab is evaluated, but perhaps you do.

Is it really necessary to have it (available before and) mounted by fstab? I assume you can have a service that creates the raid interface and mounts the partition right before basic.target or default.target without inconvenience.


Am I asking questions because I don't master systemd? Definitely.

User avatar
NieXS
Why's the rum gone?
Posts: 286
Joined: Wed Mar 12, 2008 3:10 am UTC
Location: Brazil

Re: Run command before mounting filesystems under systemd

Postby NieXS » Wed Nov 04, 2015 1:31 pm UTC

I think it is. It doesn't crash, it just hangs there for 90 seconds until it times out. Running the service file manually does the same thing.

I put it in fstab because it seemed like the most practical place to put it, hehe. If all else fails I'll move things elsewhere.
she/her


User avatar
Flumble
Yes Man
Posts: 2262
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Run command before mounting filesystems under systemd

Postby Flumble » Wed Nov 04, 2015 1:49 pm UTC

NieXS wrote:I think it is. It doesn't crash, it just hangs there for 90 seconds until it times out. Running the service file manually does the same thing.

So starting the service (manually) when the system is fully loaded results in the same behaviour as starting at the start of the boot process? And simply running the command from the terminal (when the system is fully loaded) does work? Interesting.

Does this help to get some more information about mdadm having trouble?


Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 6 guests