How to mount aufs file system on boot in archlinux?
Solution 1
Systemd has native support for mounts (man systemd.mount
). In fact systemd reads /etc/fstab
, uses it to generate mount units, and mount the filesystems itself.
Rather than relying on fstab
, it's also possible to create mount units by hand. This is how system mounts like /dev
, /sys
, /proc
, etc are handled (/usr/lib/systemd/system/*.mount
). This method allows you to use systemd dependencies to ensure things get mounted in the right order.
systemd mount unit files must be named after the mount point they control (man systemd.unit
). As an example, I created a unit file to mount my USB backup drive to /mnt/backup
. Following the naming convention, I've created /etc/systemd/system/mnt-backup.mount
, with the following contents:
[Unit]
Description = USB backup disk
[Mount]
What = LABEL=david-usb-backup
Where = /mnt/backup
Type = ext4
[Install]
WantedBy = multi-user.target
I then run systemctl daemon-reload
for systemd to load the unit. I can run systemctl start mnt-backup.mount
to mount the disk, and/or systemctl enable mnt-backup.mount
to have it started at boot.
For dependencies add Requires = some-other-mnt-point.mount
under the [Unit]
section. Optionally, you may use BindTo
rather than Requires
; this will cause it to get unmounted if one of the dependencies disappears. However Requires
does not affect the order in which the disks are mounted. So to make sure that the disks are mounted before aufs, use After
.
Edit: To expand on the use of Requires
and After
, the unit section might look like:
[Unit]
Description = USB backup disk
Requires = mnt-data01.mount
Requires = mnt-data02.mount
Requires = mnt-data03.mount
After = mnt-data01.mount
After = mnt-data02.mount
After = mnt-data03.mount
Solution 2
Thought I would post a step by step instruction for others like me. Thanks to David Baggerman for helping me reach here.
I've created /etc/systemd/system/mnt-aufs.mount
, with the following contents:
[Unit]
Description = AUFS disk
Requires = mnt-data01.mount
Requires = mnt-data02.mount
Requires = mnt-data03.mount
After = mnt-data01.mount
After = mnt-data02.mount
After = mnt-data03.mount
[Mount]
What = none
Where = /mnt/aufs
Type = aufs
Options = br:/mnt/data01/=rw:/mnt/data02/=rw:/mnt/data03/=rw,sum,create=mfs
[Install]
WantedBy = multi-user.target
I then ran systemctl daemon-reload
for systemd to load the unit. Run systemctl start mnt-aufs.mount
to mount the disk, and/or systemctl enable mnt-aufs.mount
to have it started at boot.
This is equivalent to copy pasting the following to /etc/rc.local
init script and would have been a lot easier. I wonder why systemd does not have an equivalent file.
mount -t aufs -o br:/mnt/disk01=rw:/mnt/disk02=rw: /mnt/disk03=rw,sum,create=mfs none /mnt/aufs
Solution 3
If you want to keep using fstab just try to add _netdev to the options.
none /mnt/aufs aufs sum,create=mfs,dirs=.....,_netdev 0 0
This will delay the mount until the network is up.
Related videos on Youtube
Nithin
Updated on September 18, 2022Comments
-
Nithin over 1 year
I want to use aufs to combine a few disks.I am able to mount the aufs file system using the mount command from the command line.
However, when trying to mount the same through an fstab entry, it fails. Google tells me that fstab does not mount file systems in the specified order, creating this problem. I also found recommendations to add the mount command in rc.local so the aufs is mounted after fstab.
I am using archlinux which uses systemd, so how can I run the mount command at boot in systemd?
-
Nithin almost 11 yearsMy aufs file system uses three disks mounted in fstab. I need to make sure that these disks are mounted before aufs is mounted. Can you give me an example with 'Requires' using fstab entires? How/where do I specify the aufs options like branches??
-
Franco Ferrari almost 11 yearsI've added an example of the use of
Requires
. You can get the unit names by runningsystemctl -t mount
. You can add a singleOptions = ...
under[Mount]
with the same syntax as infstab
. -
Nithin almost 11 yearsAs far as I know, systemd does not use rc.local...
-
stackexchanger almost 11 yearsBetter to fix this bug, than develop bicycle.
-
Nithin almost 11 yearsBug?? If there is an equivalent to rc.local, please let me know.
-
Nithin almost 11 yearsplz clarify what you mean by bug..
-
Nithin almost 11 yearsUsing just the
Requires =
generates a behavior similar to that offstab
that is aufs got mounted before the disks. Added theAfter =
and it seems to work. -
Woodrow Douglass about 7 yearsthis is better then rc.local because systemd can manage the mount point, unmount it on shutdown, etc. rc.local is a super-primitive way of doing things, and while it does work, it's not always the easiest thing to manage.
-
user2948306 over 6 yearsIf you have /etc/rc.local as an executable file, it will be pulled in to the boot process by
systemd-rc-local-generator
/rc-local.service
. Note the path where it looks forrc.local
is set by the distribution, you can check it withsystemctl cat rc-local.service
. -
user2948306 over 6 years... which doesn't seem very well known. so I've added it as an answer here