Path: blob/master/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-mounts.sh
2675 views
#!/bin/bash12# SPDX-FileCopyrightText: Copyright The Lima Authors3# SPDX-License-Identifier: Apache-2.045set -eux -o pipefail67# Check if mount type is virtiofs and vm type as vz8if ! [[ ${LIMA_CIDATA_VMTYPE} == "vz" && ${LIMA_CIDATA_MOUNTTYPE} == "virtiofs" ]]; then9exit 010fi1112# Update fstab entries and unmount/remount the volumes with secontext options13# when selinux is enabled in kernel14if [ -d /sys/fs/selinux ]; then15LABEL_BIN="system_u:object_r:bin_t:s0"16LABEL_NFS="system_u:object_r:nfs_t:s0"17# shellcheck disable=SC201318for line in $(grep -n virtiofs </etc/fstab | cut -d':' -f1); do19OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab)20TAG=$(awk -v line="$line" 'NR==line {print $1}' /etc/fstab)21MOUNT_OPTIONS=$(mount | grep "${TAG}" | awk '{print $6}')22if [[ ${OPTIONS} != *"context"* ]]; then23##########################################################################################24## When using vz & virtiofs, initially container_file_t selinux label25## was considered which works perfectly for container work loads26## but it might break for other work loads if the process is running with27## different label. Also these are the remote mounts from the host machine,28## so keeping the label as nfs_t fits right. Package container-selinux by29## default adds rules for nfs_t context which allows container workloads to work as well.30## https://github.com/lima-vm/lima/pull/196531##32## With integration[https://github.com/lima-vm/lima/pull/2474] with systemd-binfmt,33## the existing "nfs_t" selinux label for Rosetta is causing issues while registering it.34## This behaviour needs to be fixed by setting the label as "bin_t"35## https://github.com/lima-vm/lima/pull/263036##########################################################################################37if [[ ${TAG} == *"rosetta"* ]]; then38label=${LABEL_BIN}39else40label=${LABEL_NFS}41fi42sed -i -e "$line""s/comment=cloudconfig/comment=cloudconfig,context=\"$label\"/g" /etc/fstab43if [[ ${MOUNT_OPTIONS} != *"$label"* ]]; then44MOUNT_POINT=$(awk -v line="$line" 'NR==line {print $2}' /etc/fstab)45OPTIONS=$(awk -v line="$line" 'NR==line {print $4}' /etc/fstab)4647#########################################################48## We need to migrate existing users of Fedora having49## Rosetta mounted from nfs_t to bin_t by unregistering50## it from binfmt before remounting51#########################################################52if [[ ${TAG} == *"rosetta"* && ${MOUNT_OPTIONS} == *"${LABEL_NFS}"* ]]; then53[ ! -f "/proc/sys/fs/binfmt_misc/rosetta" ] || echo -1 >/proc/sys/fs/binfmt_misc/rosetta54fi55umount "${TAG}"56mount -t virtiofs "${TAG}" "${MOUNT_POINT}" -o "${OPTIONS}"57fi58fi59done60fi616263