Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:[#1500] allow users to exclude files when using --nvidia #1555

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions distrobox-create
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ init=0
non_interactive=0
nvidia=0
nopasswd=0
nvidia_exclusion=""
unshare_ipc=0
unshare_groups=0
unshare_netns=0
Expand Down Expand Up @@ -214,6 +215,7 @@ Options:
this will make host's processes not visible from within the container. (assumes --unshare-process)
may require additional packages depending on the container image: https://github.com/89luca89/distrobox/blob/main/docs/useful_tips.md#using-init-system-inside-a-distrobox
--nvidia: try to integrate host's nVidia drivers in the guest
--nvidia-exclude: directories to be excluded when nvidia drivers are integrated (e.g. /usr/share/cmake)
--unshare-devsys: do not share host devices and sysfs dirs from host
--unshare-groups: do not forward user's additional groups into the container
--unshare-ipc: do not share ipc namespace with host
Expand Down Expand Up @@ -387,6 +389,13 @@ while :; do
shift
nvidia=1
;;
--nvidia-exclude)
if [ -n "$2" ]; then
nvidia_exclusion="${nvidia_exclusion} $2"
shift
shift
fi
;;
-Y | --yes)
non_interactive=1
shift
Expand Down Expand Up @@ -938,17 +947,26 @@ generate_create_command()
#
# We set the entrypoint _before_ running the container image so that
# we can override any user provided entrypoint if need be
result_command="${result_command}
--entrypoint /usr/bin/entrypoint
${container_image}
init_command="
--verbose
--name \"${container_user_name}\"
--user ${container_user_uid}
--group ${container_user_gid}
--home \"${container_user_custom_home:-"${container_user_home}"}\"
--init \"${init}\"
--nvidia \"${nvidia}\"
--pre-init-hooks \"${container_pre_init_hook}\"
--nvidia \"${nvidia}\"
"
if [[ ! -z ${nvidia_exclusion} ]]; then
init_command="
${init_command}
--nvidia-exclude \"${nvidia_exclusion}\"
"
fi
result_command="${result_command}
--entrypoint /usr/bin/entrypoint
${container_image}
${init_command}
--additional-packages \"${container_additional_packages}\"
-- '${container_init_hook}'
"
Expand Down
39 changes: 31 additions & 8 deletions distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ container_additional_packages=""
init=0
init_hook=""
nvidia=0
nvidia_exclusion=""
pre_init_hook=""
rootful=0
upgrade=0
Expand Down Expand Up @@ -106,6 +107,7 @@ Options:
--init/-I: whether to use or not init
--pre-init-hooks: commands to execute prior to init
--nvidia: try to integrate host's nVidia drivers in the guest
--nvidia-exclude: directories to be excluded when nvidia is integrated (e.g. /usr/share/cmake)
--upgrade/-U: run init in upgrade mode
--verbose/-v: show more verbosity
--version/-V: show version
Expand Down Expand Up @@ -189,6 +191,13 @@ while :; do
shift
fi
;;
--nvidia-exclude)
if [ -n "$2" ]; then
nvidia_exclusion="$2"
shift
shift
fi
;;
--)
shift
init_hook=$*
Expand Down Expand Up @@ -1859,13 +1868,20 @@ if [ "${nvidia}" -eq 1 ]; then
# - egl files
# - icd files
# Excluding here the libs, we will threat them later specifically
NVIDIA_FILES="$(find /run/host/etc/ /run/host/usr/ \
-path "/run/host/usr/lib/i386-linux-gnu/*" -prune -o \
-path "/run/host/usr/lib/x86_64-linux-gnu/*" -prune -o \
-path "/run/host/usr/lib32/*" -prune -o \
-path "/run/host/usr/lib64/*" -prune -o \
-path "/run/host/usr/lib/*" -prune -o \
-iname "*nvidia*" -not -type d -print 2> /dev/null || :)"
NVIDIA_FILES_CMD="find /run/host/etc/ /run/host/usr/ \
-path \"/run/host/usr/lib/i386-linux-gnu/*\" -prune -o \
-path \"/run/host/usr/lib/x86_64-linux-gnu/*\" -prune -o \
-path \"/run/host/usr/lib32/*\" -prune -o \
-path \"/run/host/usr/lib64/*\" -prune -o \
-path \"/run/host/usr/lib/*\" -prune -o"

if [[ ! -z $nvidia_exclusion ]]; then
for exclusion in $nvidia_exclusion; do
NVIDIA_FILES_CMD="${NVIDIA_FILES_CMD} ! -path \"/run/host${exclusion}/**\""
done
fi
NVIDIA_FILES_CMD="${NVIDIA_FILES_CMD} -iname "*nvidia*" -not -type d -print 2> /dev/null || :"
NVIDIA_FILES=$(eval ${NVIDIA_FILES_CMD})
for nvidia_file in ${NVIDIA_FILES}; do
dest_file="$(printf "%s" "${nvidia_file}" | sed 's|/run/host||g')"

Expand All @@ -1876,7 +1892,14 @@ if [ "${nvidia}" -eq 1 ]; then
done

# Then we find all directories with nvidia in the name and just mount them
NVIDIA_DIRS="$(find /run/host/etc /run/host/usr -iname "*nvidia*" -type d 2> /dev/null || :)"
NVIDIA_DIRS_CMD="find /run/host/etc /run/host/usr"
if [[ ! -z $nvidia_exclusion ]]; then
for exclusion in $nvidia_exclusion; do
NVIDIA_DIRS_CMD="${NVIDIA_DIRS_CMD} ! -path \"/run/host${exclusion}/**\""
done
fi
NVIDIA_DIRS_CMD="${NVIDIA_DIRS_CMD} -iname "*nvidia*" -type d 2> /dev/null || :"
NVIDIA_DIRS=$(eval ${NVIDIA_DIRS_CMD})
for nvidia_dir in ${NVIDIA_DIRS}; do
# /usr/lib64 is common in Arch or RPM based distros, while /usr/lib/x86_64-linux-gnu is
# common on Debian derivatives, so we need to adapt between the two nomenclatures.
Expand Down