3

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?

8

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
  • 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
10

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
  • this 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. – Woodrow Douglass Mar 7 '17 at 13:07
  • If 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 for rc.local is set by the distribution, you can check it with systemctl cat rc-local.service. – sourcejedi Sep 23 '17 at 18:25
  • ... which doesn't seem very well known. so I've added it as an answer here – sourcejedi Sep 23 '17 at 18:44
1

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.

0

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
  • 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
0

Newer versions of systemd support a x-systemd.requires option in fstab, so if you don't want to use systemd.mount units and want to stick to fstab try something like the following:

aufs /mnt/storage aufs ro,nobootwait,dirs=/mnt/storage2=ro:/mnt/storage1=ro:/mnt/storage3=ro:/mnt/storage4=ro:/mnt/storage0=ro:/mnt/storage5=ro:/mnt/storage6=ro:/mnt/storage7=ro:/mnt/storage8,xino=/dev/shm/aufs.xino,x-systemd.requires=mnt-storage0,x-systemd.requires=mnt-storage1,x-systemd.requires=mnt-storage2,x-systemd.requires=mnt-storage3,x-systemd.requires=mnt-storage4,x-systemd.requires=mnt-storage5,x-systemd.requires=mnt-storage6,x-systemd.requires=mnt-storage7,x-systemd.requires=mnt-storage8  0 0
-1

Linux Live Kit - Make sure that aufs and squashfs kernel modules are supported by your kernel. Debian Jessie has both included automatically.

You may need to install aufs-dkms package on newer versions of Debian.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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