I had a problem: every time my Windows have a big update, it locks a specific partition that I use to share files between Windows and Linux. After the update, I wasn't able to boot Linux again, as
fstab could not mount it.
To avoid using a pen drive or booting any other way just to get my Linux working again, I removed the partition from
It worked, but I didn't want to manually mount it on every boot. Worst than that: Dropbox app synchronize on that partition. It means that on every single boot it raised an error message that my files were moved. It was definitely not a good way to solve it.
My new solution: create a script to mount the partition and run it at boot. Any error here would not stop my Linux from booting and I would still have it working by the time I logged in after boot. But, where is the best place to run a root script at startup? Of course,
systemd! A simple service running a script should do the trick.
Well, with a simple search I found out something even better:
systemd can mount partitions using
To keep it simple, I am going to explain, step by step, the basic usage of
systemd.mount with only the options I used myself.
.mount file on
/etc/systemd/system/ (I will get back at this point later, for now, just use any name for the file)
Inside the file you should specify the following attributes:
Description=A description of your mount script
What=The partition that will be mounted
Where=Directory where the partition will be mounted
Type=The partition file type (ext4, ntfs, fat32 etc)
RequiredBy=Unit dependencies. It's used by the enable and disable commands of the
Now comes the tricky part: you have to name your .mount file accordingly with your
Where= statement. So to mount it on /run/media/bruno/Multimedia you have to name it
It's time to test it:
# systemctl daemon-reload # systemctl start run-media-bruno-Multimedia.mount
To check the unit status, you can run
systemctl status run-media-bruno-Multimedia.mount
If everything is working fine, just enable it:
systemctl enable run-media-bruno-Multimedia.mount and you are good to go.
[Unit] Description=Mount Multimedia out of fstab [Mount] What=/dev/disk/by-label/Multimedia Where=/run/media/bruno/Multimedia Type=ntfs Options=defaults [Install] WantedBy=multi-user.target
Just a description of you .mount script.
The partition itself. You can specify it by name, path or UUID.
The easiest one after description: the file type of the partition. If you are trying to mount a Windows partition, it will probably be
ntfs. If it is a Linux partition, it will probably be
Partition options, the same used on
multi-user.target to start in multi-user runlevel.