Skip to content

Commit

Permalink
feat(dracut.sh): detect running in a container
Browse files Browse the repository at this point in the history
Don't try to `mknod` by setting DRACUT_NO_MKNOD.
Don't try to `cp` extended attributrs by setting DRACUT_NO_XATTR.
  • Loading branch information
haraldh committed May 17, 2021
1 parent c08bc81 commit 7275c6f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,13 @@ if [[ -f $dracutbasedir/dracut-version.sh ]]; then
. "$dracutbasedir"/dracut-version.sh
fi
if systemd-detect-virt -c &> /dev/null; then
export DRACUT_NO_MKNOD=1 DRACUT_NO_XATTR=1
if [[ $hostonly ]]; then
printf "%s\n" "dracut: WARNING: running in hostonly mode in a container!!"
fi
fi
if [[ -f $dracutbasedir/dracut-init.sh ]]; then
# shellcheck source=./dracut-init.sh
. "$dracutbasedir"/dracut-init.sh
Expand Down Expand Up @@ -1888,7 +1895,7 @@ if [[ $kernel_only != yes ]]; then
# shellcheck disable=SC2174
mkdir -m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
done
if [[ $EUID == "0" ]]; then
if [[ $EUID == "0" ]] && ! [[ $DRACUT_NO_MKNOD ]]; then
[[ -c ${initdir}/dev/null ]] || mknod "${initdir}"/dev/null c 1 3
[[ -c ${initdir}/dev/kmsg ]] || mknod "${initdir}"/dev/kmsg c 1 11
[[ -c ${initdir}/dev/console ]] || mknod "${initdir}"/dev/console c 5 1
Expand Down

0 comments on commit 7275c6f

Please sign in to comment.