Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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
share|improve this answer
    
My 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?? –  Nithin Jul 6 '13 at 10:21
    
I've added an example of the use of Requires. You can get the unit names by running systemctl -t mount. You can add a single Options = ... under [Mount] with the same syntax as in fstab. –  David Baggerman Jul 6 '13 at 10:38
    
Using just the Requires = generates a behavior similar to that of fstabthat is aufs got mounted before the disks. Added the After = and it seems to work. –  Nithin Jul 6 '13 at 18:02
    
edited your answer to include the After statement –  Nithin Jul 6 '13 at 18:11

You better use /etc/rc.local

Try this example:

# cat > /etc/rc.local << EOF
mount -t squashfs -o loop /usr/src/system_packages.squashfs /var/mount_point/
mount -t aufs -o remount,append:/var/mount_point/ none / 
EOF
share|improve this answer
    
As far as I know, systemd does not use rc.local... –  Nithin Jul 6 '13 at 16:34
    
Better to fix this bug, than develop bicycle. –  stackexchanger Jul 6 '13 at 16:48
    
Bug?? If there is an equivalent to rc.local, please let me know. –  Nithin Jul 6 '13 at 16:50
    
plz clarify what you mean by bug.. –  Nithin Jul 6 '13 at 17:10
    
I mean, if no rc.local, better create it, and do not develop bicycle. –  stackexchanger Jul 6 '13 at 23:48

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.