6

I'm trying to set up my Nextcloud on a Raspberry Pi 3 on Ubuntu Core. I want to have a Raid 1 setup, so a disk failure doesn't wipe out all the data (next to weekly backups I'll do with another disk attached)

The issue right now is that Ubuntu Core does not come with mdadm to create the RAID. Also there does not seem to be a snap available for mdadm, and obviously you can't install the package using apt-get on Ubuntu Core. However, I found that with the snap "classic dimension" I can use apt-get, install mdadm and use mdadm to create a Raid 1 at /dev/md0 from my two disks.

Also in the non-classic dimension I can use that /dev/md0 and mount it using systemd.mount, as described here. So far, so good.

The problem is, after a reboot the /dev/md0 does not exist anymore and systemd fails -- Subject: Unit dev-md0.device has failed -- Defined-By: systemd

I guess this is because mdadm does not exist in this environment and so the raid is gone after the reboot.

My question to you is: Is there a possibility at all to create a Raid on Ubuntu Core using mdadm? And if so, how do I get it to work?

Thank you for your time.

Edit: I found out that after a reboot I can enter the classic extension with sudo classic, and in the classic extension start the raid with sudo mdadm --assemble --scan. Is there maybe a way to do this using a systemd-script of some sort?

1

1 Answer 1

5
+200

We had a pretty active discussion a while back when we implemented the udisks2 interface in snapd. The outcome was that we don't want to give arbitrary snaps access to block devices and added all access for those directly into the udisks2 interface.

udisks2 offers a mediated way for all other snaps to deal with block devices and generally also allows working with RAIDs. I say generally, because this is a feature we haven't verified yet that it is working with the udisks2 snap currently in the store.

If support for RAIDs in udisks2 works users should be able to mount a RAID on a directory in /media via a dbus API call.

One downside is that the udisks2 interface explicitly denies plug connections as it still gives kind of privileged access to the system. Every mount done via udisks2 will appear below /media and every snap using the removable-media interface will get access to devices mounted there, regardless if it's the system partition or not. So even the plug side is a very privileged thing. That said, snaps can ask for a snap-declaration on the store side to get connections to udisks2.

Another feature we support with the udisks2 snap is auto-mounting (documentation for this will be soon on https://docs.ubuntu.com/). This allows a device to say that it wants removable devices like USB storage device to be automatically mounted in /media as you know it from consumer oriented devices like the Ubuntu Desktop. Depending on how the RAID is setup this might be able to get the the RAID mounted on boot into /media. Requirements for the automounter to consider a device are currently:

  • Device is not a system device (meaning it's not a partition on the device we're booting the system from).
  • Device is not already mounted.
  • Device is a removable device (USB, CD/DVD).

Automounting can be enabled via:

$ snap set udisks2 automount.enable=true

when the udisks2 snap is installed.

For a very simple, unconfined solution you could just install the udisks2 snap (given that it detects and works well with RAID devices) and create a systemd unit in /etc/systemd/system/mount-my-raid.service

[Unit]
Description=Mount my RAID

[Service]
Exec=/snap/bin/udisks2.udisksctl mount -b /path/to/block/device

[Install]
WantedBy=multi-user.target

Then activate it via:

$ sudo systemctl enable mount-my-raid.service

and the RAID should be automatically mounted below /media on the next system reboot.

3
  • Thank you @morphis for this answer. I installed the snap and tried to set up the service as you recommended (altough I had to write 'ExecStart' instead of 'Exec' and the service would not start without an (empty) 'ExecStop' as well). The issue is, udisks2 does not seem to work with RAID: When I try to get it to mount /dev/md0 where my RAID should be, it does not work because there is no block device (because mdadm was not started prior I guess). When I try to mount one of the disks directly, it says 'Object /org/freedesktop/UDisks2/block_devices/sda is not a mountable filesystem.'
    – Rino
    Mar 18, 2017 at 12:13
  • I have the feeling that we miss the mdadm binary in the snap. I can have a look on monday to see if we do. If we do, I can push a change so you could test this from the edge channel at the beginning of next week. Does that sound good?
    – morphis
    Mar 19, 2017 at 13:41
  • That sounds great! Sorry for the late reply. I appreciate the help!
    – Rino
    Mar 26, 2017 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .