Skip to content

Commit f289edc

Browse files
committed
cmd-osbuild: support running as root
In some limited cases we don't have access to /dev/kvm. For example, riscv just added support for KVM virtualization, but there is very little to no hardware that actually supports it. In order to build disk images for riscv using osbuild we'll need to support running outside the supermin VM. This code change allows for that. This is mostly a hack and shouldn't be used unless absolutely required. Here is the cosa alias I used to get this to work: ``` cosa() { env | grep COREOS_ASSEMBLER >&2 rm -f "${COREOS_ASSEMBLER_CONTAINER_NAME}-variant-config.json" if [ "$COREOS_ASSEMBLER_CONFIG_VARIANT" != "" ]; then cat <<EOF > "${COREOS_ASSEMBLER_CONTAINER_NAME}-variant-config.json" { "coreos-assembler.config-variant": "${COREOS_ASSEMBLER_CONFIG_VARIANT}" } EOF fi set -x # so we can see what command gets run sudo podman run --rm -ti --security-opt label=disable --privileged \ --user root --userns host -v /dev/:/dev/ -e COSA_NO_KVM=1 \ -v ${PWD}:/srv/ \ --tmpfs /tmp -v /var/tmp:/var/tmp --name ${COREOS_ASSEMBLER_CONTAINER_NAME:-cosa} \ ${COREOS_ASSEMBLER_CONFIG_VARIANT:+-v ./"${COREOS_ASSEMBLER_CONTAINER_NAME}-variant-config.json":/srv/src/config.json:ro} \ ${COREOS_ASSEMBLER_CONFIG_GIT:+-v $COREOS_ASSEMBLER_CONFIG_GIT:/srv/src/config/:ro} \ ${COREOS_ASSEMBLER_RHCOS_REPOS:+-v $COREOS_ASSEMBLER_RHCOS_REPOS:/srv/src/yumrepos/:ro} \ ${COREOS_ASSEMBLER_FCOS_SUBMODULE:+-v $COREOS_ASSEMBLER_FCOS_SUBMODULE:/srv/src/config/fedora-coreos-config:ro} \ ${COREOS_ASSEMBLER_GIT:+-v $COREOS_ASSEMBLER_GIT/src/:/usr/lib/coreos-assembler/:ro} \ ${COREOS_ASSEMBLER_ADD_CERTS:+-v /etc/pki/ca-trust:/etc/pki/ca-trust:ro} \ ${COREOS_ASSEMBLER_CONTAINER_RUNTIME_ARGS} \ ${COREOS_ASSEMBLER_CONTAINER:-quay.io/coreos-assembler/coreos-assembler:latest} "$@" rc=$?; set +x; return $rc } ``` Of note is the `--user root --userns host -v /dev/:/dev/ -e COSA_NO_KVM=1` line and the fact that we are using `sudo` to become root.
1 parent 55d5540 commit f289edc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cmd-osbuild

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ main() {
397397
fi
398398

399399
outdir=$(mktemp -p "${tmp_builddir}" -d)
400-
runvm_with_cache -- /usr/lib/coreos-assembler/runvm-osbuild \
400+
if has_privileges && [ "${COSA_NO_KVM:-}" == "1" ]; then
401+
cmd="env" # run outside of supermin if we are root already
402+
else
403+
cmd="runvm_with_cache"
404+
fi
405+
$cmd -- /usr/lib/coreos-assembler/runvm-osbuild \
401406
--config "${runvm_osbuild_config_json}" \
402407
--mpp "/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.${basearch}.mpp.yaml" \
403408
--outdir "${outdir}" \

0 commit comments

Comments
 (0)