Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 7fe5fc9

Browse files
committed
grub_install: Add LOOP_NO_UDEV for builds in a container
A lot of the SDK instructions seem to assume you're in a "classic" Linux login session. I use Fedora Atomic Workstation and do all of my development in "dev containers" (currently docker, in the process of switching to podman). In my setup the `/dev` setup is separate and won't pick up udev changes. (Ideally I'd filter out a lot of host devices, that's another issue) Anyone in a similar situation (which I assume would also include trying to do the SDK build inside a Docker container on CoreOS) can do: `env LOOP_NO_UDEV=1 ./build_images.sh` to have it manually set up the partition mounts. Loopback mounts with containers in general are ugly since they're not namespaced. A whole better solution to this IMO is to use something like http://libguestfs.org/ which basically spawns a VM, although it doesn't support grub2. So we'd really have to do instead something like what Fedora does with using Anaconda. Or the "helper VM" could probably just be an existing CoreOS qcow2.
1 parent 575f7cd commit 7fe5fc9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

build_library/grub_install.sh

+23-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ CORE_NAME=
5252
# fixed up the board root's grub will always be used.
5353
BOARD_GRUB=0
5454

55+
# This may be useful if you're running the build process inside a container
56+
# (e.g. docker/podman/etc) distinct from the host; in that case you'll have
57+
# a distinct /dev normally and won't pick up udev probed devices. But if you
58+
# do the probe from the host side, it should show up in the container.
59+
LOOP_NO_UDEV=${LOOP_NO_UDEV:-0}
60+
5561
case "${FLAGS_target}" in
5662
i386-pc)
5763
CORE_MODULES+=( biosdisk serial )
@@ -110,6 +116,21 @@ info "Installing GRUB ${FLAGS_target} in ${FLAGS_disk_image##*/}"
110116
LOOP_DEV=$(sudo losetup --find --show --partscan "${FLAGS_disk_image}")
111117
ESP_DIR=$(mktemp --directory)
112118

119+
# Hack available for doing the build in a container; see the LOOP_NO_UDEV
120+
# comments above.
121+
if [[ ${LOOP_NO_UDEV} -eq 1 ]]; then
122+
echo "LOOP_NO_UDEV enabled, creating device nodes directly"
123+
LOOPNUM=$(echo ${LOOP_DEV} | sed -e 's,/dev/loop,,')
124+
for d in /sys/block/loop${LOOPNUM}/loop${LOOPNUM}p*; do
125+
p=$(cat ${d}/partition)
126+
dev=$(cat ${d}/dev)
127+
min=${dev##*:}
128+
maj=${dev%:*}
129+
devpath=/dev/loop${LOOPNUM}p${p}
130+
sudo rm -f ${devpath}
131+
sudo mknod -m 660 ${devpath} b ${maj} ${min}
132+
done
133+
fi
113134
# work around slow/buggy udev, make sure the node is there before mounting
114135
if [[ ! -b "${LOOP_DEV}p1" ]]; then
115136
# sleep a little just in case udev is ok but just not finished yet
@@ -119,11 +140,12 @@ if [[ ! -b "${LOOP_DEV}p1" ]]; then
119140
if [[ -b "${LOOP_DEV}p1" ]]; then
120141
break
121142
fi
122-
warn "looback device node still ${LOOP_DEV}p1 missing, reprobing..."
143+
warn "loopback device node still ${LOOP_DEV}p1 missing, reprobing..."
123144
sudo blockdev --rereadpt ${LOOP_DEV}
124145
sleep 0.5
125146
done
126147
if [[ ! -b "${LOOP_DEV}p1" ]]; then
148+
ls -al /dev/loop*
127149
failboat "${LOOP_DEV}p1 where art thou? udev has forsaken us!"
128150
fi
129151
fi

0 commit comments

Comments
 (0)