canonical / microceph

MicroCeph is snap-deployed Ceph with built-in clustering
https://snapcraft.io/microceph
GNU Affero General Public License v3.0
210 stars 33 forks source link

microceph does not allow adding partitioned disks #251

Open pedrofragola opened 11 months ago

pedrofragola commented 11 months ago

Based on issue [0], I tested snapd 2.61 in the edge channel to be able to use disks with partitions (/dev/sdb1). However, I still encountered the issue:

sudo microceph disk add /dev/sdb1 Error: Failed adding new disk: Failed to bootstrap OSD: Failed to run: ceph-osd --mkfs --no-mon-config -i 1: exit status 250 (2023-10-20T19:50:04.885+0000 7fd2a09e7800 -1 bluestore(/var/lib/ceph/osd/ceph-1/block) _read_bdev_label failed to open /var/lib/ceph/osd/ceph-1/block: (13) Permission denied 2023-10-20T19:50:04.885+0000 7fd2a09e7800 -1 bluestore(/var/lib/ceph/osd/ceph-1/block) _read_bdev_label failed to open /var/lib/ceph/osd/ceph-1/block: (13) Permission denied 2023-10-20T19:50:04.885+0000 7fd2a09e7800 -1 bluestore(/var/lib/ceph/osd/ceph-1/block) _read_bdev_label failed to open /var/lib/ceph/osd/ceph-1/block: (13) Permission denied 2023-10-20T19:50:04.889+0000 7fd2a09e7800 -1 bluestore(/var/lib/ceph/osd/ceph-1) _setup_block_symlink_or_file failed to open block file: (13) Permission denied 2023-10-20T19:50:04.889+0000 7fd2a09e7800 -1 bluestore(/var/lib/ceph/osd/ceph-1) mkfs failed, (13) Permission denied 2023-10-20T19:50:04.889+0000 7fd2a09e7800 -1 OSD::mkfs: ObjectStore::mkfs failed with error (13) Permission denied 2023-10-20T19:50:04.889+0000 7fd2a09e7800 -1 ** ERROR: error creating empty object store in /var/lib/ceph/osd/ceph-1: (13) Permission denied)

After discussing this internally with the microcloud team, we added the following line to the file /var/lib/snapd/apparmor/profiles/snap.microceph.daemon:

/dev/sd{,[a-z]}[a-z][0-9]{,[0-9],[0-9][0-9]} rwk, # SCSI rule!

Then we ran the following commands:

sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.microceph.daemon sudo snap restart microceph

After this, it was possible to use partitions. Ideally, there should be a fix for this and the apparmor should already have the correct file.

[0] https://github.com/snapcore/snapd/pull/13150

sabaini commented 11 months ago

Hi @pedrofragola ftr. the linked snapd patch turned out to be erroneous, we will need to come up with a new interface for snapd

pedrofragola commented 11 months ago

Hi @sabaini thanks for the info... do you will file a new snapd bug? if so let me know the link to follow

itoffshore commented 10 months ago

I worked around this issue here

I also played around with cephadm yesterday to run a ceph cluster inside podman - but this forces you to install OSD's on top of lvm lv's rather than directly onto partitions. The mgr service also kept crashing (possibly due to using podman rather than docker)

microceph is much nicer & I'm going back to it today (it always gave me a healthy cluster)

adam-vest commented 8 months ago

Howdy!

I stumbled upon this bug report when I was deploying microceph locally as well, as my original design plan had intended on using partitions where necessary (some devices I'm using only have one storage device). I did confirm that modifying the apparmor profiles allowed things to connect smoothly; however, chattr-ing those files as immutable isn't really a sustainable solution, since if the host ever needs to reboot (or the snap gets restarted, updated, etc), microceph will just fail to come up because snap can't control those files in the way it wants.

To work around this problem for now, I instead wrote a bash script that runs as an ExecStartPre on the snap.microceph.daemon & snap.microceph.osd systemd services. Script is as such (making sure it's executable):

#!/bin/bash
if [[ ! $(grep Cephy /var/lib/snapd/apparmor/profiles/snap.microceph.daemon) ]]; then
        sed -i '/loopback control$/a \/dev\/dm-\[0-9\] rwk,\t\t\t\t\t\t# Cephy' /var/lib/snapd/apparmor/profiles/snap.microceph.daemon;
        apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.microceph.daemon;
fi

if [[ ! $(grep Cephy /var/lib/snapd/apparmor/profiles/snap.microceph.osd) ]]; then
        sed -i '/loopback control$/a \/dev\/dm-\[0-9\] rwk,\t\t\t\t\t\t# Cephy' /var/lib/snapd/apparmor/profiles/snap.microceph.osd;
        apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.microceph.osd;
fi

(In my case I'm using LVM volumes, so dm-[0-9] made sense for me - replace as appropriate for your needs)

Then do sudo systemctl edit on both of the above-named systemd services, and add the following:

[Service]
ExecStartPre=/usr/local/bin/microceph.sh

(or whatever path you placed the script in)

Then sudo systemctl daemon-reload for good measure, and at this point microceph should be able to work with partitions sustainably until the snap team makes this support native.

itoffshore commented 8 months ago

@adam-vest - many thanks for a better solution - you can also --drop-in (override) service scripts with:

systemctl edit snap.microceph.daemon --drop-in=override
systemctl edit snap.microceph.osd --drop-in=override
UtkarshBhatthere commented 8 months ago

Thank you @adam-vest and @itoffshore for sharing workarounds.

itoffshore commented 8 months ago

@UtkarshBhatthere @adam-vest - here's the script I use:

For the override I only needed to:

#!/bin/sh

TAG="Cephy"
ADD="/dev/vda[4-9] rwk,\t\t\t\t\t   # $TAG"
SEARCH="/dev/vd\[a-z\]"
#PROFILES="/var/lib/snapd/apparmor/profiles/snap.microceph*"
#FILES=$(grep -l $SEARCH $PROFILES)
FILES="/var/lib/snapd/apparmor/profiles/snap.microceph.osd"

for file in $FILES; do
        if ! grep -q $TAG $file; then
                line=$(grep -n $SEARCH $file | cut -d : -f 1)
                sed -i "$line i $ADD" $file
                echo "Reloading: $file"
                apparmor_parser -r $file
        else
                echo "Already configured: $file"
        fi
done

exit 0