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

grub_install: Add LOOP_NO_UDEV for builds in a container #794

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion build_library/grub_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ CORE_NAME=
# fixed up the board root's grub will always be used.
BOARD_GRUB=0

# This may be useful if you're running the build process inside a container
# (e.g. docker/podman/etc) distinct from the host; in that case you'll have
# a distinct /dev normally and won't pick up udev probed devices. But if you
# do the probe from the host side, it should show up in the container.
LOOP_NO_UDEV=${LOOP_NO_UDEV:-0}

case "${FLAGS_target}" in
i386-pc)
CORE_MODULES+=( biosdisk serial )
Expand Down Expand Up @@ -110,6 +116,21 @@ info "Installing GRUB ${FLAGS_target} in ${FLAGS_disk_image##*/}"
LOOP_DEV=$(sudo losetup --find --show --partscan "${FLAGS_disk_image}")
ESP_DIR=$(mktemp --directory)

# Hack available for doing the build in a container; see the LOOP_NO_UDEV
# comments above.
if [[ ${LOOP_NO_UDEV} -eq 1 ]]; then
echo "LOOP_NO_UDEV enabled, creating device nodes directly"
LOOPNUM=$(echo ${LOOP_DEV} | sed -e 's,/dev/loop,,')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scripts are already full of bashisms, so we might as well cut out unnecessary processes: LOOPNUM=${LOOP_DEV#/dev/loop}

for d in /sys/block/loop${LOOPNUM}/loop${LOOPNUM}p*; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For additional cleanliness, maybe have a shopt -s nullglob for this loop? That way if something crazy happens that breaks this pattern, the rest of the script still functions normally when it checks for a nonexistent device node. (This "library" script is only executed standalone rather than sourced, so a shopt shouldn't affect anything else.)

p=$(cat ${d}/partition)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p=$(< ${d}/partition)

dev=$(cat ${d}/dev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev=$(< ${d}/dev)

min=${dev##*:}
maj=${dev%:*}
devpath=/dev/loop${LOOPNUM}p${p}
sudo rm -f ${devpath}
sudo mknod -m 660 ${devpath} b ${maj} ${min}
done
fi
# work around slow/buggy udev, make sure the node is there before mounting
if [[ ! -b "${LOOP_DEV}p1" ]]; then
# sleep a little just in case udev is ok but just not finished yet
Expand All @@ -119,11 +140,12 @@ if [[ ! -b "${LOOP_DEV}p1" ]]; then
if [[ -b "${LOOP_DEV}p1" ]]; then
break
fi
warn "looback device node still ${LOOP_DEV}p1 missing, reprobing..."
warn "loopback device node still ${LOOP_DEV}p1 missing, reprobing..."
sudo blockdev --rereadpt ${LOOP_DEV}
sleep 0.5
done
if [[ ! -b "${LOOP_DEV}p1" ]]; then
ls -al /dev/loop*
failboat "${LOOP_DEV}p1 where art thou? udev has forsaken us!"
fi
fi
Expand Down