Skip to content

Commit b212b23

Browse files
chenxiaolongahesford
authored andcommitted
zbm-builder.sh: add mount-options argument, document use
A new `-M` option for `zbm-builder.sh` provides a means to specify mount options for the `/build` and (if specified) `/zbm` volumes in the build container. Using, for example, `-M z` allows images to be built on hosts with SELinux enabled. This change is documented, along with extra considerations for building Dracut-based images in containers when SELinux is enabled on the host. Signed-off-by: Andrew Gunnerson <[email protected]> Closes: #433.
1 parent 50ee82e commit b212b23

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

docs/guides/general/container-building.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ The default behavior of ``zbm-builder.sh`` will:
118118
2. If ``./config.yaml`` exists, inform the builder to use that custom configuration instead of the default
119119
3. Run the internal build script to produce output in the ``./build`` subdirectory
120120

121+
.. note::
122+
123+
Building on hosts with SELinux enabled may require that volumes mounted by the build container be properly labeled.
124+
This can be accomplished by specifying the argument ``-M z`` to ``zbm-builder.sh``. This will persistently relabel the
125+
build directory and, if specified, the ZFSBootMenu source directory. As an alternative to conf, it may be possible to
126+
disable SELinux entirely by invoking ``zbm-builder.sh`` with the argument ``-O --security-opt=label=disable``.
127+
128+
When Dracut is used to build an image under the constraints of SELinux, ``zbm-builder.sh`` should additionally be
129+
invoked with the argument ``-O --env=DRACUT_NO_XATTR=1`` to prevent Dracut from setting extended attributes on
130+
temporary files it creates within the container. Without this option, Dracut may try, but fail, to set the
131+
``security.selinux`` attribute on files.
132+
121133
Custom ZFSBootMenu Hooks
122134
~~~~~~~~~~~~~~~~~~~~~~~~
123135

@@ -174,3 +186,6 @@ command-line options that are described in the output of ``zbm-builder.sh -h``.
174186

175187
Before adjusting these command-line options, seek a thorough understanding of the
176188
:zbm:`image build process <releng/docker/README.md>` and the command sequence of ``zbm-builder.sh`` itself.
189+
190+
..
191+
vim: softtabstop=2 shiftwidth=2 textwidth=120

zbm-builder.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ OPTIONS:
4040
4141
-d Force use of docker instead of podman
4242
43+
-M <argument>
44+
Provide a comma-separated list of options to use for volume
45+
mounts of the build directory and (if specified) ZFSBootMenu
46+
source tree within the build container. For example, specify
47+
48+
zbm-builder -M z
49+
50+
to label the volumes for use with SELinux.
51+
52+
NOTE: An 'ro' option is always added to the volume mounted from
53+
the ZFSBootMenu source tree.
54+
4355
-O <argument>
4456
Provide an option to 'podman run' or 'docker run'; if the
4557
argument accepts one or more options, use a form with no spaces
@@ -76,6 +88,7 @@ EOF
7688

7789
SKIP_HOSTID=
7890
REMOVE_HOST_FILES=
91+
MOUNT_FLAGS=
7992

8093
# By default, use the latest upstream build container image
8194
BUILD_IMG="ghcr.io/zbm-dev/zbm-builder:latest"
@@ -101,7 +114,7 @@ else
101114
PODMAN="docker"
102115
fi
103116

104-
CMDOPTS="b:dhi:l:c:O:HR"
117+
CMDOPTS="b:dhi:l:c:M:O:HR"
105118

106119
# First pass to get build directory and configuration file
107120
while getopts "${CMDOPTS}" opt; do
@@ -156,6 +169,9 @@ while getopts "${CMDOPTS}" opt; do
156169
l)
157170
BUILD_REPO="${OPTARG}"
158171
;;
172+
M)
173+
MOUNT_FLAGS="${OPTARG}"
174+
;;
159175
O)
160176
RUNTIME_ARGS+=( "${OPTARG}" )
161177
;;
@@ -181,7 +197,7 @@ if ! command -v "${PODMAN}" >/dev/null 2>&1; then
181197
fi
182198

183199
# Always mount a build directory at /build
184-
RUNTIME_ARGS+=( "-v" "${BUILD_DIRECTORY}:/build" )
200+
RUNTIME_ARGS+=( "-v" "${BUILD_DIRECTORY}:/build${MOUNT_FLAGS:+:${MOUNT_FLAGS}}" )
185201

186202
# Only mount a local repo at /zbm if specified
187203
if [ -n "${BUILD_REPO}" ]; then
@@ -190,7 +206,7 @@ if [ -n "${BUILD_REPO}" ]; then
190206
exit 1
191207
fi
192208

193-
RUNTIME_ARGS+=( "-v" "${BUILD_REPO}:/zbm:ro" )
209+
RUNTIME_ARGS+=( "-v" "${BUILD_REPO}:/zbm:ro${MOUNT_FLAGS:+,${MOUNT_FLAGS}}" )
194210
fi
195211

196212
# Remove existing hostid

0 commit comments

Comments
 (0)